Introduction
In this Tutorial, you will run a simple yet enjoyable experiment using LEDs to make Flowing LED Lights With Raspberry Pi Pico W. As the name means, these LEDs are organised in a row, just like flowing water, and are programmed to light up in sequence. LED lights are a great way to add a visually appealing element to your project, and the Pico is a great board for controlling them. Getting Started Raspberry Pi Pico – Pinout, Specs – Beginner Guide
Required Components
- Raspberry Pi Pico
- BreadBoard
- Jumper Wires
- LEDs
- Resistor
Principle
10 LEDs are in a row sequentially light up and dim one after another. The principle of this experiment is to turn on ten LEDs in turn. The ten LEDs are connected to pin GP6-pin to GP15 respectively. Set them at a high level and the connected LED at the pins will light up. Control the period of each LED brightening to perform the flowing effect.
Schematic Diagram
The ten LEDs are connected to pin GP6-pin GP15 respectively.
MicroPython Code – Flowing LED Lights With Raspberry Pi Pico
The following code will simulate 10 LEDs using the digital function. How to Setup a Raspberry Pi for the First Time | Getting Started with Raspberry Pi
Main.py
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
from machine import Pin import time pins = [6, 7, 8,9, 10, 11, 12, 13, 14, 15] def FlowLED(): for pin in pins: print(pin) led = Pin(pin, Pin.OUT) led.value(1) time.sleep_ms(50) led.value(0) time.sleep_ms(50) for pin in reversed(pins): print(pin) led = Pin(pin, Pin.OUT) led.value(1) time.sleep_ms(50) led.value(0) time.sleep_ms(50) while True: FlowLED() |
Edit the code above and copy it onto Thonny Editor. Use the Run button to start the Python script.
Conclusion
Wiring everything up takes a bit of time, but the results are worth it The text explains how to wire up LED lights with a Raspberry Pi Pico, and the results are said to be worth the time investment.