from machine import Pin
from time import sleep
# Assign all out LEDs
led1 = Pin(15, Pin.OUT)
led2 = Pin(14, Pin.OUT)
led3 = Pin(13, Pin.OUT)
led4 = Pin(12, Pin.OUT)
WAIT_TIME = 0.4 # time to wait between each sequence
ALL_LEDS = [led4, led3, led2, led1]
BINARY_NUMS = ['0000', '0001', '0010', '0011', '0100', '0101', '0110', '0111', '1000', '1001', '1010', '1011', '1100', '1101', '1110', '1111']
def show_binary(bin_num):
for i in range(4): # for each digit we have... (4 digits)
bin_digit = bin_num[i] # pick out the binary digit
if bin_digit == '1': # if it's a 1
ALL_LEDS[i].value(1) # turn on it's corroponding LED
else: # if it's anythong else (AKA not a 1)
ALL_LEDS[i].value(0) # turn off it's corroponding LED
# main loop
while True:
for i in range(16): # for each binary number we have... (16 total, numbers 0-15)
show_binary(BINARY_NUMS[i]) # show the binary number on the LEDs
sleep(WAIT_TIME) # wait for some time before showing the next number