|
3 | 3 | Visualize air reading changes over time as a color animation on a NeoPixel strip
|
4 | 4 | Display a "sinking" or "rising" graphic on the screen along with recent reading data
|
5 | 5 |
|
6 |
| -Code by Erin St Blaine for Adafruit Industries |
| 6 | +Code by Erin St Blaine for Adafruit Industries :) |
7 | 7 | """
|
8 |
| - |
| 8 | +import time |
9 | 9 | import board
|
10 | 10 | import neopixel
|
11 | 11 | from adafruit_clue import clue
|
|
15 | 15 | from adafruit_bitmap_font import bitmap_font
|
16 | 16 |
|
17 | 17 | num_leds = 79 #number of LEDs in your strip
|
18 |
| -timeToCheck = 100 # set the amount of time between sensor checks. 7800 is approx. 1 hour |
| 18 | +timeToCheck = 23400 # set the amount of time between sensor checks. 7800 is approx. 1 hour |
19 | 19 |
|
20 | 20 | # Barometer or Thermometer? Uncomment the section you want to use
|
21 | 21 |
|
22 |
| -# BAROMETER RANGES (hPa) |
23 |
| -# set desired reading range -- the NeoPixel palette choice will be determined by these thresholds |
| 22 | +#BAROMETER RANGES (hPa) |
| 23 | +#set desired reading range -- the NeoPixel palette choice will be determined by these thresholds |
24 | 24 | deviceType = 0
|
25 | 25 | min_reading = 960
|
26 | 26 | med_reading = 965
|
|
32 | 32 | # set desired temperature range - NeoPixel palette choice determined by these thresholds
|
33 | 33 | deviceType = 1
|
34 | 34 | min_reading = 25
|
35 |
| -med_reading = 27 |
36 |
| -high_reading= 31 |
37 |
| -max_reading = 33 |
| 35 | +med_reading = 26 |
| 36 | +high_reading= 27 |
| 37 | +max_reading = 28 |
38 | 38 | """
|
39 | 39 |
|
40 | 40 | # get an initial sensor reading
|
|
50 | 50 | counter = 0
|
51 | 51 | toggle = 1 # for on/off switch on button A
|
52 | 52 | displayOn = 1 # to turn the display on and off with button B
|
| 53 | +button_b_pressed = False |
| 54 | +button_a_pressed = False |
53 | 55 |
|
54 | 56 | clue.display.brightness = 0.8
|
55 | 57 | clue_display = displayio.Group(max_size=4)
|
|
100 | 102 | icePalette = [0x8080FF, 0x8080FF, 0x8080FF, 0x0000FF, 0xC88AFF]
|
101 | 103 | sunPalette = [0xffaa00, 0xffdd00, 0x7d5b06, 0xfffca8]
|
102 | 104 | firePalette = [0xff0000, 0xff5500, 0x8a3104, 0xffaa00 ]
|
103 |
| -forestPalette = [0xccffa8, 0x69f505, 0x05f551, 0x2c8247] |
| 105 | +forestPalette = [0x76DB00, 0x69f505, 0x05f551, 0x3B6D00] |
104 | 106 |
|
105 | 107 | # set up default initial palettes, just for startup
|
106 | 108 | palette = forestPalette
|
|
116 | 118 |
|
117 | 119 | while True:
|
118 | 120 | # use button A to toggle the NeoPixels on or off by changing brightness
|
119 |
| - if clue.button_a: |
| 121 | + if clue.button_a and not button_a_pressed: # If button A pressed... |
| 122 | + print("Button A pressed.") |
120 | 123 | if toggle == 1:
|
121 | 124 | toggle = 0
|
122 | 125 | pixels.brightness = 0
|
|
125 | 128 | toggle = 1
|
126 | 129 | pixels.brightness = 1.0
|
127 | 130 | clue.display.brightness = 0.8
|
128 |
| - if clue.button_b: |
129 |
| - # Toggle only the display on and off |
| 131 | + button_a_pressed = True # Set to True. |
| 132 | + time.sleep(0.03) # Debounce. |
| 133 | + if not clue.button_a and button_a_pressed: # On button release... |
| 134 | + button_a_pressed = False # Set to False. |
| 135 | + time.sleep(0.03) # Debounce. |
| 136 | + if clue.button_b and not button_b_pressed: # If button B pressed... |
| 137 | + print("Button B pressed.") |
| 138 | + # Toggle only the display on and off |
130 | 139 | if displayOn == 0:
|
131 | 140 | clue.display.brightness = 0.8
|
132 | 141 | displayOn = 1
|
133 | 142 | else:
|
134 | 143 | clue.display.brightness = 0
|
135 | 144 | displayOn = 0
|
| 145 | + button_b_pressed = True # Set to True. |
| 146 | + time.sleep(0.03) # Debounce. |
| 147 | + if not clue.button_b and button_b_pressed: # On button release... |
| 148 | + button_b_pressed = False # Set to False. |
| 149 | + time.sleep(0.03) # Debounce. |
136 | 150 |
|
137 | 151 | # assign color palette to NeoPixel section 1 based on the current reading reading
|
138 | 152 | if reading1 < min_reading:
|
139 | 153 | palette = firePalette
|
140 |
| - elif reading1 > min_reading and reading1 < med_reading: |
| 154 | + elif min_reading > reading1 > med_reading: |
141 | 155 | palette = sunPalette
|
142 |
| - elif reading1 > med_reading and reading1 < high_reading: |
| 156 | + elif med_reading > reading1 > high_reading: |
143 | 157 | palette = forestPalette
|
144 |
| - elif reading1 > high_reading and reading1 < max_reading: |
| 158 | + elif high_reading > reading1 > max_reading: |
145 | 159 | palette = waterPalette
|
146 | 160 | else:
|
147 | 161 | palette = icePalette
|
|
226 | 240 | reading3_label.y = 194
|
227 | 241 | timer_label.y = 224
|
228 | 242 | # if reading is falling, show sinking image and position text at the top
|
229 |
| - elif reading2 < reading3: #reading is falling |
| 243 | + elif reading1 < reading2: #reading is falling |
230 | 244 | sinking_sprite.x = 0
|
231 | 245 | reading_label.y = 24
|
232 | 246 | reading2_label.y = 54
|
|
0 commit comments