summaryrefslogtreecommitdiff
path: root/micropython/fedibadge.py
diff options
context:
space:
mode:
authorElena ``of Valhalla'' Grandi <valhalla@trueelena.org>2026-08-20 19:13:21 +0200
committerElena ``of Valhalla'' Grandi <valhalla@trueelena.org>2026-08-20 19:13:21 +0200
commitf34ef93ba325475650fcf45f2e34b23f15494b37 (patch)
treef1e782ec07cb90801e87363ea3c8c4866f1e9a6e /micropython/fedibadge.py
parent00742ecbc1f8ac44fa830f74c2e8a7103b030d05 (diff)
First draft of a firmware with some tests.HEADmaster
Diffstat (limited to 'micropython/fedibadge.py')
-rw-r--r--micropython/fedibadge.py52
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)
+
+
+