I wanted to set up a snippet into my existing code that if it has been running without button press for a while, it dims the LED display.
2 buttons are attached via interrupts and I do need to maintain the LED display or the 4 pins output so those needs to remain active. I get the impression sleep mode would turn those outputs off? If so, is this a safe idle loop to use?
void displayidle() {
for (int x = LEDdefault; x <= 0; x--); {
sevseg.refreshDisplay();
sevseg.setBrightness(LEDdefault - x);
delay(50);
if (x < 1) x = 1;
}
displayidle loop is triggered when buttonidle has reached 10,000 (one increment per main loop or a few hundreds per second). If the button was pressed (either of them), it resets buttonidle to 0. When it reaches 10,000, it should jump to displayidle loop.
There, it loops until X reaches 1 and stays at 1 (minimum display brightness) and never reaches zero so it remains in permanent loop. The interrupt of the button should work to end this loop? Or am I making a mountain out of a molehill? The entire code is a bit over 5k (only idle bit is shown) and I have plenty of spare flash space on ATMega328 for any more coding to make for optional idle loop.
delay 50 should mean the display would go from preset brightness (1-100 permitted in sevseg library, I have it at 70) to completely dim in about 3.5 seconds.