Hi Trace!
Apologies for the late response ... I started answering the other day and then things went a little sideways here.
Anyhoo ....
I'm not 100% sure interrupts are needed for a project like this.
Also note that you can attach only one interrupt at a time (eg. one switch can have an interrupt attached - but only one at a time).
So if I understand your project correctly:
All LEDs (5) off when Arduino starts.
Press button X => LED X ON and all others off. ( where X = {1,2,3,4) )
If nothing pressed for 5 minutes: LED1 ON, rest OFF (5 minutes = 300 second = 300.000 milliseconds)
If nothing pressed for 5 minutes and 30 seconds: LED2 ON, rest OFF
If nothing pressed for 6 minutes: LED3 ON, rest OFF
If nothing pressed for 6 minutes and 30 seconds: LED4 ON, rest OFF
If nothing pressed for 7 minutes: All OFF or start the 5 minute cycle again
A few things I kept in mind:
You seemed to be using different colors for the 4 LEDs, so I shoved those in an array, so it will be easier to reference them, instead of a few if-then loops (which is still correct of course).
Additionally I've added a way to keep track of time so we can determine when the 5 minute marker has been passed.
For this I defined a few constants as well (NotPressed1, NotPressed2, etc) so you can easily change the timing for that if needed.
Also note that I wasn't sure what would happen after the last LED was reached (after the 5 minutes no button pressed), so I can up with 2 options:
The first one just starts the 5 minute loop again, where as the second option turns all LEDs dark.
I did write the code without having an Arduino handy ... so it is untested, but it does compile.
In code I'd do something like this - let me know how it works 😊
#define FASTLED_INTERNAL // just used to mute the Pragma messages when compiling
#include <FastLED.h>
#define NUM_LEDS 5
#define LED_PIN 5
#define buttonPin2 10
#define buttonPin3 9
#define buttonPin4 8
#define buttonPin5 7
// time slots when nothing was pressed: 5 minutes = 300 seconds = 300,000 milliseconds
#define NotPressed1 300000
#define NotPressed2 330000
#define NotPressed3 360000
#define NotPressed4 390000
#define NotPressed5 420000
unsigned long LastPressed = 0; // 0 = ignore lastPressed
CRGB leds[NUM_LEDS];
CRGB myColors[4] = { CRGB(0,0,255),
CRGB(255,0,255),
CRGB(255, 255, 0),
CRGB(0, 255, 255) };
void setup() {
FastLED.addLeds<WS2812B, LED_PIN, GRB>(leds, NUM_LEDS);
FastLED.setBrightness(100);
pinMode(buttonPin2, INPUT_PULLUP);
pinMode(buttonPin3, INPUT_PULLUP);
pinMode(buttonPin4, INPUT_PULLUP);
pinMode(buttonPin5, INPUT_PULLUP);
}
void loop() {
unsigned long SinceLastPressed; // Store time since last pressed
int CurrentLED = -1; // when -1 then no LED selected / button pressed
// Read buttons until we find one that is pressed (this can be done more elegant)
if(digitalRead(buttonPin2) == HIGH) { CurrentLED = 0; }
else if(digitalRead(buttonPin3) == HIGH) { CurrentLED = 1; }
else if(digitalRead(buttonPin4) == HIGH) { CurrentLED = 2; }
else if(digitalRead(buttonPin5) == HIGH) { CurrentLED = 3; }
if (CurrentLED==-1) {
if(LastPressed>0) { // Only do this if a button was ever pressed
SinceLastPressed = millis() - LastPressed; // milliseconds since last time button was pressed
// If after "NotPressed5" millioseconds, still nothing pressed:
// option1: start this loop again
if( SinceLastPressed>NotPressed5 ) {
LastPressed = millis - NotPressed1;
SinceLastPressed = NotPressed1;
}
// option2: turn all LEDs dark
// if( SinceLastPressed>NotPressed5 ) {
// FastLED.clear();
// }
if( SinceLastPressed>NotPressed4 ) {
CurrentLED = 3; }
else if( SinceLastPressed>NotPressed3 ) {
CurrentLED = 2; }
else if( SinceLastPressed>NotPressed2 ) {
CurrentLED = 2; }
else if( SinceLastPressed>NotPressed1 ) {
CurrentLED = 1; }
}
} else { // CurrentLED not equal -1? -> then a button was pressed
LastPressed = millis(); // save timestamp
}
FastLED.clear(); // set all LEDs to black
if (CurrentLED>-1) { // Set LED color of selected LED
leds[CurrentLED] = myColors[CurrentLED];
}
FastLED.show(); // Show LEDs
}