Still racking my brain trying to figure this out and could use some help. I have a wheel of fortune game that I am building. I am using RFID tags on the back of the wheel inside each segment (picture a big pie each piece is a segment). I am using a PN532 shield with I2C and it works great. I am able to read the cards and the ultimate goal is to trigger a video when the wheel lands on a segment (each RFID card had a unique ID which will trigger different videos. I am using Keyboard.H library to trigger a laptop with the video play list.
My problem is each time the wheel spins the reader reads the cards and triggers the media player. I need some way to not false trigger when the wheel is turning and only read the cards when it has stopped. I just cannot figure out the best solution. Any thoughts?
#include <Keyboard.h>
#include <Wire.h>
#include <SPI.h>
#include <Adafruit_PN532.h>
// If using the breakout or shield with I2C, define just the pins connected
// to the IRQ and reset lines. Use the values below (2, 3) for the shield!
#define PN532_IRQ (6)
#define PN532_RESET (3) // Not connected by default on the NFC Shield
// Uncomment just _one_ line below depending on how your breakout or shield
// is connected to the Arduino:
// Or use this line for a breakout or shield with an I2C connection:
Adafruit_PN532 nfc(PN532_IRQ, PN532_RESET);
void setup(void) {
Serial.begin(115200);
while (!Serial) delay(10); // for Leonardo/Micro/Zero
Serial.println("Hello!");
nfc.begin();
uint32_t versiondata = nfc.getFirmwareVersion();
if (! versiondata) {
Serial.print("Didn't find PN53x board");
while (1); // halt
}
// Got ok data, print it out!
Serial.print("Found chip PN5"); Serial.println((versiondata>>24) & 0xFF, HEX);
Serial.print("Firmware ver. "); Serial.print((versiondata>>16) & 0xFF, DEC);
Serial.print('.'); Serial.println((versiondata>>8) & 0xFF, DEC);
// configure board to read RFID tags
nfc.SAMConfig();
Serial.println("Waiting for an ISO14443A Card ...");
}
void loop(void) {
Keyboard.begin();
uint8_t success;
uint8_t uid[] = { 0, 0, 0, 0, 0, 0, 0 }; // Buffer to store the returned UID
uint8_t uidLength; // Length of the UID (4 or 7 bytes depending on ISO14443A card type)
// Wait for an ISO14443A type cards (Mifare, etc.). When one is found
// 'uid' will be populated with the UID, and uidLength will indicate
// if the uid is 4 bytes (Mifare Classic) or 7 bytes (Mifare Ultralight)
success = nfc.readPassiveTargetID(PN532_MIFARE_ISO14443A, uid, &uidLength);
if (success) {
// Display some basic information about the card
Serial.println("Found an ISO14443A card");
Serial.print(" UID Length: ");Serial.print(uidLength, DEC);Serial.println(" bytes");
Serial.print(" UID Value: ");
nfc.PrintHex(uid, uidLength);
if (uidLength == 4)
{
// We probably have a Mifare Classic card ...
uint32_t cardid = uid[0];
cardid <<= 8;
cardid |= uid[1];
cardid <<= 8;
cardid |= uid[2];
cardid <<= 8;
cardid |= uid[3];
Serial.print("Seems to be a Mifare Classic card #");
Serial.println(cardid);
if (cardid == 1839898475){
Keyboard.write('A');
delay(100);
}
if (cardid == 3335073343){
Keyboard.write('B');
delay(100);
}
if (cardid == 2260681791){
Keyboard.write('C');
delay(100);
}
if (cardid == 3329626431){
Keyboard.write('D');
delay(100);
}
if (cardid == 1186344511){
Keyboard.write('E');
delay(100);
}
Keyboard.end();
Serial.println("");
}
}
}


