Hello,
I am completely new here and just needed to use Arduino for this one project. I have a case with an RFID lock. When a correct card is placed to the reader, the servo moves the lock to open the case. Now, I have this code:
#include <Servo.h>
#include <SPI.h>
#include <RFID.h>
RFID rfid(10, 9);
byte kart[5] = {237,68,25,198,123};
Servo myservo;
boolean card;
void setup()
{
Serial.begin(9600);
SPI.begin();
rfid.init();
myservo.attach(3);
myservo.write(95);
}
void loop()
{
if (rfid.isCard())
{
if (rfid.readCardSerial())
{
Serial.print("Found ID: ");
Serial.print(rfid.serNum[0]);
Serial.print(",");
Serial.print(rfid.serNum[1]);
Serial.print(",");
Serial.print(rfid.serNum[2]);
Serial.print(",");
Serial.print(rfid.serNum[3]);
Serial.print(",");
Serial.println(rfid.serNum[4]);
}
for (int i = 1; i < 5; i++)
{
if (rfid.serNum[0] == kart[0] && rfid.serNum[1] == kart[1] && rfid.serNum[2] == kart[2] && rfid.serNum[3] == kart[3] && rfid.serNum[4] == kart[4])
{
card = true;
}
else {
card = false;
}
}
if (card == true)
{
Serial.println("Correct Card");
myservo.write(-95);
delay(5000);
myservo.write(95);
}
else
{
Serial.println("Wrong Card");
}
rfid.halt();
}
}
What it does it opens the lock, waits 5 seconds and then closes. What I want it to do is to open and then wait until the card is put to the reader the second time to close it. I tried to search for some kind of "wait until sth happens" function or something but I am completely green in this and had no idea how to apply it.
Any help would be appreciated, thank you in advance