pressure switched relay - save and load target value

Hello, i am making little project which is based on Arduino nano. There is analog pressure sensor, oled screen, rotary encoder and relay. Via encoder is set target on which is relay turn on. All is working fine. But i need little help. My IQ are not too high for understand how to work with eeprom. I need to save target value via button (2s press) on encoder, store it and set it after powering the arduino. Is there anyone able to help me? Sorry for my english.

Thanks

Arduino_encoder_boost_relay.ino (1.74 KB)

So, during normal operation of your sketch, if you press the encoder button for 2 seconds, you want to be able to enter/update this value:

int target = 0 ; //Stores target temp

then store it in the EEPROM (probably after another click on the encoder buttons)

When the sketch starts normally, it fetches this value from the EEPROM and uses it.

Is that correct ?

Yes this is exactly what i need. Long press to save actual target value seted via encoder to eeprom. And after load this value and set it after every start but so that it can still be adjustable.

Thanks !

It appears that you already have code in the loop() to adjust the variable target.
It detects changes to the encoder position and updates target.

A simpler way is simply to retain the original code but with the addition that, at the end of a session, the target value is saved to EEPROM (if it has changed). At the beginning of the next session, the value is retrieved from the EEPROM. Would that work for you?

It is also possible to do it with a long button press to initiate the "configuration" of the value target if that is what you prefer. You then maybe have to consider a timeout if someone initiates the update of target, but does not finish it.

Is there anyone willing to write an example code for this ? Thanks

This topic was automatically closed 120 days after the last reply. New replies are no longer allowed.