2929# neopixels, 49 total
3030OFF = (0 , 0 , 0 )
3131ON = (255 , 255 , 255 )
32+ RED = (255 ,0 ,0 )
3233pixel_pin = board .A3
3334num_pixels = 49
3435pixels = neopixel .NeoPixel (pixel_pin , num_pixels , brightness = 0.1 , auto_write = False )
4344WANING_GIBBOUS = 5
4445THIRD_QUARTER = 6
4546WANING_CRESCENT = 7
47+ DARK_MOON = 8
48+ RED_MOON = 9
4649# strings that match return from API
4750phase_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
5154def 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
100113phase_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
112127def 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
120135def 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
128148timer_clock = ticks_ms ()
0 commit comments