Update code.py

This commit is contained in:
Anne Barela 2020-04-30 11:21:04 -04:00 committed by GitHub
parent 7e61cec67b
commit 8ad22e491e
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -1,4 +1,3 @@
""" """
Read the barometric reading in the air Read the barometric reading in the air
Visualize air reading changes over time as a color animation on a NeoPixel strip Visualize air reading changes over time as a color animation on a NeoPixel strip
@ -15,7 +14,6 @@ import displayio
from adafruit_display_text import label from adafruit_display_text import label
from adafruit_bitmap_font import bitmap_font from adafruit_bitmap_font import bitmap_font
num_leds = 79 #number of LEDs in your strip num_leds = 79 #number of LEDs in your strip
timeToCheck = 100 # set the amount of time between sensor checks. 7800 is approx. 1 hour timeToCheck = 100 # set the amount of time between sensor checks. 7800 is approx. 1 hour
@ -31,7 +29,7 @@ max_reading = 975
""" """
# THERMOMETER RANGES (C) # THERMOMETER RANGES (C)
# set desired temperature range -- the NeoPixel palette choice will be determined by these thresholds # set desired temperature range - NeoPixel palette choice determined by these thresholds
deviceType = 1 deviceType = 1
min_reading = 25 min_reading = 25
med_reading = 27 med_reading = 27
@ -39,7 +37,7 @@ high_reading= 31
max_reading = 33 max_reading = 33
""" """
#get an initial sensor reading # get an initial sensor reading
if deviceType ==0: if deviceType ==0:
reading = clue.pressure reading = clue.pressure
else: else:
@ -50,8 +48,8 @@ reading1 = reading
reading2 = reading1 reading2 = reading1
reading3 = reading2 reading3 = reading2
counter = 0 counter = 0
toggle = 1 #for on/off switch on button A toggle = 1 # for on/off switch on button A
displayOn = 1 #to turn the display on and off with button B displayOn = 1 # to turn the display on and off with button B
clue.display.brightness = 0.8 clue.display.brightness = 0.8
clue_display = displayio.Group(max_size=4) clue_display = displayio.Group(max_size=4)
@ -98,34 +96,13 @@ clue_display.append(text_group)
clue.display.show(clue_display) clue.display.show(clue_display)
# Define color Palettes # Define color Palettes
waterPalette = [ waterPalette = [0x00d9ff, 0x006f82, 0x43bfb9, 0x0066ff]
0x00d9ff, icePalette = [0x8080FF, 0x8080FF, 0x8080FF, 0x0000FF, 0xC88AFF]
0x006f82, sunPalette = [0xffaa00, 0xffdd00, 0x7d5b06, 0xfffca8]
0x43bfb9, firePalette = [0xff0000, 0xff5500, 0x8a3104, 0xffaa00 ]
0x0066ff] forestPalette = [0xccffa8, 0x69f505, 0x05f551, 0x2c8247]
icePalette = [
0x8080FF,
0x8080FF,
0x8080FF,
0x0000FF,
0xC88AFF]
sunPalette = [
0xffaa00,
0xffdd00,
0x7d5b06,
0xfffca8]
firePalette = [
0xff0000,
0xff5500,
0x8a3104,
0xffaa00 ]
forestPalette = [
0xccffa8,
0x69f505,
0x05f551,
0x2c8247]
#set up default initial palettes, just for startup # set up default initial palettes, just for startup
palette = forestPalette palette = forestPalette
palette2 = waterPalette palette2 = waterPalette
palette3 = icePalette palette3 = icePalette
@ -149,7 +126,7 @@ while True:
pixels.brightness = 1.0 pixels.brightness = 1.0
clue.display.brightness = 0.8 clue.display.brightness = 0.8
if clue.button_b: if clue.button_b:
#Toggle only the display on and off # Toggle only the display on and off
if displayOn == 0: if displayOn == 0:
clue.display.brightness = 0.8 clue.display.brightness = 0.8
displayOn = 1 displayOn = 1
@ -157,7 +134,7 @@ while True:
clue.display.brightness = 0 clue.display.brightness = 0
displayOn = 0 displayOn = 0
#assign color palette to NeoPixel section 1 based on the current reading reading # assign color palette to NeoPixel section 1 based on the current reading reading
if reading1 < min_reading: if reading1 < min_reading:
palette = firePalette palette = firePalette
elif reading1 > min_reading and reading1 < med_reading: elif reading1 > min_reading and reading1 < med_reading:
@ -168,7 +145,7 @@ while True:
palette = waterPalette palette = waterPalette
else: else:
palette = icePalette palette = icePalette
#Map colors to pixels. Adjust range numbers to light up specific pixels. This configuration # Map colors to pixels. Adjust range numbers to light up specific pixels. This configuration
# maps to a reflected gradient, with pixel 0 in the upper left corner # maps to a reflected gradient, with pixel 0 in the upper left corner
# Load each pixel's color from the palette using an offset, run it # Load each pixel's color from the palette using an offset, run it
# through the gamma function, pack RGB value and assign to pixel. # through the gamma function, pack RGB value and assign to pixel.
@ -226,35 +203,35 @@ while True:
timer_label.text = "{}".format(counter) timer_label.text = "{}".format(counter)
clue.display.show(clue_display) clue.display.show(clue_display)
#Is it time to update? # Is it time to update?
if counter > timeToCheck: if counter > timeToCheck:
#This moves the current data to the "1 hour old" section of pixels and the "1 hour old" data # This moves the current data to the "1 hour old" section of pixels and the "1 hour old"
#to the "2 hours old" section of pixels # data to the "2 hours old" section of pixels
palette3 = palette2 palette3 = palette2
palette2 = palette palette2 = palette
reading3 = reading2 reading3 = reading2
reading2 = reading1 reading2 = reading1
reading1 = reading reading1 = reading
#take a new sensor reading and reset the counter # take a new sensor reading and reset the counter
if deviceType == 0: if deviceType == 0:
reading = clue.pressure reading = clue.pressure
else: else:
reading = clue.temperature reading = clue.temperature
counter = 0 counter = 0
#if reading is rising, show rising image and position text at the bottom # if reading is rising, show rising image and position text at the bottom
if reading1 > reading2: if reading1 > reading2:
sinking_sprite.x = 300 sinking_sprite.x = 300
reading_label.y = 134 reading_label.y = 134
reading2_label.y = 164 reading2_label.y = 164
reading3_label.y = 194 reading3_label.y = 194
timer_label.y = 224 timer_label.y = 224
#if reading is falling, show sinking image and position text at the top # if reading is falling, show sinking image and position text at the top
elif reading2 < reading3: #reading is falling elif reading2 < reading3: #reading is falling
sinking_sprite.x = 0 sinking_sprite.x = 0
reading_label.y = 24 reading_label.y = 24
reading2_label.y = 54 reading2_label.y = 54
reading3_label.y = 84 reading3_label.y = 84
timer_label.y = 114 timer_label.y = 114
#otherwise keep counting up # otherwise keep counting up
else: else:
counter = counter + 1 counter = counter + 1