96 lines
2.1 KiB
C++
96 lines
2.1 KiB
C++
#include <Wire.h>
|
|
#include <ArduinoJson.h>
|
|
#include <TEWeatherShield.h>
|
|
#include <LiquidCrystal_I2C.h>
|
|
|
|
LiquidCrystal_I2C lcd(0x27, 16, 2);
|
|
static TEWeatherShield weatherShield;
|
|
|
|
void setup() {
|
|
Serial.begin(9600);
|
|
weatherShield.begin();
|
|
|
|
lcd.init();
|
|
lcd.backlight();
|
|
lcd.println("Vremenska postaja");
|
|
lcd.clear();
|
|
}
|
|
|
|
void printLCD(float temperature, float humidity, float pressure) {
|
|
lcd.clear();
|
|
|
|
String temp = "T: " + (String)temperature + " C";
|
|
lcd.setCursor(2, 0);
|
|
lcd.print(temp);
|
|
|
|
String hum = "H: " + (String)humidity + " %RH";
|
|
lcd.setCursor(2, 1);
|
|
lcd.print(hum);
|
|
|
|
delay(10000);
|
|
|
|
String pres = "P: " + (String)pressure + " hPa";
|
|
lcd.setCursor(2, 1);
|
|
lcd.print(pres);
|
|
}
|
|
|
|
float measure_htu21d(int data) {
|
|
float temperature;
|
|
float humidity;
|
|
|
|
weatherShield.selectHTU21D();
|
|
|
|
if (weatherShield.HTU21D.is_connected()) {
|
|
weatherShield.HTU21D.set_i2c_master_mode(htu21_i2c_no_hold);
|
|
weatherShield.HTU21D.read_temperature_and_relative_humidity(&temperature, &humidity);
|
|
|
|
if (data == 0) {
|
|
return temperature;
|
|
} else {
|
|
return humidity;
|
|
}
|
|
}
|
|
else {
|
|
lcd.setCursor(2, 0);
|
|
lcd.print("Napaka senzorja 1!");
|
|
}
|
|
}
|
|
|
|
float measure_ms5637(int data) {
|
|
float temperature;
|
|
float pressure;
|
|
|
|
weatherShield.selectMS5637();
|
|
|
|
if (weatherShield.MS5637.is_connected()) {
|
|
weatherShield.MS5637.read_temperature_and_pressure(&temperature, &pressure);
|
|
|
|
if (data == 0) {
|
|
return temperature;
|
|
} else {
|
|
return pressure;
|
|
}
|
|
}
|
|
else {
|
|
lcd.setCursor(2, 0);
|
|
lcd.print("Napaka senzorja 2!"); }
|
|
}
|
|
|
|
void loop() {
|
|
StaticJsonDocument<100> jsonBuffer;
|
|
|
|
float temperature = measure_ms5637(0);
|
|
float pressure = measure_ms5637(1);
|
|
float humidity = measure_htu21d(1);
|
|
|
|
printLCD(temperature, humidity, pressure);
|
|
|
|
jsonBuffer["temperature"] = temperature;
|
|
jsonBuffer["humidity"] = humidity;
|
|
jsonBuffer["pressure"] = pressure;
|
|
|
|
serializeJson(jsonBuffer, Serial);
|
|
Serial.println();
|
|
|
|
delay(2000);
|
|
} |