// .  Cancel button code

const byte BUTTON = 12; // define button pin
const byte alarm = 7; //    alarm LED

unsigned long buttonPushedMillis;       // when button was released
unsigned long alarmTurnedOffAt;         // when alarm led was turned on
unsigned long turnOnDelay = 2500;       // wait to turn off alarm LED
unsigned long turnOffDelay = 5000;      // turn off alarm LED after this time
bool alarmReady = false;                // flag for when button is let go
bool alarmState = false;                // for alarm LED is on or not.
// .  Cancel button code above

void setup() {
  
  pinMode(BUTTON, INPUT_PULLUP);        // button press gives LOW
  pinMode(alarm, OUTPUT);
  digitalWrite(alarm, HIGH);

}

void loop()

// .  Cancel button code to the end of sketch
{

  unsigned long currentMillis = millis();     // get the time at the start of this loop()

  // check the button
  if (digitalRead(BUTTON) == LOW) {

    buttonPushedMillis = currentMillis;       // update the time when button was pushed
    alarmReady = true;
  }

  if (alarmReady) {                           // make sure this code isn't checked until after button has been let go

    if ((unsigned long)(currentMillis - buttonPushedMillis) >= turnOnDelay) {

      digitalWrite(alarm, LOW);               // okay, enough time has passed since the button was let go.

      alarmState = true;                      // setup our next "state"

      alarmTurnedOffAt = currentMillis;        // save when the alarm LED turned off

      alarmReady = false;                     // wait for next button press
    }
  }

  if (alarmState) {                           // see if we are watching for the time to turn off LED

    if ((unsigned long)(currentMillis - alarmTurnedOffAt) >= turnOffDelay) {
      alarmState = false;                     // see if we are to put alarm on again (boiler still cold)
      digitalWrite(alarm, HIGH);
    }
  }
}