Skip to content

Commit 7d71ee6

Browse files
authored
Merge pull request adafruit#1142 from firepixie/master
Vertical Garden Code Update
2 parents ea5f5f5 + ebd17be commit 7d71ee6

File tree

1 file changed

+30
-16
lines changed

1 file changed

+30
-16
lines changed

Vertical_Garden_Barometer/code.py

Lines changed: 30 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@
33
Visualize air reading changes over time as a color animation on a NeoPixel strip
44
Display a "sinking" or "rising" graphic on the screen along with recent reading data
55
6-
Code by Erin St Blaine for Adafruit Industries
6+
Code by Erin St Blaine for Adafruit Industries :)
77
"""
8-
8+
import time
99
import board
1010
import neopixel
1111
from adafruit_clue import clue
@@ -15,12 +15,12 @@
1515
from adafruit_bitmap_font import bitmap_font
1616

1717
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
1919

2020
# Barometer or Thermometer? Uncomment the section you want to use
2121

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
2424
deviceType = 0
2525
min_reading = 960
2626
med_reading = 965
@@ -32,9 +32,9 @@
3232
# set desired temperature range - NeoPixel palette choice determined by these thresholds
3333
deviceType = 1
3434
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
3838
"""
3939

4040
# get an initial sensor reading
@@ -50,6 +50,8 @@
5050
counter = 0
5151
toggle = 1 # for on/off switch on button A
5252
displayOn = 1 # to turn the display on and off with button B
53+
button_b_pressed = False
54+
button_a_pressed = False
5355

5456
clue.display.brightness = 0.8
5557
clue_display = displayio.Group(max_size=4)
@@ -100,7 +102,7 @@
100102
icePalette = [0x8080FF, 0x8080FF, 0x8080FF, 0x0000FF, 0xC88AFF]
101103
sunPalette = [0xffaa00, 0xffdd00, 0x7d5b06, 0xfffca8]
102104
firePalette = [0xff0000, 0xff5500, 0x8a3104, 0xffaa00 ]
103-
forestPalette = [0xccffa8, 0x69f505, 0x05f551, 0x2c8247]
105+
forestPalette = [0x76DB00, 0x69f505, 0x05f551, 0x3B6D00]
104106

105107
# set up default initial palettes, just for startup
106108
palette = forestPalette
@@ -116,7 +118,8 @@
116118

117119
while True:
118120
# 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.")
120123
if toggle == 1:
121124
toggle = 0
122125
pixels.brightness = 0
@@ -125,23 +128,34 @@
125128
toggle = 1
126129
pixels.brightness = 1.0
127130
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
130139
if displayOn == 0:
131140
clue.display.brightness = 0.8
132141
displayOn = 1
133142
else:
134143
clue.display.brightness = 0
135144
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.
136150

137151
# assign color palette to NeoPixel section 1 based on the current reading reading
138152
if reading1 < min_reading:
139153
palette = firePalette
140-
elif reading1 > min_reading and reading1 < med_reading:
154+
elif min_reading > reading1 > med_reading:
141155
palette = sunPalette
142-
elif reading1 > med_reading and reading1 < high_reading:
156+
elif med_reading > reading1 > high_reading:
143157
palette = forestPalette
144-
elif reading1 > high_reading and reading1 < max_reading:
158+
elif high_reading > reading1 > max_reading:
145159
palette = waterPalette
146160
else:
147161
palette = icePalette
@@ -226,7 +240,7 @@
226240
reading3_label.y = 194
227241
timer_label.y = 224
228242
# 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
230244
sinking_sprite.x = 0
231245
reading_label.y = 24
232246
reading2_label.y = 54

0 commit comments

Comments
 (0)