No. 2 – Alternately blinking LED

Task: We want to let two LEDs blink alternately.

Required equipment: Microcontroller / two LEDs (blue) / two resistors with 100 Ohm / Breadboard / cables




void setup()

{ //We are starting with the setup

pinMode(7, OUTPUT); //Pin 7 is defined as output

pinMode(8, OUTPUT); //Pin 8 is defined as output


void loop()

{ //The main part starts

digitalWrite(7, HIGH); //turn on the LED on pin 7

delay(1000); //wait for 1000 milliseconds

digitalWrite(7, LOW); //turn off the LED on pin 7

digitalWrite(8, HIGH); //turn on the LED on pin 8

delay(1000); //wait for 1000 milliseconds

digitalWrite(8, LOW); //turn off the LED on pin 8

} //Here at the end of the loop the program starts again from the beginning of //the loop part. So..turn on LED on pin 7..wait for 1000 //milliseconds..etc..etc..