Created
August 31, 2020 17:34
-
-
Save dglaude/ac9a4e9b87d17e06671599bf175077f2 to your computer and use it in GitHub Desktop.
Pressure balloon demo with BMP280 on Feather nRF52840 Sense
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Simple Pressure to color demo. | |
import time | |
import board | |
import digitalio | |
import neopixel | |
import adafruit_bmp280 | |
# Used for pressure. | |
bmp280 = adafruit_bmp280.Adafruit_BMP280_I2C(board.I2C()) | |
# Feather nRF52840 Sense with single NeoPixel. | |
pin_pixels = board.NEOPIXEL | |
num_pixels = 1 | |
pixels = neopixel.NeoPixel(pin_pixels, num_pixels, brightness=1, auto_write=False) | |
pixels.fill( (0,0,255) ) | |
pixels.show() | |
time.sleep(1) | |
ratio = 0.0 | |
baro_range = 0.0 | |
baro_min = bmp280.pressure | |
baro_max = baro_min + 1.0 # Avoid flickering between green and red at startup | |
while True: | |
baro_now = bmp280.pressure | |
if baro_now > baro_max: | |
baro_max = baro_now | |
# print("MAX reached and adjusted") | |
if baro_now < baro_min: | |
baro_min = baro_now | |
# print("min reached and adjusted") | |
baro_range=baro_max-baro_min | |
baro_zero=baro_now-baro_min | |
ratio = (baro_zero*100.0) / baro_range | |
colour = ratio * 255 / 100 | |
colour_inv = 255 - colour | |
color = (colour, colour_inv, 0) | |
pixels.fill( color ) # Green to Red depending on pressure | |
pixels.show() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment