How exit EEPROM.read afted x ammout of time

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);
    }

I got a feeling that EEPROM is going round and round in my loop option.

Put a Serial.print in where the EEPROM is read to prove or disprove it.

What should i do to read it only once

Set a variable to true when you read the EEPROM and check it before reading again. If it true then don't read the EEPROM.

By the way, I was amused by the function named doNothing(); that does something.

Heh. you right about doNothing() but it`s easy for me to track all.

What i`m thinking now maybe to set
global -> int readMem = 0;

and then in where the double click is executed

int readMem = EEPROM.read(20);

I did this but then i only get one RedLed blink when pressure is below the value of eeprom.

the think is that i need this eeprom value for x ammount of time until the value is reached.

post above didn`t worked.

Can you please explain in words (not code) what it is you are trying to do ?

right.
You have a ballon.
first you inflate it say to 100psi manually.
than you store pressure above in to eeprom with press and hold.
than you pick another ballon that has 0 psi and you want to automatically inflate to 100psi with double click.
All i want to read eeprom "once" with double click.

the sketch i posted workes perfectly to what i want so far.
but only if loop include that

if(pressure >= EEPROM.read(20)) //CHECK HERE
{
doNothing();
}

which i think it reads eeprom every it loop

As I said in reply #1

Set a variable to true when you read the EEPROM and check it before reading again. If it true then don't read the EEPROM.

Apart from slowing down the program a little it will not hurt the EEPROM is you read from it multiple times, it is writing to it that causes the problem.

In your description you say

You have a ballon.
first you inflate it say to 100psi manually.

Will this always happen immediately before you inflate the second balloon ? If so then why use the EEPROM ? Even the Arduino is powered down between balloon inflations you could prompt the user for the target pressure for this session.

UKHeliBob:
As I said in reply #1

Can you please post example? i`m not that flexible yet.:slight_smile:

[/quote]
In your description you sayWill this always happen immediately before you inflate the second balloon ? If so then why use the EEPROM ? Even the Arduino is powered down between balloon inflations you could prompt the user for the target pressure for this session.
[/quote]

well not quite. as this is only en example i am going to have 4 bellows (airbags) so instead of setting every corner(wheel height) individually you just hit double press and everythig inflates in one go to the pressure you store in eeprom.

If you saying that reading eeprom everytine loop circles is fine, that i don`t thik that what i did should be a problem as I probably going to write eeprom maybe 10 times during time that i use my controller.

Can you please post example? i`m not that flexible yet

#include <EEPROM.h>
boolean doneReading = false;

void setup()
{
  Serial.begin(115200);
}

void loop()
{
  if (doneReading == false)
  {
    Serial.print(EEPROM.read(255));
    doneReading = true;
  }
}

Thank you