Hi guys.
I got a feeling that EEPROM is going round and round in my loop option.
Simply saying:
Double click read EEPROM,and check if pressure is lover equal or higher.
If it`s lower, set output RedLed, HIGH.
If pressure reach value stored in EEPROM, set RedLed, LOW... But i think that this eeprom read goes in circle.
Serial.print return eeprom value all the time.
it worries me that the eeprom read/write will exceed his 100.000 cycle.
Can someone confirm that to me this section
void loop()
{
raw = analogRead(sensor1);
voltage = (float) raw / 1023.0 * 5.0;
pressure = (((float)analogRead(sensor1) / 1023.0 * 5.0) - 0.5) * 37.5;
int reading = digitalRead(Button);
Serial.println(pressure,0);
if(pressure >= readMem) //CHECK HERE
{
doNothing();
}
What should i do to read it only once.
The whole code.
#include <EEPROM.h>
const int Button = 30;
const int RedLed = 22;
const int GreenLed = 24;
const int sensor1 = A0;
int bounceTime = 50;
int holdTime = 1500;
int doubleSwitchTime = 450;
int doubleReleaseTime = 3000;
int lastReading = HIGH;
int hold = 0;
int single = 0;
int LEDstate = 0;
int readSensor1 = 0;
int readMem = EEPROM.read(20);
unsigned long onTime = 0;
long lastSwitchTime = 0;
int raw;
float voltage;
float pressure; //Pressure PSI
void setup()
{
Serial.begin(9600);
pinMode(Button, INPUT_PULLUP);
digitalWrite(RedLed, LOW);
pinMode(RedLed, OUTPUT);
pinMode(GreenLed, OUTPUT);
pinMode(sensor1, INPUT);
}
void loop()
{
raw = analogRead(sensor1);
voltage = (float) raw / 1023.0 * 5.0;
pressure = (((float)analogRead(sensor1) / 1023.0 * 5.0) - 0.5) * 37.5;
int reading = digitalRead(Button);
Serial.println(pressure,0);
if(pressure >= readMem) //CHECK HERE
{
doNothing();
}
//First Pressed
if(reading == LOW && lastReading == HIGH) {
onTime = millis();
}
//Held
if(reading == LOW && lastReading == LOW) {
if((millis() - onTime) > holdTime) {
hold = 1;
blinkLED();
}
}
//Released
if (reading == HIGH && lastReading == LOW) {
if (((millis() - onTime) > bounceTime) && hold != 1) {
doublePress();
}
if(hold == 1) {
Serial.println("HELD");
storeMemory();
digitalWrite(RedLed, LEDstate);
hold = 0;
}
}
lastReading = reading;
if (single == 1 && (millis() - lastSwitchTime) > doubleSwitchTime) {
Serial.println ("SINGLE PRESS");
single = 0;
}
}
void doublePress() //CHECK HERE
{
if ((millis() - lastSwitchTime) >= doubleSwitchTime) {
single = 1;
lastSwitchTime = millis();
return;
}
if((millis() - lastSwitchTime) < doubleSwitchTime) {
EEPROM.read(20);
Serial.println("DOUBLE PRESS");
Serial.println(EEPROM.read(20));
single = 0;
lastSwitchTime = millis();
}
if(pressure < EEPROM.read(20))
{
up();
}
if(pressure > EEPROM.read(20))
{down();
}
}
void storeMemory()
{
EEPROM.write(20,pressure);
Serial.println("DONE");
}
void readMemory()
{
}
void toggleLED()
{
}
void blinkLED()
{
if (LEDstate == 0) {
digitalWrite(RedLed, HIGH);
delay(200);
digitalWrite(RedLed, LOW);
delay(200);
digitalWrite(RedLed, HIGH);
delay(200);
digitalWrite(RedLed, LOW);
delay(200);
digitalWrite(RedLed, HIGH);
delay(200);
digitalWrite(RedLed, LOW);
}
}
void up()
{
digitalWrite(RedLed, HIGH);
digitalWrite(GreenLed, LOW);
}
void doNothing()
{
digitalWrite(RedLed, LOW);
digitalWrite(GreenLed, LOW);
}
void down()
{
digitalWrite(RedLed, LOW);
digitalWrite(GreenLed, HIGH);
}