Project: LED Traffic LightsJan 13, 2023
In this lesson you will:
Learn to apply modeling techniques to design and construct a heavily used system.
Explore the applications of loops, functions, and variables in computer programming.
- 3, LED Lights
- 3, 220Ω Resistors
- 6, Male-to-Male Jumper Wires
- 1, ATmega328P Microcontroller and Data Cable
- 1, Breadboard
- Paper, Cardboard, and other Craft Materials
Now it's time to program your traffic light! If you're unfamiliar with how to program your microcontroller, check out the microcontroller lessons in the library before you continue.
Loops make our lives so much easier! There are so many things that we do every day that require us to do them over and over again. Computers are no different! That's why when we are writing programs, loops and if-statements can be helpful! Here's when to use some common types of loops and statements.
- For-Loops: For-loops are a great way to run certain code in a loop for a given number of times. When using a for-loop you might have a variable that changes value each time it is run.
- While-Loops: While-loops use booleans—true or false statements—to run code in a loop. A while-statement would be a great choice if you are looking to run code until something changes.
- If-Statements: If statements evaluate if something is true. If that thing is true, the code in the statement will run. If that thing is not true, the code will be skipped.
- Loop Function: The IDE has a built in loop function. This makes our life easy, because any code inside of the loop function will continue running until we unplug our board!
Need help to program your traffic lights? Follow along and use the hints below!