diff --git a/M5Stack-SAM/APPS.ino b/M5Stack-SAM/APPS.ino index 7ab385f..c08ff98 100644 --- a/M5Stack-SAM/APPS.ino +++ b/M5Stack-SAM/APPS.ino @@ -33,7 +33,7 @@ void appBLEBaecon(){ menuUpdate(menuidx, menulock); } - +#if defined(WS_DHT12) void appDHT12(){ menuDrawMenu(F("DHT12"),F(""),F("ESC"),F(""),sys_menucolor,sys_windowcolor,sys_menutextcolor); M5.Lcd.drawString(F("TEMPERATURE"),30,80,2); @@ -60,6 +60,38 @@ void appDHT12(){ menuUpdate(menuidx, menulock); } +#elif defined(WS_BME280) +void appBME280(){ + menuDrawMenu(F("BME280"),F(""),F("ESC"),F(""),sys_menucolor,sys_windowcolor,sys_menutextcolor); + M5.Lcd.drawString(F("TEMPERATURE"),30,60,2); + M5.Lcd.drawString(F("°C"),250,60,2); + M5.Lcd.drawString(F("HUMIDITY"),30,120,2); + M5.Lcd.drawString(F("%RH"),250,120,2); + M5.Lcd.drawString(F("PRESSURE"),30,180,2); + M5.Lcd.drawString(F("hPa"),250,180,2); + menuidx = 1; + menulock = 0; + M5.Lcd.setTextColor(sys_menutextcolor, sys_windowcolor); + while(M5.BtnB.wasPressed()){ + M5.update(); + } + while(!M5.BtnB.wasPressed()){ + M5.update(); + if(millis()-tmp_tmr > 1000){ + tmp_tmr = millis(); + float tmp_temp = bme280.readTemperature(); + float tmp_humi = bme280.readHumidity(); + float tmp_pres = (bme280.readPressure()/100.0F); + //menuWindowClr(sys_windowcolor); + M5.Lcd.drawFloat(tmp_temp, 1, 140, 40, 6); + M5.Lcd.drawFloat(tmp_humi, 1, 140, 100, 6); + M5.Lcd.drawFloat(tmp_pres, 1, 140, 160, 6); + } + } + menuUpdate(menuidx, menulock); +} +#endif + void appStopky(){ boolean tmp_run = false; float tmp_sec = 0; diff --git a/M5Stack-SAM/GFX_MENU.ino b/M5Stack-SAM/GFX_MENU.ino index 5cbe9da..88d54ce 100644 --- a/M5Stack-SAM/GFX_MENU.ino +++ b/M5Stack-SAM/GFX_MENU.ino @@ -117,7 +117,11 @@ void menuAplikaceLevel(byte inmenuidx){ case 0: menuIsMenu = LOW; menuWindowClr(sys_windowcolor); - windowPrintInfoText(F("DHT12"),sys_menutextcolor); + #if defined(WS_DHT12) + windowPrintInfoText(F("DHT12"),sys_menutextcolor); + #elif defined(WS_BME280) + windowPrintInfoText(F("BME280"),sys_menutextcolor); + #endif break; case 1: menuIsMenu = LOW; @@ -166,7 +170,11 @@ void menuRunApp(byte inmenuidx, byte inmenulock){ } if(inmenulock==1 and inmenuidx==0){ - appDHT12(); + #if defined(WS_DHT12) + appDHT12(); + #elif defined(WS_BME280) + appBME280(); + #endif } if(inmenulock==1 and inmenuidx==1){ appStopky(); diff --git a/M5Stack-SAM/M5Stack-SAM.ino b/M5Stack-SAM/M5Stack-SAM.ino index 3462be8..d2f0b91 100644 --- a/M5Stack-SAM/M5Stack-SAM.ino +++ b/M5Stack-SAM/M5Stack-SAM.ino @@ -1,11 +1,33 @@ #include #include "EEPROM.h" -#include "utility/DHT12.h" #include #include "SimpleBeacon.h" +/* + * To let the Menu not grow to fast, both "Weather" Apps, + * appDHT12 and appBME280 use the same Menu Index. + * If you like appDHT12, use this define + * #define WEATHER_SENSOR WS_DHT12 + * else if you like appBME280, use this define + * #define WEATHER_SENSOR WS_BME280 + */ +#define WEATHER_SENSOR WS_BME280 + +#if defined(WS_DHT12) + #include "utility/DHT12.h" + DHT12 dht12; + +#elif defined(WS_BME280) + #include + #include + + #define SEALEVELPRESSURE_HPA (1013.25) + Adafruit_BME280 bme280; + bool status; +#endif + SimpleBeacon ble; -DHT12 dht12; + #define TFT_GREY 0x5AEB #define TFT_BROWN 0x38E0 @@ -29,7 +51,11 @@ unsigned long tmp_tmr = 0; void setup(void) { Serial.begin(115200); - + + #if defined(WS_BME280) + status = bme280.begin(0x76); + #endif + if (!EEPROM.begin(EEPROM_SIZE)) { Serial.println("failed to initialise EEPROM");