"""
Example number: 45
base 10 number system (Decimal)
╭─────┬─────╮
│ 10¹ │ 10⁰ │
├─────┼─────┤
│ 4 │ 5 │
╰─────┴─────╯
(4 * 10¹) + (5 * 10⁰)
(4 * 10) + (5 * 1)
40 + 5 = 45
base 2 number system (Binary)
╭────┬────┬────┬────┬────┬────╮
│ 2⁵ │ 2⁴ │ 2³ │ 2² │ 2¹ │ 2⁰ │
├────┼────┼────┼────┼────┼────┤
│ 1 │ 0 │ 1 │ 1 │ 0 │ 1 │
╰────┴────┴────┴────┴────┴────╯
(1 * 2⁵) + (0 * 2⁴) + (1 * 2³) + (1 * 2²) + (0 * 2¹) + (1 * 2⁰)
(1 * 32) + (0 * 16) + (1 * 8) + (1 * 4) + (0 * 2) + (1 * 1)
32 + 0 + 8 + 4 + 0 + 1 = 45
base 16 number system (Hexadecimal)
1 = 1, 2 = 2, 3 = 3, ... , A = 10, B = 11, C = 12, D = 13, E = 14, F = 15
╭─────┬─────╮
│ 16¹ │ 16⁰ │
├─────┼─────┤
│ 2 │ D │
╰─────┴─────╯
(4 * 16¹) + (D * 16⁰)
(2 * 16) + (13 * 1)
32 + 13 = 45
"""
from machine import Pin
from time import sleep
# Assign all 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] # list will all the leds we defined
# main loop
while True:
for i in range(2 ** len(ALL_LEDs)): # for every combination...
binary_num = f'{i:0>4b}' # format number to 4-bit binary string
print(binary_num) # print binary number
for j in range(len(binary_num)): # go through all the binary digits
if binary_num[j] == '1': # if it's a 1...
ALL_LEDs[j].value(1) # set respective LED on
else: # if it's NOT a 1
ALL_LEDs[j].value(0) # set respective LED off
sleep(WAIT_TIME) # wait before flashing the next sequence