led_on_and_off
Differences
This shows you the differences between two versions of the page.
| Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
| led_on_and_off [2026/06/12 22:32] – [Introduction] walkeradmin | led_on_and_off [2026/06/17 16:39] (current) – walkeradmin | ||
|---|---|---|---|
| Line 10: | Line 10: | ||
| \\ | \\ | ||
| \\ | \\ | ||
| - | {{ : | + | {{ : |
| \\ | \\ | ||
| In the above picture we can see where the LED is. Once powered on the LED by default will be off, and we will need to use some micro python to turn it on. | In the above picture we can see where the LED is. Once powered on the LED by default will be off, and we will need to use some micro python to turn it on. | ||
| Line 18: | Line 18: | ||
| \\ | \\ | ||
| \\ | \\ | ||
| - | {{ : | + | {{ : |
| \\ | \\ | ||
| Here we can see the code that we need to enter in to Thonny. | Here we can see the code that we need to enter in to Thonny. | ||
| \\ | \\ | ||
| \\ | \\ | ||
| - | <code | download> | + | <code: |
| # Import the picozero LED class | # Import the picozero LED class | ||
| from picozero import pico_led | from picozero import pico_led | ||
| Line 30: | Line 30: | ||
| pico_led.on() | pico_led.on() | ||
| </ | </ | ||
| + | \\ | ||
| + | To run this code, click the green play button on the Thonny toolbar. This of course turns the Pi Pico LED on. | ||
| + | \\ | ||
| + | \\ | ||
| + | {{ : | ||
| \\ | \\ | ||
| This code does a couple of things: | This code does a couple of things: | ||
| Line 35: | Line 40: | ||
| \\ | \\ | ||
| **from picozero import pico_led** | **from picozero import pico_led** | ||
| - | \\ | ||
| \\ | \\ | ||
| This line imports the pico_led object from the picozero library. | This line imports the pico_led object from the picozero library. | ||
| Line 43: | Line 47: | ||
| pico_led is a built‑in object that represents the on‑board LED (the little LED already on the Pico board). | pico_led is a built‑in object that represents the on‑board LED (the little LED already on the Pico board). | ||
| | | ||
| - | So this line is basically saying: | + | So this line is basically saying: |
| + | \\ | ||
| + | **pico_led.on()** | ||
| + | \\ | ||
| + | |||
| + | This is the line that actually turns the LED on. | ||
| | | ||
| - | | + | |
| + | |||
| + | .on() is a function that switches it on | ||
| + | |||
| + | The LED lights up and stays on until you turn it off or reset the board | ||
| + | |||
| + | It’s the simplest possible way to control hardware on the Pico. | ||
| + | \\ | ||
| + | Now that you have turned the LED on, you might want to turn it off, and the program is almost the same except for the argument for the pico_led line. | ||
| + | \\ | ||
| + | < | ||
| + | # Import the picozero LED class | ||
| + | from picozero import pico_led | ||
| + | |||
| + | #Turn on the pico LED | ||
| + | pico_led.off() | ||
| + | </ | ||
| + | As you can see in the code above, all we have done is to change the pico_led.< | ||
| + | \\ | ||
| + | \\ | ||
| + | This now turns of the Pi Pico LED. | ||
| + | \\ | ||
| + | \\ | ||
| + | {{ : | ||
| + | \\ | ||
| + | That is it, we can now successfully turn on and off the onboard LED on the Pi Pico, as well as creating our first piece of Micro Python in Thonny. | ||
| + | \\ | ||
| + | \\ | ||
| + | ---- | ||
led_on_and_off.1781303557.txt.gz · Last modified: by walkeradmin
