4242
4343spi = busio .SPI (board .SCK , board .MOSI , board .MISO )
4444esp = adafruit_esp32spi .ESP_SPIcontrol (spi , esp32_cs , esp32_ready , esp32_reset )
45- status_light = neopixel .NeoPixel (board .NEOPIXEL , 1 , brightness = 0.2 ) # Uncomment for Most Boards
45+ status_light = neopixel .NeoPixel (board .NEOPIXEL , 1 , brightness = 0.2 ) # Uncomment for Most Boards
4646wifi = adafruit_esp32spi_wifimanager .ESPSPI_WiFiManager (esp , secrets , status_light )
4747pixels = neopixel .NeoPixel (board .D2 , 150 , brightness = 1.0 , auto_write = False )
4848pixels .fill (0x050505 )
4949pixels .show ()
5050
5151# clouds palette
52- cloudy_palette = [fancy .CRGB (1.0 , 1.0 , 1.0 ), # White
53- fancy .CRGB (0.5 , 0.5 , 0.5 ), # gray
54- fancy .CRGB (0.5 , 0.5 , 1.0 )] # blue-gray
52+ cloudy_palette = [fancy .CRGB (1.0 , 1.0 , 1.0 ), # White
53+ fancy .CRGB (0.5 , 0.5 , 0.5 ), # gray
54+ fancy .CRGB (0.5 , 0.5 , 1.0 )] # blue-gray
5555# sunny palette
56- sunny_palette = [fancy .CRGB (1.0 , 1.0 , 1.0 ), # White
57- fancy .CRGB (1.0 , 1.0 , 0.0 ),# Yellow
58- fancy .CRGB (1.0 , 0.5 , 0.0 ),] # Orange
56+ sunny_palette = [fancy .CRGB (1.0 , 1.0 , 1.0 ), # White
57+ fancy .CRGB (1.0 , 1.0 , 0.0 ), # Yellow
58+ fancy .CRGB (1.0 , 0.5 , 0.0 ), ] # Orange
5959# thunderstorm palette
60- thunder_palette = [fancy .CRGB (0.0 , 0.0 , 1.0 ), # blue
61- fancy .CRGB (0.5 , 0.5 , 0.5 ), # gray
62- fancy .CRGB (0.5 , 0.5 , 1.0 )] # blue-gray
60+ thunder_palette = [fancy .CRGB (0.0 , 0.0 , 1.0 ), # blue
61+ fancy .CRGB (0.5 , 0.5 , 0.5 ), # gray
62+ fancy .CRGB (0.5 , 0.5 , 1.0 )] # blue-gray
6363last_thunder_bolt = None
6464
6565palette = None # current palette
8787 pressed_time = time .monotonic ()
8888 button_select = True
8989 weather_refresh = None
90- while not button .value :
90+ while not button .value : # Debounce
9191 audio .stop ()
92- #print("Debounce")
9392 if (time .monotonic () - pressed_time ) > 4 :
9493 print ("Turning OFF" )
9594 cloud_on = False
96- pixels .fill (0x000000 ) # bright white!
95+ pixels .fill (0x000000 ) # bright white!
9796 pixels .show ()
9897 while not cloud_on :
99- while not button .value :
98+ while not button .value : # Debounce
10099 pass
101- #print("Debounce")
102100 if not button .value :
103101 pressed_time = time .monotonic ()
104102 print ("Button Pressed" )
105103 cloud_on = True
106104 button_select = False
107105 weather_refresh = None
108-
106+
109107 if button_mode == 0 :
110108 weather_type = 'Sunny'
111109 if button_mode == 1 :
124122 response = wifi .get (DATA_SOURCE ).json ()
125123 print ("Response is" , response )
126124 weather_type = response ['weather' ][0 ]['main' ]
127- #weather_type = 'Rain' # manually adjust weather type for testing!
128125 if weather_type == 'Clear' :
129126 weather_type = 'Sunny'
130- print (weather_type ) # See https://openweathermap.org/weather-conditions
127+ print (weather_type ) # See https://openweathermap.org/weather-conditions
131128 # default to no rain or thunder
132129 raining = snowing = thundering = has_sound = False
133130 if weather_type == 'Sunny' :
193190 print ("Ka Bam!" )
194191 # fill pixels white, delay, a few times
195192 for i in range (random .randint (1 , 3 )): # up to 3 times...
196- pixels .fill (0xFFFFFF ) # bright white!
193+ pixels .fill (0xFFFFFF ) # bright white!
197194 pixels .show ()
198- time .sleep (random .uniform (0.01 , 0.2 )) # pause
199- pixels .fill (0x0F0F0F ) # gray
195+ time .sleep (random .uniform (0.01 , 0.2 )) # pause
196+ pixels .fill (0x0F0F0F ) # gray
200197 pixels .show ()
201- time .sleep (random .uniform (0.01 , 0.3 )) # pause
198+ time .sleep (random .uniform (0.01 , 0.3 )) # pause
202199 # pick next thunderbolt time now
203200 Thunder = random .randint (0 , 2 )
204201 if Thunder == 0 :
209206 wave_file = open ("sound/Thunderstorm2.wav" , "rb" )
210207 wave = audioio .WaveFile (wave_file )
211208 audio .play (wave )
212- next_bolt_time = time .monotonic () + random .randint (5 , 15 ) # between 5 and 15 s
209+ next_bolt_time = time .monotonic () + random .randint (5 , 15 ) # between 5 and 15 s
0 commit comments