From e05e3f928d4513fc0840eab8321ff3ca46384080 Mon Sep 17 00:00:00 2001 From: Henry Amador Date: Mon, 7 Apr 2025 21:01:18 -0700 Subject: [PATCH 1/2] Dark Moon support, code.py Added Dark Moon support when i noticed the moon didn't update on a dark moon night. Added Red Moon as error indicator if there is another instance of API responding with something unexpected --- QT_Py/NeoPixel_Moon_Phase_Clock/code.py | 28 +++++++++++++++++++++---- 1 file changed, 24 insertions(+), 4 deletions(-) diff --git a/QT_Py/NeoPixel_Moon_Phase_Clock/code.py b/QT_Py/NeoPixel_Moon_Phase_Clock/code.py index d9579a757..e392b83f8 100644 --- a/QT_Py/NeoPixel_Moon_Phase_Clock/code.py +++ b/QT_Py/NeoPixel_Moon_Phase_Clock/code.py @@ -29,6 +29,7 @@ # neopixels, 49 total OFF = (0, 0, 0) ON = (255, 255, 255) +RED = (255,0,0) pixel_pin = board.A3 num_pixels = 49 pixels = neopixel.NeoPixel(pixel_pin, num_pixels, brightness=0.1, auto_write=False) @@ -43,9 +44,11 @@ WANING_GIBBOUS = 5 THIRD_QUARTER = 6 WANING_CRESCENT = 7 +DARK_MOON = 8 +RED_MOON = 9 # strings that match return from API phase_names = ["New Moon", "Waxing Crescent", "First Quarter", "Waxing Gibbous", - "Full Moon", "Waning Gibbous", "Third Quarter", "Waning Crescent"] + "Full Moon", "Waning Gibbous", "Third Quarter", "Waning Crescent","Dark Moon","Red Moon"] # functions for each moon phase to light up based on neopixel orientation def set_new_moon(): @@ -95,7 +98,17 @@ def set_waning_crescent(): for i in range(5, 18): pixels[i] = ON pixels.show() - + +def set_dark_moon(): + pixels.fill(OFF) + for i in range(9,14): + pixels[i] = ON + pixels.show() + +def set_red_moon(): + pixels.fill(RED) + pixels.show() + # match functions with phases phase_functions = { NEW_MOON: set_new_moon, @@ -105,12 +118,14 @@ def set_waning_crescent(): FULL_MOON: set_full_moon, WANING_GIBBOUS: set_waning_gibbous, THIRD_QUARTER: set_third_quarter, - WANING_CRESCENT: set_waning_crescent + WANING_CRESCENT: set_waning_crescent, + DARK_MOON: set_dark_moon, + RED_MOON: set_red_moon } # test function, runs through all 8 in order def demo_all_phases(delay=1): - for phase in range(8): + for phase in range(9): print(f"Setting phase: {phase_names[phase]}") phase_functions[phase]() time.sleep(delay) @@ -119,10 +134,15 @@ def demo_all_phases(delay=1): # takes response from API, matches to function, runs function def set_moon_phase(phase): phase_lower = phase.lower() + error_check = 0 for i, name in enumerate(phase_names): if phase_lower == name.lower(): + error_check = 1 phase_functions[i]() print(f"Moon phase set to: {name}") + if error_check == 0: + print("ERROR") + set_red_moon() #error indicator if API responce is unexpected # time keeping, fetches API every 6 hours timer_clock = ticks_ms() From b2a98fe698544aee6e43dcfcce70592bbd66f007 Mon Sep 17 00:00:00 2001 From: Henry Amador Date: Wed, 9 Apr 2025 15:25:01 -0700 Subject: [PATCH 2/2] Update code.py fixing pylint error inconsistent use of tabs and spaces in indentation corrected by removing tabs and indenting with spaces --- QT_Py/NeoPixel_Moon_Phase_Clock/code.py | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/QT_Py/NeoPixel_Moon_Phase_Clock/code.py b/QT_Py/NeoPixel_Moon_Phase_Clock/code.py index e392b83f8..46adf4405 100644 --- a/QT_Py/NeoPixel_Moon_Phase_Clock/code.py +++ b/QT_Py/NeoPixel_Moon_Phase_Clock/code.py @@ -98,17 +98,17 @@ def set_waning_crescent(): for i in range(5, 18): pixels[i] = ON pixels.show() - + def set_dark_moon(): - pixels.fill(OFF) - for i in range(9,14): - pixels[i] = ON - pixels.show() + pixels.fill(OFF) + for i in range(9,14): + pixels[i] = ON + pixels.show() def set_red_moon(): - pixels.fill(RED) - pixels.show() - + pixels.fill(RED) + pixels.show() + # match functions with phases phase_functions = { NEW_MOON: set_new_moon, @@ -141,8 +141,8 @@ def set_moon_phase(phase): phase_functions[i]() print(f"Moon phase set to: {name}") if error_check == 0: - print("ERROR") - set_red_moon() #error indicator if API responce is unexpected + print("ERROR") + set_red_moon() #error indicator if API responce is unexpected # time keeping, fetches API every 6 hours timer_clock = ticks_ms()