Menu

Arduino blink with condition

//Constants
const int ledPin = 13; //The pin we have the LED on
//Variables
boolean ledOn = true; //Store the last status of the LED
//Sketch
void setup()
{
pinMode(ledPin, OUTPUT); //Set the pin we got the LED on to OUTPUT
}
void loop()
{
digitalWrite(ledPin, ledOn?HIGH:LOW); //Turn the LED on or off, depending on if ledOn is true or false
ledOn = ledOn?false:true; //Toggle between false and true
delay(500);
}