For a life of me, I am finding it to hard absorb the timer and the timer interrupt. All I want something simple. Just want a timer to start when button is pressed and a timer interrupt to switch the button off at 30sec regards where the loop is. Appreciate any help
You don’t need an interrupt for this. If you think you need an interrupt, your code (or more correctly the code for what you are doing in loop) is wrong.
See the tutorials sticky post of how to do more than one thing at once, and how to wait without using delay.
Post your code if you want more help.
consider
// turn LED on with button press & off after some period of time
#define ON LOW
#define OFF HIGH
byte butPin = A1;
byte ledPin = 10;
byte butLst;
// -----------------------------------------------------------------------------
void setup (void)
{
digitalWrite (ledPin, OFF);
pinMode (ledPin, OUTPUT);
pinMode (butPin, INPUT_PULLUP);
butLst = digitalRead (butPin);
}
// -----------------------------------------------------------------------------
void loop (void)
{
static unsigned long msecLst = 0;
unsigned long msec = millis();
#define Period 5000
if (msecLst && msec - msecLst > Period) {
digitalWrite (ledPin, OFF);
}
byte but = digitalRead (butPin);
if (butLst != but) {
butLst = but;
if (LOW == but) { // button pressed
msecLst = msec;
digitalWrite (ledPin, ON);
}
delay (10); // debounce
}
}