Hello all, what I need to do is basically,
- Read the card uid.
- Get selection (by pushing a button)
- Restart loop
It reads the card in the first time after uploading the sketch and gets the selection, but it doesn't detect after the first loop.
What can be the problem ? I searched it and I checked (and made some changes) the code but I couldn't find out what is wrong with my code.
(I know for sure that something is wrong with the getVote part. Without it, the code works as I expect)
...
void loop() {
// Look for new cards
if ( ! mfrc522.PICC_IsNewCardPresent())
return;
// Verify if the NUID has been readed
if ( ! mfrc522.PICC_ReadCardSerial())
return;
int cardUID = getCardID();
Serial.println("CARD UID READ");
printCardName(cardUID);
Serial.println("SELECT WITH BUTTONS");
//getVote
int blueState = LOW , redState = LOW ;
while(1) {
blueState = digitalRead(BLUE_BUT);
redState = digitalRead(RED_BUT);
if(blueState == HIGH){
Serial.println("BLUE");
break;
}
if(redState == HIGH){
Serial.println("RED");
break;
}
}
Serial.println("PROGRAM COMPLETE");
}
(I cut the first part of the code, which I think is not neccessary to post because I don't think there is a problem with that part)
dannable:
Also posted on SE rfid - MFRC522 won't detect cards after the first loop - Arduino Stack Exchange