Hi, i have created a EEPROM write and read to store a userlist that consists of fingerid and employeeno
below are the codes that i use to read and write.
My problem is that when i write in the current address, it looks like the other address data that run before the upcoming data became random number.
struct strUsers {
byte fingerid;
long empid;
} user;
//The data is pass from the html inputs and the 200 and 400 address set is the slots i plan to use
void writeUser(byte fingerid, long empid)
{
Serial.println("Writing User");
EEPROM.write(200 + (int)fingerid, fingerid);
EEPROMWritelong(400 + (int)fingerid, empid);
EEPROM.commit();
}
void readUser()
{
int a = 0;
while (a <= 100)
{
byte checkfinger = EEPROM.read(200 + a);
long checkemp = EEPROMReadlong(400 + a);
Serial.println("No." + (String)a + " " + (String)checkfinger +" "+ (String)checkemp);
a++;
}
}
below this is the helper code for EEPROM write/read long
void EEPROMWritelong(int address, long value)
{
byte four = (value & 0xFF);
byte three = ((value >> 8) & 0xFF);
byte two = ((value >> 16) & 0xFF);
byte one = ((value >> 24) & 0xFF);
//Write the 4 bytes into the eeprom memory.
EEPROM.write(address, four);
EEPROM.write(address + 1, three);
EEPROM.write(address + 2, two);
EEPROM.write(address + 3, one);
}
long EEPROMReadlong(long address)
{
//Read the 4 bytes from the eeprom memory.
long four = EEPROM.read(address);
long three = EEPROM.read(address + 1);
long two = EEPROM.read(address + 2);
long one = EEPROM.read(address + 3);
//Return the recomposed long by using bitshift.
return ((four << 0) & 0xFF) + ((three << 8) & 0xFFFF) + ((two << 16) & 0xFFFFFF) + ((one << 24) & 0xFFFFFFFF);
}
below image is the sample output i get when i write it, the No.1 should be fingerid 1 and employeeid 9001 before i submit the No.2, but it somehow became random number for employeeid
