diff --git a/main.py b/main.py index 73f1431..aa86009 100644 --- a/main.py +++ b/main.py @@ -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") @@ -29,22 +45,33 @@ while True: time.sleep_ms(1000) 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) + #oled.drawLine(0, 48, 127, 48) + #oled.drawLine(0, 49, 127, 49) + oled.displayText(str(bme688.readTemperature()) + " oC", 3, 0) + oled.displayText(str(bme688.readHumidity()) + " %H", 3, 80) + eCO2 = bme688.readeCO2() + oled.displayText(str(eCO2) + " CO2 ppm", 4, 0) + IAQ = bme688.getAirQualityScore() + oled.displayText(str(IAQ) + " AQ ", 5, 0) + 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"); - #oled.drawRect(4, 5, 120, 35) - oled.displayText(rtc.readDateString(), 1, 25) - oled.displayText(rtc.readTimeString(), 2, 33) - #oled.drawLine(0, 48, 127, 48) - #oled.drawLine(0, 49, 127, 49) - oled.displayText(str(bme688.readTemperature()) + " oC", 3, 0) - oled.displayText(str(bme688.readHumidity()) + " %H", 3, 80) - eCO2 = bme688.readeCO2() - oled.displayText(str(eCO2) + " CO2 ppm", 4, 0) - IAQ = bme688.getAirQualityScore() - oled.displayText(str(IAQ) + " AQ ", 5, 0) - mbar = bme688.readPressure()/100.0 - oled.displayText(str(mbar) + " mB ", 5, 50) - oled.show() - if (IAQ < 100): zipleds.setLED(0, zipleds.GREEN) else: @@ -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): @@ -85,5 +130,4 @@ while True: if ( (sec+1) % 2 ) == 0: zipleds.setLED(1, zipleds.BLACK) - zipleds.show() - + zipleds.show() \ No newline at end of file