Created
December 6, 2023 23:08
-
-
Save adrianyorke/0f6a8a2d30ed62ba87b73cca5f137ffb to your computer and use it in GitHub Desktop.
Let it Glow - Day 4 - Binary LED Graph
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from machine import Pin | |
import time | |
redbutton = Pin(2, Pin.IN, Pin.PULL_DOWN) | |
greenbutton = Pin(3, Pin.IN, Pin.PULL_DOWN) | |
seg1 = Pin(13, Pin.OUT) | |
seg2 = Pin(12, Pin.OUT) | |
seg3 = Pin(11, Pin.OUT) | |
seg4 = Pin(10, Pin.OUT) | |
seg5 = Pin(9, Pin.OUT) | |
segments = [seg1, seg2, seg3, seg4, seg5] | |
count = 0 | |
while True: | |
if redbutton.value() == 1: | |
if count > 0: | |
count -= 1 | |
print(count) | |
if greenbutton.value() == 1: | |
if count < 31: | |
count += 1 | |
print(count) | |
for i in range(0, 5): | |
segments[i].value(2**i & count) | |
time.sleep(0.1) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment