So far I have a code allowing me to put and update temperature changes to EEPROM. There are 2 push buttons which are used to change the temp value (up or down depends on how many times I press), and I wanna save the new value to EEPROM only when the pushbuttons are not pressed for 10s.
Any ideas how to detect if the buttons are not pressed for 10s? Thank you!
Save the millis() value when the buttons become not pressed and set a boolean to true. Then, each time through loop() if the boolean is true test whether 10 seconds has elapsed. If so then save the value and set the boolean to false
The code below from Robin2's post here is probably what you need, and is slightly simpler (although perhaps not as intuitive) than UKHeliBob's approach above:
buttonState = digitalRead(buttonPin);
if (buttonState == HIGH) { // assumes LOW when pressed
lastTimeButtonWasNotPressed = millis();
}
if (millis() - lastTimeButtonWasNotPressed >= interval) {
// do stuff
}
It essentially keeps "zeroing" the timer if the button is not pressed.
Whilst the button remains not pressed lastTimeButtonWasNotPressed will be repeatedly updated to the current value of millis(). Will the test of whether the period has elapsed ever be true ?