Thank you Arrch for that correction and Henry_Best, my objective is to use the if statement so that the first statement, if it's true, activates the second statement and the LED only turns on if the second statement is true. The two push button presses have to happen within a two seconds delay.
With this new code, the LED is always off until I press and hold the push button for two seconds, then it turns on and stays on for two seconds.The same as before.
Here's the newest code:
const int pushButton = 12;
const int ledPin = 13; // LED connected to digital pin 13
void setup() {
pinMode(ledPin, OUTPUT);
// initialize serial communications:
pinMode (pushButton, INPUT_PULLUP);
Serial.begin(9600);
}
void loop()
{
if (digitalRead(pushButton) == LOW) {
delay(2000);
if (digitalRead(pushButton) == LOW) {
digitalWrite(ledPin, HIGH);
}
else {
digitalWrite(ledPin, LOW);
}
}
else {
digitalWrite(ledPin, LOW);
}
}