diff --git a/include/YourSensor.h b/include/YourSensor.h index c70b0bba..9c3b72c8 100644 --- a/include/YourSensor.h +++ b/include/YourSensor.h @@ -6,3 +6,4 @@ float yourSensorReading(String type, String addr); void HDC1080_init(String addr); void AHTX0_init(); void LCD_init(); +void BH1750_init(); diff --git a/platformio.ini b/platformio.ini index a11f6404..c7c184f2 100644 --- a/platformio.ini +++ b/platformio.ini @@ -44,6 +44,7 @@ lib_deps = ClosedCube HDC1080 Adafruit AHTX0 LiquidCrystal_I2C + BH1750 monitor_filters = esp8266_exception_decoder upload_speed = 921600 monitor_speed = 115200 @@ -71,6 +72,7 @@ lib_deps = ClosedCube HDC1080 Adafruit AHTX0 LiquidCrystal_I2C + BH1750 monitor_filters = esp8266_exception_decoder upload_speed = 921600 monitor_speed = 115200 @@ -116,6 +118,7 @@ lib_deps = ClosedCube HDC1080 Adafruit AHTX0 LiquidCrystal_I2C + BH1750 monitor_filters = esp32_exception_decoder upload_speed = 921600 monitor_speed = 115200 diff --git a/src/YourSensor.cpp b/src/YourSensor.cpp index 86ab858e..ef4ce987 100644 --- a/src/YourSensor.cpp +++ b/src/YourSensor.cpp @@ -5,10 +5,11 @@ #include "Utils/StringUtils.h" //подключаем необходимые файлы библиотеки -#include -#include - +//#include "Adafruit_ADS1X15.h" +#include "Adafruit_AHTX0.h" +#include "BH1750.h" #include "ClosedCube_HDC1080.h" +#include "LiquidCrystal_I2C.h" //создаем объект HDC1080 ClosedCube_HDC1080 hdc1080; @@ -21,13 +22,20 @@ sensors_event_t tmpEvent_t; //создаем объект LCD LiquidCrystal_I2C LCD(0x27, 16, 2); +//создаем объект BH1750 +BH1750 lightMeter; + +//создаем объект ADS1015 +//Adafruit_ADS1015 ads; + float yourSensorReading(String type, String paramsAny) { float value; //========================================================HDC1080================================================================ if (type == "HDC1080_temp") { HDC1080_init(jsonReadStr(paramsAny, "addr")); value = hdc1080.readTemperature(); - } else if (type == "HDC1080_hum") { + } + if (type == "HDC1080_hum") { HDC1080_init(jsonReadStr(paramsAny, "addr")); value = hdc1080.readHumidity(); } @@ -36,7 +44,8 @@ float yourSensorReading(String type, String paramsAny) { AHTX0_init(); aht_temp->getEvent(&tmpEvent_t); value = tmpEvent_t.temperature; - } else if (type == "AHTX0_hum") { + } + if (type == "AHTX0_hum") { AHTX0_init(); aht_humidity->getEvent(&tmpEvent_t); value = tmpEvent_t.relative_humidity; @@ -48,6 +57,12 @@ float yourSensorReading(String type, String paramsAny) { String toPrint = jsonReadStr(paramsAny, "descr") + " " + jsonReadStr(configLiveJson, jsonReadStr(paramsAny, "val")); LCD.print(toPrint); } + //==========================================================BH1750================================================================= + if (type == "BH1750_lux") { + BH1750_init(); + value = lightMeter.readLightLevel(); + } + return value; } @@ -82,3 +97,12 @@ void LCD_init() { LCD.backlight(); //включаем подсветку } } + +void BH1750_init() { + static bool BH1750_flag = true; + if (BH1750_flag) { + lightMeter.begin(); + + BH1750_flag = false; + } +} \ No newline at end of file