Hello friends, this is a test program I'm writing to get eeprom to read back a couple of long integers. So far, I incremented up a few hundred clicks, (because I could not load 45,000 on startup) then started the chip again, I had in memory say "235" and "188" i.e. When I restart, the numbers comes back for a few loops then it goes to 61 and 120, then sits there. Restarting only reloads these two values, no matter if I change them. Can't get anything to write.
I have to store a 5 or 6 digit in memory and retrieve it, change it, put it back, etc. So this is not working. The print lines are for debugging.
Code:#include <EEPROM.h> const int buttonPin3 = 3; const int buttonPin4 = 4; const int buttonPin5 = 5; int button3 = 0; int button4 = 0; int button5 = 0; long y2 = 45000; long y1 = 15000; long oldy2; long oldy1; void setup() { pinMode(buttonPin3, INPUT); pinMode(buttonPin4, INPUT); pinMode(buttonPin5, INPUT); Serial.begin(9600); byte addr1; byte addr2; y2 = EEPROM.read(20); y1 = EEPROM.read(10); Serial.println(y2, DEC); Serial.println(y1, DEC); } void loop() { Serial.println(y2, DEC); Serial.println(y1, DEC); delay(10); button3 = digitalRead(buttonPin3); // reading the buttons. button4 = digitalRead(buttonPin4); button5 = digitalRead(buttonPin5); if(button3 == HIGH) { y2 = y2 + 1; // incrementing byte addr2; oldy2 = EEPROM.read(addr2); //compare old and new value if(y2 != oldy2) { byte addr2; EEPROM.write(addr2, y2); // write in eeprom Serial.println(y2, DEC); delay(100); } } if(button4 == HIGH) { y1 = y1 + 1; byte addr1; oldy1 = EEPROM.read(addr1); if(y1 != oldy1) { byte addr1; EEPROM.write(addr1, y1); Serial.println(y1, DEC); delay(100); } } }



LinkBack URL
About LinkBacks



