i did something similar. For me it was a heartbeat led that does 1500ms of fastblink when a button is pressed.
might not be the most efficient route as i am still learning. But it works exactly as i wanted it to work.
in abridged code:
void loop(){
heartbeat(heartbeatRate); //amount of time led is on and off are equal
if (calButton){
heartbeatRateTemp = heartbeatRate; //store current heartbeat timer to restore later
heartbeatRate = .05; // quicker flash to signal a calibration has happened
specialFlash = true;
specialFlashTimer = millis();
calButtonPressed = true; // set variable to true to show button is pressed
lastPress = millis(); // set lastPressed to current time for debounce purposes
}
// if a calibration was performed and the quicker flashes happened for 1.5 seconds
if (specialFlash && millis() - specialFlashTimer > 1500){
specialFlash = false;
heartbeatRate = heartbeatRateTemp;
}
// if the calibration button is not pressed and more time has passed than the debounceTimer setting, set the variable to false
if (!calButtonState && (millis()-lastPress) > debounceTimer) calButtonPressed = false;
}
void heartbeat(double rate){
// Serial.print(statLEDstate);
// Serial.println(millis()-statTimer);
if (millis()-statTimer >= rate*1000){ // time since last flash is greater than rate set then change state of LED
if (statLEDstate) digitalWrite (statLED, LOW);
if (!statLEDstate) digitalWrite (statLED, HIGH);
statTimer = millis(); //reset timer
statLEDstate = !statLEDstate; // change led state variable
}