LED Tricks Using The Raspberry Pi Pico - Raspberry Pi Projects, Tutorials, Learning DIY Electronics - Makergenix

Breaking

 


LED Tricks Using The Raspberry Pi Pico

 LED sequences created using a Raspberry Pi Pico Using the Raspberry Pi Pico RP2040 microcontroller and Thonny software, create a number of LED sequences, each with four buttons to trigger one of the sequences.

LED Tricks Using The Raspberry Pi Pico
Leonardo Flores González

This project's hardware and software

Hardware components

Software apps and online services

  • Raspberry Pi Thonny


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)

Download Full Code: Click Here
Author CreditLeonardo Flores González 

 


Most Viewed Posts

Write For Us

Name

Email *

Message *

All Blogs