I’m using an rfid-rc522 and I want to print to the serial a string of text if two rfid tags have been read in a given time period.
Essentially this:
-
First tag is read (print to serial: Tag 1 has been read)
-
Wait 2 seconds
-
Second tag is read (print to serial: Tag 2 has been read)
-
Print to serial: Tag 1 and Tag 2 has been read)
-
Bonus: Keep this state - and then when a button is pressed (print to serial: Tag 1 and Tag 2 are finished)
I know how to read the UID and print to the serial if one is read. Thank you so much for your help, it’s greatly appreciated.
Here is my code so far:
#include <Adafruit_GFX.h> // Core graphics library
#include <Adafruit_ST7735.h> // Hardware-specific library
#include <SPI.h>
#include <MFRC522.h>
// For the breakout, you can use any 2 or 3 pins
// These pins will also work for the 1.8" TFT shield
#define sclk 4 // SainSmart: SCL
#define mosi 5 // SainSmart: SDA
#define cs 6 // SainSmart: CS
#define dc 7 // SainSmart: RS/DC
#define rst 8 // SainSmart: RES
Adafruit_ST7735 tft = Adafruit_ST7735(cs, dc, mosi, sclk, rst);
#define SS_PIN 10
#define RST_PIN 9
MFRC522 mfrc522(SS_PIN, RST_PIN);
float p = 3.1415926;
void setup(void) {
Serial.begin(9600);
SPI.begin();
Serial.print("Starting cornhole leaderboard...");
mfrc522.PCD_Init(); // Init MFRC522 card
Serial.println("Scan PICC to see UID and type...");
// Use this initializer if you're using a 1.8" TFT
tft.initR(INITR_BLACKTAB); // initialize a ST7735S chip, black tab
// Use this initializer (uncomment) if you're using a 1.44" TFT
//tft.initR(INITR_144GREENTAB); // initialize a ST7735S chip, black tab
Serial.println("Initialized");
uint16_t time = millis();
tft.fillScreen(ST7735_BLACK);
time = millis() - time;
Serial.println(time, DEC);
// large block of text
tft.fillScreen(ST7735_BLACK);
}
void loop() {
// Look for new cards
if ( ! mfrc522.PICC_IsNewCardPresent()) {
return;
}
// Select one of the cards
if ( ! mfrc522.PICC_ReadCardSerial()) {
return;
}
if (mfrc522.uid.uidByte[0] == 0xA4 &&
mfrc522.uid.uidByte[1] == 0xB8 &&
mfrc522.uid.uidByte[2] == 0xB8 &&
mfrc522.uid.uidByte[3] == 0x96) {
Serial.println("Nate has checked in to the game.");
tft.fillScreen(ST7735_BLUE);
tft.setTextSize(2);
tft.setCursor(0, 0);
tft.setTextColor(ST7735_YELLOW);
tft.print("Nate ");
tft.setTextColor(ST7735_WHITE);
tft.println("has checked in ");
tft.setTextSize(2);
tft.println("to the game.");
delay(2000);
tft.fillScreen(ST7735_BLACK);
}
if (mfrc522.uid.uidByte[0] == 0x03 &&
mfrc522.uid.uidByte[1] == 0xFD &&
mfrc522.uid.uidByte[2] == 0xBC &&
mfrc522.uid.uidByte[3] == 0x02) {
Serial.println("Ted has checked in to the game.");
tft.fillScreen(ST7735_RED);
tft.setTextSize(2);
tft.setCursor(0, 0);
tft.setTextColor(ST7735_CYAN);
tft.print("Ted ");
tft.setTextColor(ST7735_WHITE);
tft.println("has checked in ");
tft.setTextSize(2);
tft.println("to the game.");
delay(2000);
tft.fillScreen(ST7735_BLACK);
}
}