diff options
| author | Elena ``of Valhalla'' Grandi <valhalla@trueelena.org> | 2026-08-20 19:13:21 +0200 |
|---|---|---|
| committer | Elena ``of Valhalla'' Grandi <valhalla@trueelena.org> | 2026-08-20 19:13:21 +0200 |
| commit | f34ef93ba325475650fcf45f2e34b23f15494b37 (patch) | |
| tree | f1e782ec07cb90801e87363ea3c8c4866f1e9a6e | |
| parent | 00742ecbc1f8ac44fa830f74c2e8a7103b030d05 (diff) | |
| -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) + + + |
