traffic_light_leds_using_array
Differences
This shows you the differences between two versions of the page.
| Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
| traffic_light_leds_using_array [2026/06/17 21:22] – walkeradmin | traffic_light_leds_using_array [2026/07/07 19:48] (current) – [Introduction] walkeradmin | ||
|---|---|---|---|
| Line 7: | Line 7: | ||
| ===== Introduction ===== | ===== Introduction ===== | ||
| \\ | \\ | ||
| - | In this LED example, we are creating a traffic light sequence, but instead of | + | In this LED example, we are creating a traffic light sequence, but instead of addressing every LED at every stage, we are going to put the GPIO pins in to an array, and address just the LEDs that need to change each time. |
| \\ | \\ | ||
| \\ | \\ | ||
| Line 13: | Line 13: | ||
| \\ | \\ | ||
| \\ | \\ | ||
| - | {{ : | + | {{ : |
| \\ | \\ | ||
| We have wired the LEDs to GPIO pins 2, 6 & 10. These are the GPIO Pin numbers, not the actual Pi Pico Pin numbers. | We have wired the LEDs to GPIO pins 2, 6 & 10. These are the GPIO Pin numbers, not the actual Pi Pico Pin numbers. | ||
| Line 61: | Line 61: | ||
| </ | </ | ||
| - | The software works by performing | + | As you can see from the code, we have the four steps of the traffic light sequence. In step one, we can also turn off all the LEDs by calling the function we defined called <color # |
| \\ | \\ | ||
| - | * Import Libraries (Machine and Time) | + | \\ |
| - | + | Here is the sequence running. | |
| - | * * Set GPIO Pins to output | + | \\ |
| - | + | \\ | |
| - | * Start a loop that will loop 5 times | + | {{ : |
| - | + | ||
| - | * Turn on the first LED and turn off all other LEDs | + | |
| - | + | ||
| - | * Turn on the second LED and turn off all other LEDs | + | |
| - | + | ||
| - | * Turn on the third LED and turn off all other LEDs | + | |
| - | + | ||
| - | That's it. Pretty simple. Remember, you can control other devices using the GPIO pins other than LEDs, but the current output is limited to around 20mA. If you try to pull more than this, you could damage that GPIO Pin. | + | |
| \\ | \\ | ||
| \\ | \\ | ||
| ---- | ---- | ||
traffic_light_leds_using_array.1781731372.txt.gz · Last modified: by walkeradmin
