UKHeliBob:
Don't try to write it all at once.Write one program that puts a fixed int value into a known EEPROM location in the setup() function.
Write a second program that gets the int value from the same EEPROM location in setup() and prints its value to the Serial monitor.
Note the use of put() and get() rather than write() and read()
There are examples of both included with the EEPROM library.
i cant use put and get because after i learn it im kinda confuse how to apply it but i use write and read instead because its pretty simple to use, and now another problem is when the arduino is start,the value is null but if sensor is sense something, it goes 0 instead 1.
#include <LiquidCrystal.h>
#include <EEPROM.h>
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
const int sensorPin = A0; //analog pin 0
const int ledPin = 13; // the pin that the LED is attached to
// vars
int sensorCounter = 0; // counter for the number of button presses
int sensorState = 0; // current state of the sensor
int resetButton = 0;
int addr = 0;
int debounceTime = 20;
void setup() {
// initialize the sensor pin and input
pinMode(sensorPin, INPUT);
// initialize the LED as an output
pinMode(ledPin, OUTPUT);
// initialize serial communication
Serial.begin(9600);
// set the matrix
lcd.begin(16,2);
lcd.print("Flight Cycle :");
sensorCounter = EEPROM.read(0);
EEPROM.write (0,0);
for (int i = 0 ; i < EEPROM.length() ; i++) {
EEPROM.write(i, 0);
}
}
void loop() {
// read the sensor input pin:
int sensorState = analogRead(sensorPin);
// if sensor is closer than than x distance
if (sensorState == 400 ) {
sensorCounter++;
EEPROM.write(0, sensorCounter);
lcd.setCursor (0, 1);
lcd.print(sensorCounter / 2);
int val = analogRead(0) / 4;
// show output on the digital display
addr = addr + 1;
if (addr == EEPROM.length()) {
addr = 0;
}
// slow down the output
delay(2000);
}
}
thank you by the way guys