flash_the_led_ex1
Differences
This shows you the differences between two versions of the page.
| Next revision | Previous revision | ||
| flash_the_led_ex1 [2026/06/12 22:44] – created walkeradmin | flash_the_led_ex1 [2026/06/17 16:38] (current) – walkeradmin | ||
|---|---|---|---|
| Line 10: | Line 10: | ||
| \\ | \\ | ||
| \\ | \\ | ||
| + | Lets write some more code in Thonny | ||
| + | \\ | ||
| + | \\ | ||
| + | {{ : | ||
| + | \\ | ||
| + | Here is the full Micro Python code that we are using. | ||
| + | \\ | ||
| + | < | ||
| + | # Import the picozero LED class | ||
| + | from picozero import pico_led | ||
| + | # Import the time module for delays | ||
| + | from time import sleep | ||
| + | |||
| + | # Create an LED object for the onboard LED | ||
| + | led = pico_led | ||
| + | |||
| + | # Run forever | ||
| + | while True: | ||
| + | |||
| + | # Turn the LED on | ||
| + | led.on() | ||
| + | |||
| + | # Wait for 0.25 second | ||
| + | sleep(0.25) | ||
| + | |||
| + | # Turn the LED off | ||
| + | led.off() | ||
| + | |||
| + | # Wait for 0.25 second | ||
| + | sleep(0.25) | ||
| + | </ | ||
| + | In this code we are using a **Loop**. The While True: runs forever, and loops around the four lines of code. The comments should make this Micro Python code very easy to understand. | ||
| + | \\ | ||
| + | \\ | ||
| + | Here we can see there is an on time of 0.25 seconds and an off time of 0.25 seconds, so each on/off cycle is 0.5 seconds so every second the LED goes on and off twice. | ||
| + | \\ | ||
| + | \\ | ||
| + | {{ : | ||
| + | \\ | ||
| + | We will explore a simpler way to achieve a flashing LED in another example. | ||
| + | \\ | ||
| + | \\ | ||
| + | ---- | ||
flash_the_led_ex1.1781304252.txt.gz · Last modified: by walkeradmin
