|
1 |
| - |
2 | 1 | """
|
3 | 2 | Read the barometric reading in the air
|
4 | 3 | Visualize air reading changes over time as a color animation on a NeoPixel strip
|
|
15 | 14 | from adafruit_display_text import label
|
16 | 15 | from adafruit_bitmap_font import bitmap_font
|
17 | 16 |
|
18 |
| - |
19 | 17 | num_leds = 79 #number of LEDs in your strip
|
20 | 18 | timeToCheck = 100 # set the amount of time between sensor checks. 7800 is approx. 1 hour
|
21 | 19 |
|
|
31 | 29 |
|
32 | 30 | """
|
33 | 31 | # THERMOMETER RANGES (C)
|
34 |
| -# set desired temperature range -- the NeoPixel palette choice will be determined by these thresholds |
| 32 | +# set desired temperature range - NeoPixel palette choice determined by these thresholds |
35 | 33 | deviceType = 1
|
36 | 34 | min_reading = 25
|
37 | 35 | med_reading = 27
|
38 | 36 | high_reading= 31
|
39 | 37 | max_reading = 33
|
40 | 38 | """
|
41 | 39 |
|
42 |
| -#get an initial sensor reading |
| 40 | +# get an initial sensor reading |
43 | 41 | if deviceType ==0:
|
44 | 42 | reading = clue.pressure
|
45 | 43 | else:
|
|
50 | 48 | reading2 = reading1
|
51 | 49 | reading3 = reading2
|
52 | 50 | counter = 0
|
53 |
| -toggle = 1 #for on/off switch on button A |
54 |
| -displayOn = 1 #to turn the display on and off with button B |
| 51 | +toggle = 1 # for on/off switch on button A |
| 52 | +displayOn = 1 # to turn the display on and off with button B |
55 | 53 |
|
56 | 54 | clue.display.brightness = 0.8
|
57 | 55 | clue_display = displayio.Group(max_size=4)
|
|
98 | 96 | clue.display.show(clue_display)
|
99 | 97 |
|
100 | 98 | # Define color Palettes
|
101 |
| -waterPalette = [ |
102 |
| - 0x00d9ff, |
103 |
| - 0x006f82, |
104 |
| - 0x43bfb9, |
105 |
| - 0x0066ff] |
106 |
| -icePalette = [ |
107 |
| - 0x8080FF, |
108 |
| - 0x8080FF, |
109 |
| - 0x8080FF, |
110 |
| - 0x0000FF, |
111 |
| - 0xC88AFF] |
112 |
| -sunPalette = [ |
113 |
| - 0xffaa00, |
114 |
| - 0xffdd00, |
115 |
| - 0x7d5b06, |
116 |
| - 0xfffca8] |
117 |
| -firePalette = [ |
118 |
| - 0xff0000, |
119 |
| - 0xff5500, |
120 |
| - 0x8a3104, |
121 |
| - 0xffaa00 ] |
122 |
| -forestPalette = [ |
123 |
| - 0xccffa8, |
124 |
| - 0x69f505, |
125 |
| - 0x05f551, |
126 |
| - 0x2c8247] |
127 |
| - |
128 |
| -#set up default initial palettes, just for startup |
| 99 | +waterPalette = [0x00d9ff, 0x006f82, 0x43bfb9, 0x0066ff] |
| 100 | +icePalette = [0x8080FF, 0x8080FF, 0x8080FF, 0x0000FF, 0xC88AFF] |
| 101 | +sunPalette = [0xffaa00, 0xffdd00, 0x7d5b06, 0xfffca8] |
| 102 | +firePalette = [0xff0000, 0xff5500, 0x8a3104, 0xffaa00 ] |
| 103 | +forestPalette = [0xccffa8, 0x69f505, 0x05f551, 0x2c8247] |
| 104 | + |
| 105 | +# set up default initial palettes, just for startup |
129 | 106 | palette = forestPalette
|
130 | 107 | palette2 = waterPalette
|
131 | 108 | palette3 = icePalette
|
|
149 | 126 | pixels.brightness = 1.0
|
150 | 127 | clue.display.brightness = 0.8
|
151 | 128 | if clue.button_b:
|
152 |
| - #Toggle only the display on and off |
| 129 | + # Toggle only the display on and off |
153 | 130 | if displayOn == 0:
|
154 | 131 | clue.display.brightness = 0.8
|
155 | 132 | displayOn = 1
|
156 | 133 | else:
|
157 | 134 | clue.display.brightness = 0
|
158 | 135 | displayOn = 0
|
159 | 136 |
|
160 |
| - #assign color palette to NeoPixel section 1 based on the current reading reading |
| 137 | + # assign color palette to NeoPixel section 1 based on the current reading reading |
161 | 138 | if reading1 < min_reading:
|
162 | 139 | palette = firePalette
|
163 | 140 | elif reading1 > min_reading and reading1 < med_reading:
|
|
168 | 145 | palette = waterPalette
|
169 | 146 | else:
|
170 | 147 | palette = icePalette
|
171 |
| - #Map colors to pixels. Adjust range numbers to light up specific pixels. This configuration |
| 148 | + # Map colors to pixels. Adjust range numbers to light up specific pixels. This configuration |
172 | 149 | # maps to a reflected gradient, with pixel 0 in the upper left corner
|
173 | 150 | # Load each pixel's color from the palette using an offset, run it
|
174 | 151 | # through the gamma function, pack RGB value and assign to pixel.
|
|
226 | 203 | timer_label.text = "{}".format(counter)
|
227 | 204 | clue.display.show(clue_display)
|
228 | 205 |
|
229 |
| - #Is it time to update? |
| 206 | + # Is it time to update? |
230 | 207 | if counter > timeToCheck:
|
231 |
| - #This moves the current data to the "1 hour old" section of pixels and the "1 hour old" data |
232 |
| - #to the "2 hours old" section of pixels |
| 208 | + # This moves the current data to the "1 hour old" section of pixels and the "1 hour old" |
| 209 | + # data to the "2 hours old" section of pixels |
233 | 210 | palette3 = palette2
|
234 | 211 | palette2 = palette
|
235 | 212 | reading3 = reading2
|
236 | 213 | reading2 = reading1
|
237 | 214 | reading1 = reading
|
238 |
| - #take a new sensor reading and reset the counter |
| 215 | + # take a new sensor reading and reset the counter |
239 | 216 | if deviceType == 0:
|
240 | 217 | reading = clue.pressure
|
241 | 218 | else:
|
242 | 219 | reading = clue.temperature
|
243 | 220 | counter = 0
|
244 |
| - #if reading is rising, show rising image and position text at the bottom |
| 221 | + # if reading is rising, show rising image and position text at the bottom |
245 | 222 | if reading1 > reading2:
|
246 | 223 | sinking_sprite.x = 300
|
247 | 224 | reading_label.y = 134
|
248 | 225 | reading2_label.y = 164
|
249 | 226 | reading3_label.y = 194
|
250 | 227 | timer_label.y = 224
|
251 |
| - #if reading is falling, show sinking image and position text at the top |
| 228 | + # if reading is falling, show sinking image and position text at the top |
252 | 229 | elif reading2 < reading3: #reading is falling
|
253 | 230 | sinking_sprite.x = 0
|
254 | 231 | reading_label.y = 24
|
255 | 232 | reading2_label.y = 54
|
256 | 233 | reading3_label.y = 84
|
257 | 234 | timer_label.y = 114
|
258 |
| - #otherwise keep counting up |
| 235 | + # otherwise keep counting up |
259 | 236 | else:
|
260 | 237 | counter = counter + 1
|
0 commit comments