цифровая электроника
вычислительная техника
встраиваемые системы

 


Светодиодные «бегущие огни» на основе Raspberry Pi Pico

Автор: Mike(admin) от 28-11-2021, 09:59

Микроконтроллерная плата Raspberry Pi Pico является отличной отправной точкой для новичков в мир электронике. И в данном материале мы расскажем про проект организации последовательностей включения светодиодов типа «бегущие огни» на основе Raspberry Pi Pico.


Светодиодные «бегущие огни» на основе Raspberry Pi Pico

В данном проекте мы реализуем создадите селектор последовательностей включения светодиодов на основе Raspberry Pi Pico. Помимо микроконтроллерной платы здесь будет десять светодиодов и четыре кнопки. Для каждой кнопки будет своя последовательность светодиодов.


Распиновка платы Raspberry Pi Pico:


Распиновка платы Raspberry Pi Pico

Схема подключения компонентов:


Схема подключения компонентов

Код программы для Raspberry Pi Pico следующий:



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)



© digitrode.ru


Теги: Raspberry Pi Pico




Уважаемый посетитель, Вы зашли на сайт как незарегистрированный пользователь.
Мы рекомендуем Вам зарегистрироваться либо войти на сайт под своим именем.

Комментарии:

Оставить комментарий