Hello guys i need some help on how to store data to eeprom, below is my code that need modification.
#include <EEPROM.h>
#include <LiquidCrystal.h>
LiquidCrystal lcd(12, 11, 10, 9, 8, 7);
unsigned long flow=0;
float Litres;
void setup()
{
lcd.begin(16,2);
attachInterrupt(digitalPinToInterrupt(2), isr, FALLING);
lcd_initialize();
}
void loop()
{
byte count = 0;
byte digits = 6;
long buff;
Litres = flowmeasure()/1000.0;
buff = Litres;
if(buff == 0)
{
count = 1;
}
while(buff!=0)
{
count++;
buff /=10;
}
digits = digits - count;
lcd.setCursor(digits,1);
lcd.print(Litres, 3);
count = 0;
if(flow>=449999550)
{
flow = 0UL;
lcd.clear();
delay(100);
lcd_initialize();
}
}
void isr()
{
flow++;
}
float flowmeasure()
{
float flowcount;
flowcount = (flow/0.45);
return flowcount;
}
void lcd_initialize()
{
lcd.setCursor(0,0);
lcd.print("LITRES CONSUMED");
lcd.setCursor(0,1);
lcd.print("000000.000Litres");
}
Have you tried reading the documentation?
What do you want to save, where in the code, how often and how many times ?
When and where will you read the values previously saved ?
i want to save LITRES CONSUMED in EEPROM incase power is down and when power come back system can get LITRES CONSUMED from eeprom.
yes i have tried but i did not managed it, because i want to save data in the form of 000000.000 digits
EEPROM.put(myVar);
EEPROM.get(myVar);
EDIT... correct syntax...
EEPROM.put(address, myVar);
EEPROM.get(address, myVar);
thanks, but sorry can you help me to modify the code?
No.
I have shown you the EPPROM methods you need to call.
I have given you a link to the documentation... I suggest you read it.
i have tried it but when i try to compile it generate an error
Well show us your attempt at least...
It might help if the syntax in your examples was correct
True.. I should have left it at...
EEPROM.put()
EEPROM.get()
... and left it to the documentation.
help me please to modify the code
My original example did not have the correct syntax. You need to specify the address (memory location) you want to write to/read from.
That's why you need to read the documentation.
Try...
EEPROM.put(0, Litres);
EEPROM.get(0, Litres);
@mwanyamaki96 Please do not post pictures of code
Please follow the advice given in the link below when posting code, in particular the section entitled 'Posting code and common code problems'
Use code tags (the </> icon above the compose window) to make it easier to read and copy for examination
please help me i have not managed to solve my problem.
What did you try after it was pointed out that
EEPROM.put(Litres);
is the wrong syntax ?