t is overwhelming
OK
The relevant functions are:-
unsigned long tokenInVar(){
unsigned long number = 0;
for(int i=0; i<8; i++) number = (number << 4) | convertFromHex(int(token[i]));
return(number);
}
unsigned long convertFromHex(int ascii){
if(ascii > 0x39) ascii -= 7; // adjust for hex letters upper or lower case
return(ascii & 0xf);
}
To convert a token in a string into a long int, note this gives you 4 bytes or 32 bits, good for most RFID tokens.
If you want more then use a long long, that gives you 64 bit numbers. Once in number form they are compared just like you compare any other number.
The token is in and array of chr token or C string ( note this is not String )
Then to store use:-
* *void saveToken(int point){ // saves the token in EEprom memory at point EEPROM.write(point, (tokensOnBoard[0] >> 24) & 0xff); EEPROM.write(point+1, (tokensOnBoard[0] >> 16) & 0xff); EEPROM.write(point+2, (tokensOnBoard[0] >> 8) & 0xff); EEPROM.write(point+3, tokensOnBoard[0] & 0xff); EEPROM.write(point+4,value[6]); EEPROM.write(point+5,value[7]); EEPROM.write(point+6,value[8]); }* *
This stores the token as 4 bytes plus three other values that my program needed to store, you might not need this. They were the MIDI channel, note number and velocity associated with each token.
The EEPROM is split up into slots of 7 bytes each and that function takes in a pointer to that slot or EEPROM address called point. Note how the big number is split up into bytes using the >> shift right operator and the bitwise AND operator & to mask off parts of the word just leaving a byte.
Another function you will have to implement is one to find the next free slot in the EEPROM when storing a new token.
* *int findFreeEntry(){ int i = 0; boolean found = false; while( found == false && i < 1000){ if( EEPROM.read(i) == 0xff && EEPROM.read(i+1) == 0xff && EEPROM.read(i+2) == 0xff && EEPROM.read(i+3) == 0xff ) found = true; if(!found) i +=7; } if(found) return i; else return -1; }* *
Also this searches the EEPROM for a match to a given token:-
```
- int matchToken(unsigned long token){
int i = 0;
boolean found = false;
while( found == false && i < 1000){
if( EEPROM.read(i) == ((token >> 24)& 0xff) && EEPROM.read(i+1) == ((token >> 16)& 0xff)
&& EEPROM.read(i+2) == ((token >> 8)& 0xff) && EEPROM.read(i+3) == (token & 0xff) ){
found = true;
}
if(!found) i +=7; // move on to the start of the next entry
}
if(found) return i; else return -1;
}*
```