gpio_controlled_leds
Differences
This shows you the differences between two versions of the page.
| Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
| gpio_controlled_leds [2026/06/17 16:26] – [Introduction] walkeradmin | gpio_controlled_leds [2026/06/30 21:01] (current) – walkeradmin | ||
|---|---|---|---|
| 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 20: | Line 20: | ||
| Below is the software being used to drive the LEDs | Below is the software being used to drive the LEDs | ||
| \\ | \\ | ||
| - | <code | download> | + | <code: |
| # Start by importing lib files " | # Start by importing lib files " | ||
| # Imports the machine module, which provides access to hardware features such as GPIO pins, ADCs, PWM, etc. | # Imports the machine module, which provides access to hardware features such as GPIO pins, ADCs, PWM, etc. | ||
| Line 27: | Line 27: | ||
| import time | import time | ||
| - | #we're initalizing pin 25 (which is the onboard LED) & pins 2, 6 and 6 as outputs | + | #we're initalizing pin 25 (which is the onboard LED) & GPIO pins 2, 6 and 10 as outputs |
| # Creates a pin object called led1. | # Creates a pin object called led1. | ||
| # Uses GPIO pin 25. | # Uses GPIO pin 25. | ||
| Line 33: | Line 33: | ||
| # On a Raspberry Pi Pico, GPIO 25 is usually connected to the onboard LED. | # On a Raspberry Pi Pico, GPIO 25 is usually connected to the onboard LED. | ||
| led1 = machine.Pin(25, | led1 = machine.Pin(25, | ||
| - | # Creates an output pin object for GPIO 2. | + | # Creates an output pin object for GPIO 2 (GP2). |
| led2 = machine.Pin(2, | led2 = machine.Pin(2, | ||
| - | # Creates an output pin object for GPIO 6. | + | # Creates an output pin object for GPIO 6 (GP6). |
| led3 = machine.Pin(6, | led3 = machine.Pin(6, | ||
| - | # Creates an output pin object for GPIO 10. | + | # Creates an output pin object for GPIO 10 (GP10). |
| led4 = machine.Pin(10, | led4 = machine.Pin(10, | ||
| Line 85: | Line 85: | ||
| </ | </ | ||
| + | The software works by performing the following tasks. | ||
| \\ | \\ | ||
| - | \\ | + | * Import Libraries (Machine and Time) |
| - | \\ | + | |
| - | <code | download> | + | |
| - | # Start by importing lib files " | + | |
| - | import machine | + | |
| - | import time | + | |
| - | #we're initalizing pin 25 (which is the onboarde LED) & pin 2 as outputs | + | * * Set GPIO Pins to output |
| - | led1 = machine.Pin(25, | + | |
| - | led2 = machine.Pin(2, | + | |
| - | #Run a loop 10 times | + | * Start a loop that will loop 5 times |
| - | for i in range(10): | + | |
| - | #Turn the onbaord LED on | + | |
| - | led1.value(1) | + | |
| - | + | ||
| - | #Use time to wait for 1 second | + | |
| - | time.sleep(1) | + | |
| - | + | ||
| - | #Turn the onbaord LED off | + | |
| - | led1.value(0) | + | |
| - | #Turn the external LED on pin 2 on | + | |
| - | led2.value(1) | + | |
| - | </ | + | |
| + | * 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. | ||
| + | \\ | ||
| + | \\ | ||
| + | ---- | ||
gpio_controlled_leds.1781713602.txt.gz · Last modified: by walkeradmin
