The goal is to build a circuit with 2 LEDs. Each LED has to be able to be controlled independently using the Arduino.
For this to work you have to build 2 independent circuits, one for each LED. Notice how both LEDs share the same ground (GND) but the plus side of each LED is connected to a different digital port on the Arduino. It’s important that each LED is connected to its own digital port on the plus side, this is the only way to control each LED individually. When pin 7 is set to HIGH current will flow through the LED and the resistor to ground and it won’t have any effect on the LED connected to pin 8.
Setup is used to declare pin 7 and pin 8 as outputs so we can use them to control the LEDs.
The loop is used to make the LEDs blink, when the first LED is on, the second LED is off and vice versa. LEDs are on for half a second before switching. There is no delay between turning off pin 7 and turning on pin 8, this makes it seem like it’s happening at the same time.
Have a good look at the code and make sure you understand what happens when the code ends the loop and starts over again.
- Make both LEDs blink at the same time
- Add more LEDs and make patterns
- Add more LEDs and make them go on and off randomly
- Make a set of (safe) traffic lights