I have made a program that increments a counter everytime the up button is pressed. I am trying to write this value to EEPROM, so that when I turn my board off and on again, the value before power off is shown on screen.
I wrote this code but the value doesn't seem to be written to EEPROM. The counter incrementation works fine.
#include <EEPROM.h>
#include <Adafruit_RGBLCDShield.h>
#include <utility/Adafruit_MCP23017.h>
Adafruit_RGBLCDShield lcd = Adafruit_RGBLCDShield();
int addr = 0;
byte value;
void setup() {
lcd.begin(16, 2);
lcd.setCursor(0,0);
}
int a;
void loop() {
uint8_t buttons = lcd.readButtons();
if (buttons) {
lcd.clear();
lcd.setCursor(0,0);
if (buttons & BUTTON_UP) {
a+= 1;
EEPROM.write(addr, a);
value = EEPROM.read(addr);
lcd.print(value);
delay(100);
}
}
}
Thanks for the help!
EEPROM.read()
insetup()
if you want the value restored at boot time.