This is wending machine program but i cant get last value of pad when power off and on

#include <EEPROM.h>
#include <LiquidCrystal.h>
const int rs = 12, en = 11, d4 = 5, d5 = 4, d6 = 3, d7 = 13;
LiquidCrystal lcd(rs, en, d4, d5, d6, d7);
#define BUTTON 2
int button_state=0;
int count = 0;
int value;
int pad = 25;
int rr;
int a=5;
void setup()
{
lcd.begin(16, 2);
//Serial.begin(9600);
attachInterrupt(digitalPinToInterrupt(BUTTON),countf,RISING);
EEPROM.write(0, pad);
pad = EEPROM.read(0);
}
void loop()
{
if(count==0)
{
lcd.setCursor(0,0);
lcd.print("ENTER COIN");
lcd.setCursor(0,1);
lcd.print("REMAINING PAD:");
lcd.print(pad);

if(count==1)
{
lcd.clear();
}
}
else if(count==5)
{
pad=pad-1;

lcd.clear();
lcd.setCursor(0,0);
lcd.print("PROCESING.....");
delay(4000);
count = 0;
return;
exit(0);
}
else if(count<5)
{
lcd.setCursor(0,0);
lcd.print("Remaining Rupees");
lcd.setCursor(0,1);
lcd.print(rr);

}
}
void countf()
{
count=count+1;

rr=a-count;

//Serial.println(count);
}

pad is an int which is 2 bytes on 8-bit AVR processors and 4 bytes on 32 bit processors. EEPROM.write() only writes a single byte, EEPROM.read() only read a single byte.

Use EEPROM.put() to store an integer and EEPROM.get() to read it.

1 Like

You initialize 'pad' to 25. In setup() you write the 25 to EEPROM before you read back the 25 from EEPROM. You will always get the value of 25. If you want the LAST value, DON'T write 25 into EEPROM before you read 'pad' from EEPROM and write 'pad' to EEPROM when you change it.

1 Like

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.