Skip to content

Dark Moon support, code.py #3012

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Apr 14, 2025
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 24 additions & 4 deletions QT_Py/NeoPixel_Moon_Phase_Clock/code.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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():
Expand Down Expand Up @@ -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,
Expand All @@ -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)
Expand All @@ -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()
Expand Down
Loading