Calibrate distance calculation with temperature
This commit is contained in:
15
src/main.cpp
15
src/main.cpp
@@ -1,7 +1,7 @@
|
||||
#include <Homie.h>
|
||||
|
||||
#include "PingNode.hpp"
|
||||
#include "RelayNode.hpp"
|
||||
//#include "RelayNode.hpp"
|
||||
#include "DHT22Node.hpp"
|
||||
|
||||
#define TURN_ON LOW
|
||||
@@ -9,16 +9,19 @@
|
||||
|
||||
const int trigPin = D1;
|
||||
const int echoPin = D2;
|
||||
const int relayPin = 14; // D5
|
||||
const int relayPin = D5;
|
||||
const int dhtPin = D7; ;
|
||||
const int ledPin = LED_BUILTIN;
|
||||
|
||||
unsigned long HEARTBEAT_INTERVAL = 5;
|
||||
unsigned long lastHeartbeat = 0;
|
||||
unsigned long TEMPERATURE_INTERVAL = 120;
|
||||
unsigned long lastTemperatureUpdate = 0;
|
||||
|
||||
|
||||
PingNode obstacleNode("obstacle",trigPin,echoPin);
|
||||
DHT22Node airNode("air",dhtPin,20);
|
||||
RelayNode relayNode("relay",relayPin,ledPin);
|
||||
DHT22Node airNode("air",dhtPin,TEMPERATURE_INTERVAL);
|
||||
//RelayNode relayNode("relay",relayPin,ledPin);
|
||||
|
||||
void signal_led(bool on = true);
|
||||
void heartbeat_led(int times = 2);
|
||||
@@ -32,6 +35,10 @@ void loopHandler() {
|
||||
heartbeat_led();
|
||||
lastHeartbeat = millis();
|
||||
}
|
||||
if (millis() - lastTemperatureUpdate > TEMPERATURE_INTERVAL * 1000UL || lastTemperatureUpdate == 0) {
|
||||
obstacleNode.setTemperature(airNode.getTemperature());
|
||||
lastTemperatureUpdate = millis();
|
||||
}
|
||||
}
|
||||
|
||||
void setup() {
|
||||
|
||||
Reference in New Issue
Block a user