const int SWT1 = 3; // the number of the pushbutton pin
const int LED1 = 2;
int start;
int lastMillis;
void setup() {
// initialize serial communication at 9600 bits per second:
Serial.begin(9600);
pinMode(SWT1, INPUT_PULLUP);
pinMode(LED1, OUTPUT);
// digitalWrite(LED1, HIGH);
}
void loop() {
if (!digitalRead(SWT1))
{
if (start == false) // do we want to start the LED on/off cycle?
{
lastMillis = millis(); // initialize the timing
digitalWrite(LED1, HIGH); // turn LED on
start = true; // this prevents reinitializing lastMillis
}
}
if ( millis() - lastMillis >= 20UL) // if we in in checking mode, has the time expired?
{
digitalWrite(LED1, LOW); // turn led off
start = false;
while(!digitalRead(SWT1)){}
delay(10); // For debouncing
}
}