Good afternoon everyone,
I am preparing a test with the EEPROM memory of my arduino uno. The test consists of 2 buttons, Button 1 each time I press prints an integral number, it starts with 0, and each time I press it adds 1 and I keep it in the consecutive address of the EEPROM memory.
Button2 prints the total number of times I have pressed Button1, resets the counter to 0, and saves it to my EEPROM.
I hope I have explained myself well, I leave you the code that works well for me:
#include <EEPROM.h>
const int boton1 = 8;
const int boton2 = 9;
bool valorBoton1, valorBotonAnt1 = false;
bool valorBoton2, valorBotonAnt2 = false;
int count = 0;
byte direction = 0;
void setup() {
Serial.begin(9600);
pinMode(boton1,INPUT);
pinMode(boton2,INPUT);
}
void loop() {
EEPROM.get(direction, count);
valorBoton1 = digitalRead(boton1);
valorBoton2 = digitalRead(boton2);
if (valorBoton1 && !valorBotonAnt1){
Serial.println(count);
count++;
direction++;
EEPROM.update(direction, count);
}
valorBotonAnt1 = valorBoton1;
delay (5);
if (valorBoton2 && !valorBotonAnt2){
Serial.println("The Total is:");
Serial.println(count);
count = 0;
direction++;
EEPROM.update(direction, count);
}
valorBotonAnt2 = valorBoton2;
delay (5);
}
And when I turn off and turn on the arduino, I get totally different values, style 162, or 470 ... without being consecutive.
If you have any suggestions or hints that can guide me, I will be very grateful.