Hey all, i am working in rfid and now here i very confused in my coding coz i wanna make it could be interrupt where if that tag has been scan by reader it will call process, and if that other process has been scan too that first tag process must be stop and process 2 will be called. please your help.
my code of rfid :
int buffer[14];
int *buffer_at;
int *buffer_end = buffer + sizeof(buffer);
String checksum;
boolean tagfound = false;
void setup()
{
Serial.begin(9600);
Serial.println("Serial Ready");
Serial1.begin(9600);
Serial.println("RFID Ready");
}
void loop()
{
if (Serial1.available()){
delay(20);
buffer_at = buffer;
while ( buffer_at < buffer_end )
{
*buffer_at++ = Serial1.read();
}
tagfound = true;
Serial1.end();
Serial1.begin(9600);
}
if (tagfound){
buffer_at = buffer;
uint32_t result = 0;
// Skip the preamble
++buffer_at;
// Accumulate the checksum, starting with the first value
int checksum = rfid_get_next();
// We are looking for 4 more values
int i = 4;
while(i--)
{
// Grab the next value
int value = rfid_get_next();
// Add it into the result
result <<= 8;
//Serial.print("Add =");
//Serial.println(result);
result |= value;
//Serial.print("Xor =");
//Serial.println(result);
// Xor it into the checksum
checksum ^= value;
}
// Pull out the checksum from the data
int data_checksum = rfid_get_next();
// Print the result
Serial.print("Tag: ");
Serial.print(result);
if ( checksum == data_checksum )
Serial.println(" OK");
else
Serial.println(" CHECKSUM FAILED");
// We're done processing, so there is no current value
tagfound = false;
}
}
int rfid_get_next(void)
{
// sscanf needs a 2-byte space to put the result but we only need one byte.
int hexresult;
// Working space to assemble each byte
static char byte_chars[3];
// Pull out one byte from this position in the stream
snprintf(byte_chars,3,"%c%c",buffer_at[0],buffer_at[1]);
sscanf(byte_chars,"%x",&hexresult);
buffer_at += 2;
return hexresult;
}
so hopefully you could help me :mrgreen: