I am trying to save two variables "i,j" to EEPROM but I can save only one "i" , what I am doing wrong with EEPROM address ?
Code: Select all
#include
#include
LiquidCrystal lcd(PA0, PA1, PA2, PA3, PA4, PA5);
int i;
int ovfi;
int j;
int ovfj;
void setup()
{
pinMode(PC13, OUTPUT);
pinMode(PB6, INPUT_PULLDOWN);
pinMode(PB9, INPUT_PULLDOWN);
pinMode(PB5, INPUT_PULLDOWN);
pinMode(PB8, INPUT_PULLDOWN);
lcd.begin(16, 2);
/////////////////////////////////////////////////////
EEPROM.read(0, (uint16*)&i);
EEPROM.read(0, (uint16*)&j);
///////////////////////////////////////////////////
}
// the loop function runs over and over again forever
void loop() {
ovfi = 10000 - i; // ????
ovfj = 10000 - j;// ????
if (digitalRead(PB9) == HIGH)
{
if (i < 6000)
// if (i < 25)
{
i++;//if pin PB3 is pressed and the duty ratio value is less than 255
analogWrite(PB0, i); // analogWrite values from 0 to 255
delay(100);
}
}
if (digitalRead(PB6) == HIGH)
{
if (i > 0)
{
i--;// if pin PB5 is pressed and the duty ratio value is greater than 0
analogWrite(PB0, i); // analogWrite values from 0 to 255
delay(100);
}
}
//////////////////////////////////////////////////////////////
EEPROM.write(0, i); //write counter to address 0
//////////////////////////////////////////////////////////////
if (digitalRead(PB8) == HIGH)
{
if (j < 6000)
// if (i < 25)
{
j++;//if pin PB3 is pressed and the duty ratio value is less than 255
analogWrite(PB0, i); // analogWrite values from 0 to 255
delay(100);
}
}
if (digitalRead(PB5) == HIGH)
{
if (j > 0)
{
j--;// if pin PB5 is pressed and the duty ratio value is greater than 0
analogWrite(PB0, i); // analogWrite values from 0 to 255
delay(100);
}
}
/////////////////////////////////
// EEPROM.write(0, j);
EEPROM.write(500, j);
////////////////////////////////////
digitalWrite(PC13, HIGH);
// delay(1000);
delay(i);
digitalWrite(PC13, LOW);
//delay(1000);
delay(j);
lcd.setCursor(0, 1);
lcd.println(i);
lcd.println(j);
}
Code: Select all
EEPROM.read(0, (uint16*)&i);
EEPROM.read(0, (uint16*)&j);