Hi,
I am trying to get keyboard output from the arduino after scanning respective card but I need an output when there is no card. It comes but so rapidly and doesn't stop.
I need only one output when there is no card.
#include <SPI.h>
#include <RFID.h>
#include<Keyboard.h>
#define SS_PIN 10
#define RST_PIN 9
RFID rfid(SS_PIN, RST_PIN);
bool flag = false;
int btn = 4;
String rfidCard;
String Prev_Card;
String Card1= "f3 3c 7c 1a";
String Card2= "c3 69 81 1a";
String Card3= "63 2f 7d 1a";
String Card4= "4a 8d bc ed";
void setup() {
Serial.begin(9600);
Keyboard.begin();
pinMode(btn, INPUT);
Serial.println("Starting the RFID Reader...");
SPI.begin();
rfid.init();
}
void loop() {
if (digitalRead(btn)== HIGH){
resett:
if (rfid.isCard()){ // checks if the card is present
//rfid.halt(); // it stops the rfid reader to read the hex id simultaniously
if (flag == false) { // check flag if true then run cmd and return flag to false to run stop running same cmd
//Serial.println("Card is present");
if (rfid.readCardSerial()) {
rfidCard = String(rfid.serNum[0], HEX) + " " + String(rfid.serNum[1],HEX) + " " + String(rfid.serNum[2], HEX) + " " + String(rfid.serNum[3], HEX);
if (rfidCard==Prev_Card){
//Prev_Card= rfidCard;
goto resett;}
else{
Prev_Card= rfidCard;
}
Serial.println(rfidCard);
if (rfidCard==Card1){
Keyboard.write('b');
Serial.println("Card 1 is tapped");}
else if (rfidCard==Card2){
Keyboard.write('c');
Serial.println("Card 2 is tapped");}
else if (rfidCard==Card3){
Keyboard.write('d');
Serial.println("Card 3 is tapped");}
else if (rfidCard==Card4){
Keyboard.write('e');
Serial.println("Card 4 is tapped");
}
//rfid.halt();
delay(100);
}
else{
Serial.println("Card is not tapped");
}
//rfid.halt();
flag = true;
}
}
else{ // if the card is not present
if (flag == true){ // check if the flag is true or not means not runit if previosly card is not present there.
Serial.println("Card is not present");
Keyboard.write('a');
flag =false;
}
}
}
}
My scope is just to get keyboard output when card is tapped and when there is no card it trigger once and then stop sending trigger but in state of reading card again.