diff options
Diffstat (limited to 'micropython')
| -rw-r--r-- | micropython/fedibadge.py | 52 |
1 files changed, 52 insertions, 0 deletions
diff --git a/micropython/fedibadge.py b/micropython/fedibadge.py new file mode 100644 index 0000000..db8d942 --- /dev/null +++ b/micropython/fedibadge.py @@ -0,0 +1,52 @@ + +from machine import Pin +import neopixel +import time + +class Fedi: + def __init__(self): + self.led = neopixel.NeoPixel(Pin(2), 5) + self.butt = Pin(5, Pin.IN, Pin.PULL_UP) + + self.butt_count = 0 + self.butt_latest = time.ticks_ms() + + self.butt.irq(self.button_pressed, Pin.IRQ_RISING) + + def button_pressed(self, pin): + if self.butt_count == 0: + self.butt_latest = time.ticks_ms() + self.butt_count += 1 + else: + now = time.ticks_ms() + delta = now - self.butt_latest + if delta > 5000: + self.button_counted() + elif delta > 500: + self.butt_latest = now + self.butt_count += 1 + + def button_counted(self): + print("We have counted", self.butt_count) + self.butt_count = 0 + + def test_loop(self): + count = 0 + cols = [ + (16, 0, 0), + (16, 16, 0), + (0, 16, 0), + (0, 16, 16), + (0, 0, 16), + (16, 0, 16) + ] + while True: + self.led.fill(cols[count]) + self.led.write() + count += 1 + count = count % 6 + print("butt_count", self.butt_count) + time.sleep(1) + + + |
