I made a part of code to change the temperature limit for alarm system. On warm days user have to change the temperature limit with buttons and OLED display.
The question is: How can the variable templimit
keep its last setup value after many restarts(for many reasons)?
This is the code:
const int buttonPin = 8; // up
const int buttonPin1 = 3; // down
const int buttonPin2 = 2; // enter
int buttonPushCounter; // counter for the number of button presses
int buttonState;; // up
int buttonState1;; // down
int buttonState2;; // enter
int templimit; // temperature limit for alarm
void setup() {
Serial.begin(9600);
Serial.print("Update temperature limit if not wait 10 sec time out");
updatevalue();
Serial.print("Done");
}
void loop() {
// do nothing
}
int updatevalue(void) {
int timenow;
int timepassed;
timenow = millis();
// this loop is just for 10 sec time out
while (buttonState == LOW and buttonState1 == LOW and buttonState2 == LOW) {
buttonState2 = digitalRead(buttonPin2); // enter
buttonState = digitalRead(buttonPin); //up
buttonState1 = digitalRead(buttonPin1); // down
timepassed = (millis() - timenow);
if (timepassed >= 10000)
return 0;
}
while (buttonState2 != HIGH) { // do this until enter is pressed
buttonState2 = digitalRead(buttonPin2); // enter
buttonState = digitalRead(buttonPin); //up
buttonState1 = digitalRead(buttonPin1); // down
if (buttonState == HIGH) { // up
buttonPushCounter++;
Serial.print("number of button pushes: ");
Serial.println(buttonPushCounter);
}
if (buttonState1 == HIGH) { // down
buttonPushCounter-- ;
Serial.print("number of button pushes: ");
Serial.println(buttonPushCounter);
}
delay(700);
}
templimit = buttonPushCounter; // update templimit value
}