-27-
v7.0
Code examples and extended information
credit = RFID13.vector2int(aux); // convert the card data to int
if (credit >= tripFare)
{
sprintf(text, “%d”, credit - tripFare);
RFID13.string2vector(text, aux);
for (int i=0; i<sizeof(text); i++) // clear this variable
{
text[i] = ‘\0’;
}
// **** write aux in block number 1, and check afterwards
state = RFID13.write(1, aux);
if (state == 0)
{
//miSerial.print(“ --> correct write checked”);
completed = true;
credit = credit - tripFare; // only substract if success happened
// **** check the 16 bytes in block 1
state = RFID13.read(1, aux);
if (state == 0) // if the read command was successful, we show the data (16
bytes)
{
USB.print(“\r\n Credit after the trip: “);
for (int i=0; i<16; i++)
{
if (aux[i] == ‘\0’) // to avoid showing voids
break;
USB.print(aux[i], BYTE); // print the 16 bits of block number 1, now in ASCII
code
}
}
}
}
else
{
USB.print(“\r\
n ** Not enough credit”);
}
}
}
if (completed == true) // a complete operation was done !!!
{
USB.print(“\r\n ACCESS GRANTED !!”);
completed = false;
for (int i=0; i<2; i++) // blink the LED fast to show not-OK
{
Utils.blinkLEDs(50);
}
}
else
{
for (int i=0; i<10; i++) // blink the LED fast to show not-OK
{
Utils.blinkLEDs(50);
}
}
delay(2000); // wait some time in each loop
}