Lab_interaccio/2011/QAN_v2/RFID.ino

46 lines
1.1 KiB
Arduino
Raw Normal View History

2025-02-25 21:29:42 +01:00
// RFID llegit de test
//char rfid[13]="13004C8ED302";
char rfid[13]="";
boolean rfid_read()
{
byte i = 0;
byte val = 0;
byte bytesread = 0;
boolean checking = false;
if(Serial.available() > 0) {
if((val = Serial.read()) == 2) { // check for header
bytesread = 0;
while (bytesread < 12) { // read 10 digit code + 2 digit checksum
if( Serial.available() > 0) {
val = Serial.read();
if((val == 0x0D)||(val == 0x0A)||(val == 0x03)||(val == 0x02)) { // if header or stop bytes before the 10 digit reading
break; // stop reading
}
rfid[bytesread] = val;
bytesread++; // ready to read next digit
}
}
// Output to Serial:
if (bytesread == 12) { // if 12 digit read is complete
Serial.println();
Serial.println(rfid);
checking = true;
bytesread = 0;
}
}
}
return(checking);
}