From c732ae9bf5599a56875658e25ff745af7e3889b2 Mon Sep 17 00:00:00 2001 From: Michal Kunc Date: Sun, 5 Mar 2023 11:43:17 +0100 Subject: [PATCH] Initial commit --- boot.py | 6 ++++++ counter.py | 51 +++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 57 insertions(+) create mode 100644 boot.py create mode 100644 counter.py diff --git a/boot.py b/boot.py new file mode 100644 index 0000000..a7643ae --- /dev/null +++ b/boot.py @@ -0,0 +1,6 @@ +import counter + +# NISEI +counter.numbers = [0b11101111, 0b10001001, 0b11010111, 0b11011011, 0b00100100, 0b11010110, 0b01110110, 0b00111100] + +counter.run() \ No newline at end of file diff --git a/counter.py b/counter.py new file mode 100644 index 0000000..c858539 --- /dev/null +++ b/counter.py @@ -0,0 +1,51 @@ +from machine import Pin +import time + +idx = 0 + +led_DP = Pin("GP12", Pin.OUT) +led_D = Pin("GP13", Pin.OUT) +led_E = Pin("GP14", Pin.OUT) +led_C = Pin("GP15", Pin.OUT) +led_G = Pin("GP16", Pin.OUT) +led_F = Pin("GP17", Pin.OUT) +led_A = Pin("GP18", Pin.OUT) +led_B = Pin("GP19", Pin.OUT) + +led_pins = [led_DP, led_D, led_E, led_C, led_G, led_F, led_A, led_B] +numbers = [0b11101110, 0b10001000, 0b11010110, 0b11011010, 0b10111000, 0b01111010, 0b01111110, 0b11001000, 0b11111110, 0b11111010] + +button_fwd = Pin("GP20", Pin.IN, pull=Pin.PULL_DOWN) +button_bck = Pin("GP21", Pin.IN, pull=Pin.PULL_DOWN) + +def set_leds(leds, mask): + for led in leds: + led.value(mask & 1) + mask >>= 1 + +class ButtonHandler(): + def __init__(self,change=0): + self.change = change + self.last = 0 + + def handler(self, pin): + global idx + now = time.ticks_ms() + if time.ticks_diff(now, self.last) < 150: + print("Debouncing") + else: + print(f"Changing by {self.change}") + idx += self.change + self.last = now + + +button_fwd.irq(ButtonHandler(+1).handler, trigger=Pin.IRQ_RISING) +button_bck.irq(ButtonHandler(-1).handler, trigger=Pin.IRQ_RISING) + +for pin in led_pins: + pin.value(0) + +def run(): + while True: + set_leds(led_pins, numbers[idx%len(numbers)]) + time.sleep(0.1)