Welcome to Pico Robot Car repository
3.1 Control LED light
3.1 Control the onboard LED light to flash
In the previous section, we learned how to build a development environment and run the program to control the onboard LED to flash. In this section, we will learn how this part of the program realizes LED control.
1. Learning objectives
- Learn the basic use of the pins of the Raspberry Pi Pico 2/Pico board.
- Understand how to control the onboard LED light.
2. Hardware usage
This course does not require additional hardware, and can directly use the onboard LED light on the Raspberry Pi Pico 2/Pico board. (The LED positions on Pico 2/Pico board are the same)

3. Program Analysis
Code path: Code -> 1.Basic course -> 1. On board LED lamp.py
For the use of ThonnyIDE, please refer to the second chapter course.
ximport machineimport timeled_onboard = machine.Pin(25, machine.Pin.OUT)while True:led_onboard.value(1)time.sleep(1)led_onboard.value(0)time.sleep(1)
import machine
The machine library contains all the instructions MicroPython needs to communicate with Pico and other MicroPython-compatible devices, extending the language of physical computing.
import time
The "time" library. This library handles everything to do with time, from measuring it to inserting delays into your program. The units are in seconds.
led_onboard = machine.Pin(25, machine.Pin.OUT)
The first argument, 25, is the number of pins you are setting; the second argument, machine.Pin.OUT, tells Pico that the pin should be used as an output rather than an input.
time.sleep(1)
This calls the sleep function from the time library, which will cause the program to pause for whatever number of seconds you type - in this case, 1 second.
4. Experimental Phenomenon
After the program is downloaded, we can see that the LED light on the Raspberry Pi Pico 2/Pico development board flashes every 1 second.