Hackster is hosting Hackster Holidays, Ep. 6: Livestream & Giveaway Drawing. Watch previous episodes or stream live on Monday!Stream Hackster Holidays, Ep. 6 on Monday!
Leonardo Flores González
Published

LED sequences using Raspberry Pi Pico

Create a series of LED sequences, using 4 buttons to activate one of the sequences, using the Raspberry Pi Pico and Thonny software.

IntermediateFull instructions provided2,165
LED sequences using Raspberry Pi Pico

Things used in this project

Hardware components

Raspberry Pi Pico
Raspberry Pi Pico
×1
LED (generic)
LED (generic)
×10
Resistor 220 ohm
Resistor 220 ohm
×10
Jumper wires (generic)
Jumper wires (generic)
×1
USB Cable Assembly, USB Type A Plug to Micro USB Type B Plug
USB Cable Assembly, USB Type A Plug to Micro USB Type B Plug
×1
4 pin open pushbutton
×4

Software apps and online services

Raspberry Pi Thonny

Story

Read more

Schematics

led_s_HA14bTtHuM.PNG

Code

led_sequence_pushbutton

Python
import machine
import utime
led1 = machine.Pin(2, machine.Pin.OUT)
led2 = machine.Pin(3, machine.Pin.OUT)
led3 = machine.Pin(4, machine.Pin.OUT)
led4 = machine.Pin(5, machine.Pin.OUT)
led5 = machine.Pin(6, machine.Pin.OUT)
led6 = machine.Pin(7, machine.Pin.OUT)
led7 = machine.Pin(8, machine.Pin.OUT)
led8 = machine.Pin(9, machine.Pin.OUT)
led9 = machine.Pin(10, machine.Pin.OUT)
led10= machine.Pin(11, machine.Pin.OUT)
#Botones
b1 = machine.Pin(16, machine.Pin.IN, machine.Pin.PULL_DOWN)
b2 = machine.Pin(17, machine.Pin.IN, machine.Pin.PULL_DOWN)
b3 = machine.Pin(18, machine.Pin.IN, machine.Pin.PULL_DOWN)
b4 = machine.Pin(19, machine.Pin.IN, machine.Pin.PULL_DOWN)
def led_sequence (a,b,c,d,e,f,g,h,i,j):
    led1.value(a)
    led2.value(b)
    led3.value(c)
    led4.value(d)
    led5.value(e)
    led6.value(f)
    led7.value(g)
    led8.value(h)
    led9.value(i)
    led10.value(j)

while True:
    if b1.value() == 1:
        led_sequence(0,0,0,0,0,0,0,0,0,0)
        utime.sleep(0.03)
        led_sequence(1,0,0,0,0,0,0,0,0,0)
        utime.sleep(0.03)
        led_sequence(1,1,0,0,0,0,0,0,0,0)
        utime.sleep(0.03)
        led_sequence(0,1,1,0,0,0,0,0,0,0)
        utime.sleep(0.03)
        led_sequence(0,0,1,1,0,0,0,0,0,0)
        utime.sleep(0.03)
        led_sequence(0,0,0,1,1,0,0,0,0,0)
        utime.sleep(0.03)
        led_sequence(0,0,0,0,1,1,0,0,0,0)
        utime.sleep(0.03)
        led_sequence(0,0,0,0,0,1,1,0,0,0)
        utime.sleep(0.03)
        led_sequence(0,0,0,0,0,0,1,1,0,0)
        utime.sleep(0.03)
        led_sequence(0,0,0,0,0,0,0,1,1,0)
        utime.sleep(0.03)
        led_sequence(0,0,0,0,0,0,0,0,1,1)
        utime.sleep(0.03)
        led_sequence(0,0,0,0,0,0,0,0,0,1)
        utime.sleep(0.03)
        led_sequence(0,0,0,0,0,0,0,0,0,0)
        utime.sleep(0.5)
        led_sequence(0,0,0,0,0,0,0,0,0,1)
        utime.sleep(0.03)
        led_sequence(0,0,0,0,0,0,0,0,1,1)
        utime.sleep(0.03)
        led_sequence(0,0,0,0,0,0,0,1,1,0)
        utime.sleep(0.03)
        led_sequence(0,0,0,0,0,0,1,1,0,0)
        utime.sleep(0.03)
        led_sequence(0,0,0,0,0,1,1,0,0,0)
        utime.sleep(0.03)
        led_sequence(0,0,0,0,1,1,0,0,0,0)
        utime.sleep(0.03)
        led_sequence(0,0,0,1,1,0,0,0,0,0)
        utime.sleep(0.03)
        led_sequence(0,0,1,1,0,0,0,0,0,0)
        utime.sleep(0.03)
        led_sequence(0,1,1,0,0,0,0,0,0,0)
        utime.sleep(0.03)
        led_sequence(1,1,0,0,0,0,0,0,0,0)
        utime.sleep(0.03)
        led_sequence(1,0,0,0,0,0,0,0,0,0)
        utime.sleep(0.03)
        led_sequence(0,0,0,0,0,0,0,0,0,0)
        utime.sleep(0.5)
        
    if b2.value() == 1:
        led_sequence(0,0,0,0,0,0,0,0,0,0)
        utime.sleep(0.03)
        led_sequence(0,0,0,0,1,1,0,0,0,0)
        utime.sleep(0.03)
        led_sequence(0,0,0,1,1,1,1,0,0,0)
        utime.sleep(0.03)
        led_sequence(0,0,1,1,0,0,1,1,0,0)
        utime.sleep(0.03)
        led_sequence(0,1,1,0,0,0,0,1,1,0)
        utime.sleep(0.03)
        led_sequence(1,1,0,0,0,0,0,0,1,1)
        utime.sleep(0.03)
        led_sequence(1,0,0,0,0,0,0,0,0,1)
        utime.sleep(0.03)
        led_sequence(1,0,0,0,0,0,0,0,0,1)
        utime.sleep(0.03)
        led_sequence(0,0,0,0,0,0,0,0,0,0)
        utime.sleep(0.5)
        led_sequence(1,0,0,0,0,0,0,0,0,1)
        utime.sleep(0.03)
        led_sequence(1,1,0,0,0,0,0,0,1,1)
        utime.sleep(0.03)
        led_sequence(0,1,1,0,0,0,0,1,1,0)
        utime.sleep(0.03)
        led_sequence(0,0,1,1,0,0,1,1,0,0)
        utime.sleep(0.03)
        led_sequence(0,0,0,1,1,1,1,0,0,0)
        utime.sleep(0.03)
        led_sequence(0,0,0,0,1,1,0,0,0,0)
        utime.sleep(0.03)
        led_sequence(0,0,0,0,0,0,0,0,0,0)
        utime.sleep(0.5)
        
    if b3.value() == 1:
        led_sequence(0,0,0,0,0,0,0,0,0,0)
        utime.sleep(0.02)
        led_sequence(1,0,0,0,0,0,0,0,0,0)
        utime.sleep(0.02)
        led_sequence(1,1,0,0,0,0,0,0,0,0)
        utime.sleep(0.02)
        led_sequence(0,1,1,0,0,0,0,0,0,0)
        utime.sleep(0.02)
        led_sequence(0,0,1,1,0,0,0,0,0,0)
        utime.sleep(0.02)
        led_sequence(0,0,0,1,1,0,0,0,0,0)
        utime.sleep(0.02)
        led_sequence(0,0,0,0,1,1,0,0,0,0)
        utime.sleep(0.02)
        led_sequence(0,0,0,0,0,1,1,0,0,0)
        utime.sleep(0.02)
        led_sequence(0,0,0,0,0,0,1,1,0,0)
        utime.sleep(0.02)
        led_sequence(0,0,0,0,0,0,0,1,1,0)
        utime.sleep(0.02)
        led_sequence(0,0,0,0,0,0,0,0,1,1)
        utime.sleep(0.02)
        led_sequence(0,0,0,0,0,0,0,0,0,1)
        utime.sleep(0.02)
        led_sequence(0,0,0,0,0,0,0,0,0,0)
        utime.sleep(0.02)
    if b4.value() == 1:
        led_sequence(0,0,0,0,0,0,0,0,0,0)
        utime.sleep(0.02)
        led_sequence(1,0,0,0,0,0,0,0,0,0)
        utime.sleep(0.02)
        led_sequence(1,1,0,0,0,0,0,0,0,0)
        utime.sleep(0.02)
        led_sequence(1,1,1,0,0,0,0,0,0,0)
        utime.sleep(0.02)
        led_sequence(1,1,1,1,0,0,0,0,0,0)
        utime.sleep(0.02)
        led_sequence(1,1,1,1,1,0,0,0,0,0)
        utime.sleep(0.02)
        led_sequence(1,1,1,1,1,1,0,0,0,0)
        utime.sleep(0.02)
        led_sequence(1,1,1,1,1,1,1,0,0,0)
        utime.sleep(0.02)
        led_sequence(1,1,1,1,1,1,1,1,0,0)
        utime.sleep(0.02)
        led_sequence(1,1,1,1,1,1,1,1,1,0)
        utime.sleep(0.02)
        led_sequence(1,1,1,1,1,1,1,1,1,1)
        utime.sleep(1)
        led_sequence(0,1,1,1,1,1,1,1,1,1)
        utime.sleep(0.02)
        led_sequence(0,0,1,1,1,1,1,1,1,1)
        utime.sleep(0.02)
        led_sequence(0,0,0,1,1,1,1,1,1,1)
        utime.sleep(0.02)
        led_sequence(0,0,0,0,1,1,1,1,1,1)
        utime.sleep(0.02)
        led_sequence(0,0,0,0,0,1,1,1,1,1)
        utime.sleep(0.02)
        led_sequence(0,0,0,0,0,0,1,1,1,1)
        utime.sleep(0.02)
        led_sequence(0,0,0,0,0,0,0,1,1,1)
        utime.sleep(0.02)
        led_sequence(0,0,0,0,0,0,0,0,1,1)
        utime.sleep(0.02)
        led_sequence(0,0,0,0,0,0,0,0,0,1)
        utime.sleep(0.02)
        led_sequence(0,0,0,0,0,0,0,0,0,0)
        utime.sleep(0.5)

Credits

Leonardo Flores González

Leonardo Flores González

1 project • 0 followers

Comments