betsy-button

Family health button
git clone https://git.woozle.org/neale/betsy-button.git

betsy-button / web
Neale Pickett  ·  2025-06-21

blinker.py

 1import machine
 2import neopixel
 3
 4# colors is the list of colors to cycle through.
 5# Each color will be visible for 1/4 second.
 6colors = (
 7    (20, 15, 0),
 8    (0, 0, 0),
 9)
10
11pixel = neopixel.NeoPixel(machine.Pin(5), 1)
12index = 0
13
14def set(*vals, now=False):
15    """Set the blinker pattern."""
16    global colors, index
17    colors = vals
18    if now:
19        index = 0
20        pixel[0] = colors[0]
21        pixel.write()
22    
23def pulse(self):
24    global index
25    index = index % len(colors)
26    pixel[0] = colors[index]
27    pixel.write()
28    index += 1
29
30timer = machine.Timer(1)
31timer.init(freq=4, callback=pulse)