29
29
# neopixels, 49 total
30
30
OFF = (0 , 0 , 0 )
31
31
ON = (255 , 255 , 255 )
32
+ RED = (255 ,0 ,0 )
32
33
pixel_pin = board .A3
33
34
num_pixels = 49
34
35
pixels = neopixel .NeoPixel (pixel_pin , num_pixels , brightness = 0.1 , auto_write = False )
43
44
WANING_GIBBOUS = 5
44
45
THIRD_QUARTER = 6
45
46
WANING_CRESCENT = 7
47
+ DARK_MOON = 8
48
+ RED_MOON = 9
46
49
# strings that match return from API
47
50
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" ]
49
52
50
53
# functions for each moon phase to light up based on neopixel orientation
51
54
def set_new_moon ():
@@ -96,6 +99,16 @@ def set_waning_crescent():
96
99
pixels [i ] = ON
97
100
pixels .show ()
98
101
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
+
99
112
# match functions with phases
100
113
phase_functions = {
101
114
NEW_MOON : set_new_moon ,
@@ -105,12 +118,14 @@ def set_waning_crescent():
105
118
FULL_MOON : set_full_moon ,
106
119
WANING_GIBBOUS : set_waning_gibbous ,
107
120
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
109
124
}
110
125
111
126
# test function, runs through all 8 in order
112
127
def demo_all_phases (delay = 1 ):
113
- for phase in range (8 ):
128
+ for phase in range (9 ):
114
129
print (f"Setting phase: { phase_names [phase ]} " )
115
130
phase_functions [phase ]()
116
131
time .sleep (delay )
@@ -119,10 +134,15 @@ def demo_all_phases(delay=1):
119
134
# takes response from API, matches to function, runs function
120
135
def set_moon_phase (phase ):
121
136
phase_lower = phase .lower ()
137
+ error_check = 0
122
138
for i , name in enumerate (phase_names ):
123
139
if phase_lower == name .lower ():
140
+ error_check = 1
124
141
phase_functions [i ]()
125
142
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
126
146
127
147
# time keeping, fetches API every 6 hours
128
148
timer_clock = ticks_ms ()
0 commit comments