I need to store 5 digits or more to store it safely in EEPROM. How to achieve it. Is there any solution for this or any hardware we can addHow to store a 6 digit value in EEPROM? But it is holding only 256.
help plese??
#include <EEPROM.h>
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
// Set the LCD address to 0x27 for a 16 chars and 2 line display
LiquidCrystal_I2C lcd(0x3F, 16, 2);
// pin definitions
int ledPin = 13;
int buttonPin = 7;
const int resetPin = 2;
int resetValue = 0;
// global variables
int lastButtonState = 1;
long unsigned int lastPress;
int debounceTime = 20;
int counter;
void setup() {
// setup pin modes
pinMode(ledPin, OUTPUT);
pinMode(buttonPin, INPUT_PULLUP);
pinMode(resetPin, INPUT);
lcd.begin();
// Turn on the blacklight and print a message.
lcd.backlight();
//initialise Serial port
Serial.begin(9600);
byte value = EEPROM.read(0);
lcd.print("Last Count");
lcd.setCursor(7, 1);
lcd.print(value);
//assign counter the value of address 0
counter = EEPROM.read(0);
//write a 0 to address 0. This allows for consecutive resets to reset the counter
EEPROM.write(0, 0);
}
void loop() {
int resetCount = digitalRead(resetPin);
if (resetCount == LOW) {
counter = 0;
EEPROM.write(0, counter);
delay(100);
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("Product Count");
lcd.setCursor(7, 1);
lcd.print(counter);
}
int buttonState = digitalRead(buttonPin); //read the state of buttonPin and store it as buttonState (0 or 1)
if ((millis() - lastPress) > debounceTime) //if the time between the last buttonChange is greater than the debounceTime
{
lastPress = millis(); //update lastPress
if (buttonState == 0 && lastButtonState == 1) //if button is pressed and was released last change
{
counter++;
EEPROM.write(0, counter); //write counter to address 0
digitalWrite(ledPin, HIGH); //momentary LED
lastButtonState = 0; //record the lastButtonState
//print the results
Serial.print("Counter: ");
Serial.println(counter);
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("Product Count");
lcd.setCursor(7, 1);
lcd.print(counter);
}
if (buttonState == 1 && lastButtonState == 0) //if button is not pressed, and was pressed last change
{
lastButtonState = 1; //record the lastButtonState
digitalWrite(ledPin, LOW); //momentary LED
}
}
}
999999Eeprom.ino (2.28 KB)