Blink Alternating LEDs


Step 1 - Build the Project

Blink Alternating LEDs Hookup: 2 LEDs in pin 13 and 11. Remember the shorter leg of the LED is ground.

Topics Covered:

 

In this code, you’re placing digitalWrite commands side by side so they happen at almost the exact same time. 


Step 2 - Upload the Code

//Toggle between two LEDs for a siren-like effect. void setup(){
//Set your LED pins as outputs pinMode(13,OUTPUT);
pinMode(11,OUTPUT); } void loop(){ digitalWrite(11,LOW); digitalWrite(13,HIGH); delay(100); //Update the delay for different toggle speeds
//Reverse the pins' status digitalWrite(13,LOW);
digitalWrite(11,HIGH);
delay(100);
} // Try to get both LEDs to be on at the same time. // Try adding another LED to your hardware and then adding it to the code // Need help? https://www.letsstartcoding.com/help // (c) 2018 Let's Start Coding. License: www.letsstartcoding.com/bsdlicense
 

Step 3 - Read the Walkthrough

Although the Maker Board actually runs the commands in order, the calculation happens so fast that the changes appear simultaneously.

The delay between the two ‘pairs’ of commands holds the program’s status for 100 milliseconds, or 1/10th of a second, then it quickly executes the next digitalWrite!