(This was posted before tgm175 posted his explanation.)
OK I've made some changes to the code and tested it and with acknowledgements and thanks to tgm1175 who was the chef here, I wasn't even the sous chef, I was the washer-upper.
This is tested working.
THANKS
#include <Bounce.h>
const int switchPin1 = 7;
long switchPin1TriggeredTime = 10000;
Bounce bouncer = Bounce( switchPin1,5 );
void setup()
{
Serial.begin(57600);
pinMode(switchPin1, INPUT);
digitalWrite(switchPin1, HIGH); //pull up
Serial.println("TEST");
pinMode(13, OUTPUT);
}
void loop()
{
bouncer.update ( );
int value = !bouncer.read();
static unsigned long switch_timestamp = 0;
if(value && switch_timestamp && (millis() - switch_timestamp) >= switchPin1TriggeredTime) {
Serial.println("HEY SWITCH HAS BEEN 'ON' TOO LONG!!");
}
else if (!switch_timestamp && value) {
//The !switch_timestamp is to make sure we don't refresh the timer if the switch remained on.
//The pin just changed to on, start the timer
switch_timestamp = millis();
}
else if(!value && switch_timestamp) {
//Switch went off, while timer was running, disable the timer
switch_timestamp = 0;
Serial.println("TURNED OFF");
}
if(value) {
digitalWrite(13, HIGH); // LED on
}
if(!value) {
digitalWrite(13, LOW); // LED off
}
}