добавил BH1750

This commit is contained in:
Dmitry Borisenko
2021-12-19 22:52:26 +01:00
parent fd09ec9d6b
commit e9032365b4
3 changed files with 33 additions and 5 deletions

View File

@@ -6,3 +6,4 @@ float yourSensorReading(String type, String addr);
void HDC1080_init(String addr); void HDC1080_init(String addr);
void AHTX0_init(); void AHTX0_init();
void LCD_init(); void LCD_init();
void BH1750_init();

View File

@@ -44,6 +44,7 @@ lib_deps =
ClosedCube HDC1080 ClosedCube HDC1080
Adafruit AHTX0 Adafruit AHTX0
LiquidCrystal_I2C LiquidCrystal_I2C
BH1750
monitor_filters = esp8266_exception_decoder monitor_filters = esp8266_exception_decoder
upload_speed = 921600 upload_speed = 921600
monitor_speed = 115200 monitor_speed = 115200
@@ -71,6 +72,7 @@ lib_deps =
ClosedCube HDC1080 ClosedCube HDC1080
Adafruit AHTX0 Adafruit AHTX0
LiquidCrystal_I2C LiquidCrystal_I2C
BH1750
monitor_filters = esp8266_exception_decoder monitor_filters = esp8266_exception_decoder
upload_speed = 921600 upload_speed = 921600
monitor_speed = 115200 monitor_speed = 115200
@@ -116,6 +118,7 @@ lib_deps =
ClosedCube HDC1080 ClosedCube HDC1080
Adafruit AHTX0 Adafruit AHTX0
LiquidCrystal_I2C LiquidCrystal_I2C
BH1750
monitor_filters = esp32_exception_decoder monitor_filters = esp32_exception_decoder
upload_speed = 921600 upload_speed = 921600
monitor_speed = 115200 monitor_speed = 115200

View File

@@ -5,10 +5,11 @@
#include "Utils/StringUtils.h" #include "Utils/StringUtils.h"
//подключаем необходимые файлы библиотеки //подключаем необходимые файлы библиотеки
#include <Adafruit_AHTX0.h> //#include "Adafruit_ADS1X15.h"
#include <LiquidCrystal_I2C.h> #include "Adafruit_AHTX0.h"
#include "BH1750.h"
#include "ClosedCube_HDC1080.h" #include "ClosedCube_HDC1080.h"
#include "LiquidCrystal_I2C.h"
//создаем объект HDC1080 //создаем объект HDC1080
ClosedCube_HDC1080 hdc1080; ClosedCube_HDC1080 hdc1080;
@@ -21,13 +22,20 @@ sensors_event_t tmpEvent_t;
//создаем объект LCD //создаем объект LCD
LiquidCrystal_I2C LCD(0x27, 16, 2); LiquidCrystal_I2C LCD(0x27, 16, 2);
//создаем объект BH1750
BH1750 lightMeter;
//создаем объект ADS1015
//Adafruit_ADS1015 ads;
float yourSensorReading(String type, String paramsAny) { float yourSensorReading(String type, String paramsAny) {
float value; float value;
//========================================================HDC1080================================================================ //========================================================HDC1080================================================================
if (type == "HDC1080_temp") { if (type == "HDC1080_temp") {
HDC1080_init(jsonReadStr(paramsAny, "addr")); HDC1080_init(jsonReadStr(paramsAny, "addr"));
value = hdc1080.readTemperature(); value = hdc1080.readTemperature();
} else if (type == "HDC1080_hum") { }
if (type == "HDC1080_hum") {
HDC1080_init(jsonReadStr(paramsAny, "addr")); HDC1080_init(jsonReadStr(paramsAny, "addr"));
value = hdc1080.readHumidity(); value = hdc1080.readHumidity();
} }
@@ -36,7 +44,8 @@ float yourSensorReading(String type, String paramsAny) {
AHTX0_init(); AHTX0_init();
aht_temp->getEvent(&tmpEvent_t); aht_temp->getEvent(&tmpEvent_t);
value = tmpEvent_t.temperature; value = tmpEvent_t.temperature;
} else if (type == "AHTX0_hum") { }
if (type == "AHTX0_hum") {
AHTX0_init(); AHTX0_init();
aht_humidity->getEvent(&tmpEvent_t); aht_humidity->getEvent(&tmpEvent_t);
value = tmpEvent_t.relative_humidity; 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")); String toPrint = jsonReadStr(paramsAny, "descr") + " " + jsonReadStr(configLiveJson, jsonReadStr(paramsAny, "val"));
LCD.print(toPrint); LCD.print(toPrint);
} }
//==========================================================BH1750=================================================================
if (type == "BH1750_lux") {
BH1750_init();
value = lightMeter.readLightLevel();
}
return value; return value;
} }
@@ -82,3 +97,12 @@ void LCD_init() {
LCD.backlight(); //включаем подсветку LCD.backlight(); //включаем подсветку
} }
} }
void BH1750_init() {
static bool BH1750_flag = true;
if (BH1750_flag) {
lightMeter.begin();
BH1750_flag = false;
}
}