Calculate median value of pings
This commit is contained in:
@@ -39,7 +39,13 @@
|
|||||||
#include <NewPing.h>
|
#include <NewPing.h>
|
||||||
|
|
||||||
#ifdef SEND_STATUS_TO_CONTROLLER
|
#ifdef SEND_STATUS_TO_CONTROLLER
|
||||||
#include <SPI.h>
|
// Enable debug prints to serial monitor
|
||||||
|
#define MY_DEBUG
|
||||||
|
|
||||||
|
// Enable and select radio type attached
|
||||||
|
#define MY_RADIO_NRF24
|
||||||
|
//#define MY_RADIO_RFM69
|
||||||
|
|
||||||
#include <MySensor.h>
|
#include <MySensor.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
@@ -67,7 +73,6 @@ NewPing sonar(TRIGGER_PIN, ECHO_PIN, MAX_DISTANCE); // NewPing setup of pins and
|
|||||||
|
|
||||||
#ifdef SEND_STATUS_TO_CONTROLLER
|
#ifdef SEND_STATUS_TO_CONTROLLER
|
||||||
#define CHILD_ID 1
|
#define CHILD_ID 1
|
||||||
MySensor gw;
|
|
||||||
MyMessage msg(CHILD_ID,V_TRIPPED);
|
MyMessage msg(CHILD_ID,V_TRIPPED);
|
||||||
#endif
|
#endif
|
||||||
unsigned long sendInterval = 5000; // Send park status at maximum every 5 second.
|
unsigned long sendInterval = 5000; // Send park status at maximum every 5 second.
|
||||||
@@ -91,16 +96,15 @@ void setup() {
|
|||||||
pixels.begin(); // This initializes the NeoPixel library.
|
pixels.begin(); // This initializes the NeoPixel library.
|
||||||
Serial.println("Neopixels initialized");
|
Serial.println("Neopixels initialized");
|
||||||
#ifdef SEND_STATUS_TO_CONTROLLER
|
#ifdef SEND_STATUS_TO_CONTROLLER
|
||||||
gw.begin();
|
sendSketchInfo("Parking Sensor", "1.0");
|
||||||
gw.sendSketchInfo("Parking Sensor", "1.0");
|
present(CHILD_ID, S_DOOR, "Parking Status");
|
||||||
gw.present(CHILD_ID, S_DOOR, "Parking Status");
|
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
void loop() {
|
void loop() {
|
||||||
unsigned long now = millis();
|
unsigned long now = millis();
|
||||||
|
|
||||||
int fullDist = sonar.ping_cm();
|
unsigned int fullDist = (sonar.ping_median() / US_ROUNDTRIP_CM);
|
||||||
// Serial.println(fullDist);
|
// Serial.println(fullDist);
|
||||||
int displayDist = min(fullDist, MAX_DISTANCE);
|
int displayDist = min(fullDist, MAX_DISTANCE);
|
||||||
if (displayDist == 0 && skipZero<10) {
|
if (displayDist == 0 && skipZero<10) {
|
||||||
@@ -120,7 +124,7 @@ void loop() {
|
|||||||
else
|
else
|
||||||
Serial.println("Car Gone");
|
Serial.println("Car Gone");
|
||||||
#ifdef SEND_STATUS_TO_CONTROLLER
|
#ifdef SEND_STATUS_TO_CONTROLLER
|
||||||
gw.send(msg.set(parked));
|
send(msg.set(parked));
|
||||||
#endif
|
#endif
|
||||||
oldParkedStatus = parked;
|
oldParkedStatus = parked;
|
||||||
lastSend = now;
|
lastSend = now;
|
||||||
|
|||||||
Reference in New Issue
Block a user