Skip to content

Commit 1516fdf

Browse files
committed
accurate lighting sequence
1 parent 7a8df7c commit 1516fdf

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

WS2801_LED_Menorah/code.py

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323

2424
lit_candles = None
2525
night = 1
26+
timestamp = None
2627

2728
def split(first, second, offset):
2829
"""
@@ -51,9 +52,16 @@ def split(first, second, offset):
5152
lit_candles = None # reset the lights
5253
if not lit_candles:
5354
print("Current night: ", night)
54-
lit_candles = [True] * night + [False] * (8-night)
55+
night_countup = 0
56+
timestamp = time.monotonic()-1
57+
58+
if (night_countup != night) and (time.monotonic() - timestamp >= 1):
59+
# we slowly 'light' up the candles from left to right, once a second
60+
night_countup += 1
61+
lit_candles = [False] * (8-night) + [True] * night_countup + [False] * (night-night_countup)
5562
lit_candles.insert(4, True) # shamash always on
56-
print(lit_candles)
63+
print("Count up candle #", night_countup, lit_candles)
64+
timestamp = time.monotonic()
5765

5866
# animate candles
5967
for p in range(len(pixels)-pixel_offset):

0 commit comments

Comments
 (0)