42
42
43
43
spi = busio .SPI (board .SCK , board .MOSI , board .MISO )
44
44
esp = 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
46
46
wifi = adafruit_esp32spi_wifimanager .ESPSPI_WiFiManager (esp , secrets , status_light )
47
47
pixels = neopixel .NeoPixel (board .D2 , 150 , brightness = 1.0 , auto_write = False )
48
48
pixels .fill (0x050505 )
49
49
pixels .show ()
50
50
51
51
# 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
55
55
# 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
59
59
# 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
63
63
last_thunder_bolt = None
64
64
65
65
palette = None # current palette
87
87
pressed_time = time .monotonic ()
88
88
button_select = True
89
89
weather_refresh = None
90
- while not button .value :
90
+ while not button .value : # Debounce
91
91
audio .stop ()
92
- #print("Debounce")
93
92
if (time .monotonic () - pressed_time ) > 4 :
94
93
print ("Turning OFF" )
95
94
cloud_on = False
96
- pixels .fill (0x000000 ) # bright white!
95
+ pixels .fill (0x000000 ) # bright white!
97
96
pixels .show ()
98
97
while not cloud_on :
99
- while not button .value :
98
+ while not button .value : # Debounce
100
99
pass
101
- #print("Debounce")
102
100
if not button .value :
103
101
pressed_time = time .monotonic ()
104
102
print ("Button Pressed" )
105
103
cloud_on = True
106
104
button_select = False
107
105
weather_refresh = None
108
-
106
+
109
107
if button_mode == 0 :
110
108
weather_type = 'Sunny'
111
109
if button_mode == 1 :
124
122
response = wifi .get (DATA_SOURCE ).json ()
125
123
print ("Response is" , response )
126
124
weather_type = response ['weather' ][0 ]['main' ]
127
- #weather_type = 'Rain' # manually adjust weather type for testing!
128
125
if weather_type == 'Clear' :
129
126
weather_type = 'Sunny'
130
- print (weather_type ) # See https://openweathermap.org/weather-conditions
127
+ print (weather_type ) # See https://openweathermap.org/weather-conditions
131
128
# default to no rain or thunder
132
129
raining = snowing = thundering = has_sound = False
133
130
if weather_type == 'Sunny' :
193
190
print ("Ka Bam!" )
194
191
# fill pixels white, delay, a few times
195
192
for i in range (random .randint (1 , 3 )): # up to 3 times...
196
- pixels .fill (0xFFFFFF ) # bright white!
193
+ pixels .fill (0xFFFFFF ) # bright white!
197
194
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
200
197
pixels .show ()
201
- time .sleep (random .uniform (0.01 , 0.3 )) # pause
198
+ time .sleep (random .uniform (0.01 , 0.3 )) # pause
202
199
# pick next thunderbolt time now
203
200
Thunder = random .randint (0 , 2 )
204
201
if Thunder == 0 :
209
206
wave_file = open ("sound/Thunderstorm2.wav" , "rb" )
210
207
wave = audioio .WaveFile (wave_file )
211
208
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