Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Pressure balloon demo with BMP280 on Feather nRF52840 Sense
# 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
You can’t perform that action at this time.