Program using a button timer

is this for an Arduino?

  • pin 27 is not an interrupt on an Uno or Mega
  • where are these defined
    ** timerBegin()
    ** timerAttachInterrupt()
    ** timerAlarmEnable()
    ** timerRestart()
    ** timerStop()
  • if there's a pullup on the button pin and you want to detect the press, why is the interrupt configured for RISING, instead of FALLING
  • if "CheckForTimeDone() is called before 1 second has expired and is not called again, how can it recognize that a second has expired?

in general, interrupts are overkill for recognizing button presses pressed by humans because interrupts are intended to detect event very quickly or of short duration.

and recognizing that a second has elapsed doesn't suggest the need for a quick response

consider


//Define constants ------------------------------------
#undef MyHW
#ifdef MyHW
#define BTN     A1
#else
#define BTN     27
#endif

#define LED_PIN 13

#define ONE_SECOND  1000

//Setup variables ------------------------------------
byte          butState = HIGH;
unsigned long msecLst;

//Initialization ------------------------------------
void setup () {
    digitalWrite (LED_PIN, LOW);
    pinMode      (LED_PIN, OUTPUT);
    pinMode      (BTN, INPUT_PULLUP);

    Serial.begin (115200);
}

//Main loop ------------------------------------
void loop () {
    unsigned long msec = millis ();
    if ( (0 != msecLst) && (msec > msecLst))  {
        msecLst = 0;
        Serial.println ("1 second has passed since the last button press!");
    }

    byte but = digitalRead (BTN);
    if (butState != but)  {
        butState = but;
        delay (10);         // debounce

        if (LOW == but)  {
            msecLst = msec + ONE_SECOND;
            msecLst = 0 == msecLst ? 1 : msecLst;
            Serial.println ("Pressed!");
        }
    }
}