Skip to content

Commit 8b940c9

Browse files
authored
Merge pull request #3012 from monkz0390/patch-1
Dark Moon support, code.py
2 parents dceed82 + b2a98fe commit 8b940c9

File tree

1 file changed

+23
-3
lines changed
  • QT_Py/NeoPixel_Moon_Phase_Clock

1 file changed

+23
-3
lines changed

QT_Py/NeoPixel_Moon_Phase_Clock/code.py

+23-3
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
# neopixels, 49 total
3030
OFF = (0, 0, 0)
3131
ON = (255, 255, 255)
32+
RED = (255,0,0)
3233
pixel_pin = board.A3
3334
num_pixels = 49
3435
pixels = neopixel.NeoPixel(pixel_pin, num_pixels, brightness=0.1, auto_write=False)
@@ -43,9 +44,11 @@
4344
WANING_GIBBOUS = 5
4445
THIRD_QUARTER = 6
4546
WANING_CRESCENT = 7
47+
DARK_MOON = 8
48+
RED_MOON = 9
4649
# strings that match return from API
4750
phase_names = ["New Moon", "Waxing Crescent", "First Quarter", "Waxing Gibbous",
48-
"Full Moon", "Waning Gibbous", "Third Quarter", "Waning Crescent"]
51+
"Full Moon", "Waning Gibbous", "Third Quarter", "Waning Crescent","Dark Moon","Red Moon"]
4952

5053
# functions for each moon phase to light up based on neopixel orientation
5154
def set_new_moon():
@@ -96,6 +99,16 @@ def set_waning_crescent():
9699
pixels[i] = ON
97100
pixels.show()
98101

102+
def set_dark_moon():
103+
pixels.fill(OFF)
104+
for i in range(9,14):
105+
pixels[i] = ON
106+
pixels.show()
107+
108+
def set_red_moon():
109+
pixels.fill(RED)
110+
pixels.show()
111+
99112
# match functions with phases
100113
phase_functions = {
101114
NEW_MOON: set_new_moon,
@@ -105,12 +118,14 @@ def set_waning_crescent():
105118
FULL_MOON: set_full_moon,
106119
WANING_GIBBOUS: set_waning_gibbous,
107120
THIRD_QUARTER: set_third_quarter,
108-
WANING_CRESCENT: set_waning_crescent
121+
WANING_CRESCENT: set_waning_crescent,
122+
DARK_MOON: set_dark_moon,
123+
RED_MOON: set_red_moon
109124
}
110125

111126
# test function, runs through all 8 in order
112127
def demo_all_phases(delay=1):
113-
for phase in range(8):
128+
for phase in range(9):
114129
print(f"Setting phase: {phase_names[phase]}")
115130
phase_functions[phase]()
116131
time.sleep(delay)
@@ -119,10 +134,15 @@ def demo_all_phases(delay=1):
119134
# takes response from API, matches to function, runs function
120135
def set_moon_phase(phase):
121136
phase_lower = phase.lower()
137+
error_check = 0
122138
for i, name in enumerate(phase_names):
123139
if phase_lower == name.lower():
140+
error_check = 1
124141
phase_functions[i]()
125142
print(f"Moon phase set to: {name}")
143+
if error_check == 0:
144+
print("ERROR")
145+
set_red_moon() #error indicator if API responce is unexpected
126146

127147
# time keeping, fetches API every 6 hours
128148
timer_clock = ticks_ms()

0 commit comments

Comments
 (0)