Hello, this is a counter system. I try to save the values when the power is out, and I did that using the EEPROM function, but the problem is that it only retains 256 numbers. Can I make it keep more than 3000?
i using arduino uno .
#include <LiquidCrystal.h>
int Contrast=75;
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
#include <EEPROM.h>
int ir_pin=13;
int counter=0;
int hitObject=false;
int pushbutton=13;
int button =0;//reset button
int i=0;
void setup()
{ pinMode(ir_pin,INPUT);
analogWrite(6,Contrast);
lcd.begin(16, 2);
lcd.setCursor(4, 0);
lcd.print("counter");
counter=EEPROM.read(i); //get the previously saved value from EEPROM address zero
}
void loop()
{ int val = digitalRead(ir_pin);
if((val==0)&&(hitObject==false))
{
counter++;
EEPROM.update(i,counter); //save the new value to EEPROM address zero
hitObject=true;
lcd.setCursor(7,1);
lcd.print(counter);
lcd.setCursor(7,1);
}
else if((val==1)&&(hitObject==true))
{
hitObject=false;
}
if(button==1){
counter=0;
}
}
What number do you get when you divide 3000 by 255? what remainder do you get?
missdrew:
What number do you get when you divide 3000 by 255? what remainder do you get?
sry for that iam just beginner why i divide 3000by255?
Use EEPROM.put() and EEPROM.get() to store integer values greater than 255. In the Arduino Uno, an integer is 2 bytes, but each eeprom address can only hold one byte. You will need to store you larger values in 2 eeprom memory locations, and the eeprom library will do that for you with EEPROM.put() and EEPROM.get().
https://www.arduino.cc/en/Reference/EEPROM
iam fine, thanks alot peter i try it
Peter-CAD-HST:
Hello ahmed_sliem
How are you?
The used EEPROM.update() function is limited to the byte datatype.
Try this:
if (counter!=EEPROM.get(address) EEPROM.put(address,counter);
Good luck
br Peter
and stay healthy
this my new code it read over 5000 number thats make me happy but itry now to make areset button (as apush button)
to back the value in adress 0 to zero how i make it ?
i try to use the clear funcation but nothing happen
#include <LiquidCrystal.h>
int Contrast=75;
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
#include <EEPROM.h>
int ir_pin=13;
int counter;
int hitObject=false;
int button =8;//reset button
int i=0;
void setup()
{ pinMode(ir_pin,INPUT);
pinMode(button,INPUT);
analogWrite(6,Contrast);
lcd.begin(16, 2);
lcd.setCursor(4, 0);
lcd.print("counter");
EEPROM.get(i,counter); //get the previously saved value from EEPROM address zero
}
void loop()
{
int val = digitalRead(ir_pin);
if((val==0)&&(hitObject==false))
{
counter++;
EEPROM.put(i,counter); //save the new value to EEPROM address zero
hitObject=true;
lcd.setCursor(6,1);
lcd.print(counter);
lcd.setCursor(6,1);
}
else if((val==1)&&(hitObject==true))
{
hitObject=false;
if (button==1)
{EEPROM.write(i, 0);
}
}
}