From 1516fdf8050ee9bb542ae1b5300c24b63c266983 Mon Sep 17 00:00:00 2001 From: lady ada Date: Sun, 25 Dec 2022 17:23:14 -0500 Subject: [PATCH] accurate lighting sequence --- WS2801_LED_Menorah/code.py | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/WS2801_LED_Menorah/code.py b/WS2801_LED_Menorah/code.py index 227d68a10..8e2845d47 100644 --- a/WS2801_LED_Menorah/code.py +++ b/WS2801_LED_Menorah/code.py @@ -23,6 +23,7 @@ pixel_prev = [128] * len(pixels) lit_candles = None night = 1 +timestamp = None def split(first, second, offset): """ @@ -51,9 +52,16 @@ while True: lit_candles = None # reset the lights if not lit_candles: print("Current night: ", night) - lit_candles = [True] * night + [False] * (8-night) + night_countup = 0 + timestamp = time.monotonic()-1 + + if (night_countup != night) and (time.monotonic() - timestamp >= 1): + # we slowly 'light' up the candles from left to right, once a second + night_countup += 1 + lit_candles = [False] * (8-night) + [True] * night_countup + [False] * (night-night_countup) lit_candles.insert(4, True) # shamash always on - print(lit_candles) + print("Count up candle #", night_countup, lit_candles) + timestamp = time.monotonic() # animate candles for p in range(len(pixels)-pixel_offset):