Button A re-activates the display

Button B turns the LEDS on for two mins (they fade)
Always get a red LED 1 flash when a data point is logged.
This commit is contained in:
Robin Clark 2022-04-11 09:34:11 +01:00
parent 135fb1e730
commit 451e61057a

56
main.py
View File

@ -1,16 +1,32 @@
# A weather station program display the date, time, temperature and humidity on the OLED screen with Air Quality and eCO2 on ZIP LEDs (Red/Green)
from PicoAirQuality import KitronikBME688, KitronikDataLogger, KitronikOLED, KitronikRTC, KitronikZIPLEDs
from PicoAirQuality import KitronikBME688, KitronikDataLogger, KitronikButton, KitronikOLED, KitronikRTC, KitronikZIPLEDs
import time
logFileName = "atmosphere_log.txt"
buttons = KitronikButton()
def ButtonA_IRQHandler(pin):
global buttonA
buttonA = 30
print("button A pressed", buttonA)
# LEDS ON FOR 2 MINS 10% brightness
def ButtonB_IRQHandler(pin):
global buttonB
buttonB = 2*60
print("button B pressed", buttonB)
buttons.buttonA.irq(trigger=machine.Pin.IRQ_RISING, handler=ButtonA_IRQHandler)
buttons.buttonB.irq(trigger=machine.Pin.IRQ_RISING, handler=ButtonB_IRQHandler)
bme688 = KitronikBME688()
oled = KitronikOLED()
rtc = KitronikRTC()
zipleds = KitronikZIPLEDs(3)
# Python u arse hole sec = Integer()
#rtc.setDate(07, 4, 2022)
#rtc.setTime(21, 58, 0)
@ -21,7 +37,7 @@ sec = 0
#f.write("# Data Logging: Date, Time, Temperature, Pressure, Humidity, AirQuality, CO2\n")
while True:
#global buttonA, buttonB
if sec == 0:
f = open(logFileName, 'a+')
f.write("# Data Logging: Date, Time, Temperature, Pressure, Humidity, AirQuality, CO2\n")
@ -30,6 +46,13 @@ while True:
bme688.measureData()
oled.clear()
try:
_ = buttonA
except NameError:
buttonA = 30
if buttonA > 0:
oled.poweron()
#oled.drawRect(4, 5, 120, 35)
oled.displayText(rtc.readDateString(), 1, 25)
oled.displayText(rtc.readTimeString(), 2, 33)
@ -44,6 +67,10 @@ while True:
mbar = bme688.readPressure()/100.0
oled.displayText(str(mbar) + " mB ", 5, 50)
oled.show()
buttonA = buttonA - 1
else:
oled.poweroff() # would really like to turn it off
#print("oled.clear");
if (IAQ < 100):
zipleds.setLED(0, zipleds.GREEN)
@ -53,14 +80,28 @@ while True:
zipleds.setLED(2, zipleds.GREEN)
else:
zipleds.setLED(2, zipleds.RED)
zipleds.setBrightness(10)
try:
_ = buttonB
except NameError:
buttonB = 30
if buttonB > 0:
brightness = buttonB/4
if brightness > 100:
brighness = 100
zipleds.setBrightness(brightness)
buttonB = buttonB - 1
else:
zipleds.setBrightness(0)
# ffs all I want is an action every minute I hate python scope shit
#now = rtc.readTimeString();
# log every minute, thats 1440 records a day
sec = sec + 1
secmod = sec % 29
secmod = sec % 59
if (secmod) == 0:
#log.setupDataFields("Date", "Time", "Temperature", "Pressure", "Humidity", "IAQ", "eCO2")
log_string = (rtc.readDateString() + ',' + \
@ -75,6 +116,10 @@ while True:
f.write(log_string)
f.flush()
zipleds.setLED(1, zipleds.RED)
zipleds.setLED(0, zipleds.BLACK)
zipleds.setLED(2, zipleds.BLACK)
zipleds.setBrightness(20) # always show a logging flash
#print("flash");
elif (secmod < 10):
zipleds.setLED(1, zipleds.BLUE)
elif (secmod > 10):
@ -86,4 +131,3 @@ while True:
zipleds.setLED(1, zipleds.BLACK)
zipleds.show()