Initial commit
This commit is contained in:
commit
c732ae9bf5
6
boot.py
Normal file
6
boot.py
Normal file
@ -0,0 +1,6 @@
|
||||
import counter
|
||||
|
||||
# NISEI
|
||||
counter.numbers = [0b11101111, 0b10001001, 0b11010111, 0b11011011, 0b00100100, 0b11010110, 0b01110110, 0b00111100]
|
||||
|
||||
counter.run()
|
51
counter.py
Normal file
51
counter.py
Normal file
@ -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)
|
Loading…
Reference in New Issue
Block a user