Calculate median value of pings
This commit is contained in:
@@ -39,7 +39,13 @@
|
||||
#include <NewPing.h>
|
||||
|
||||
#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>
|
||||
#endif
|
||||
|
||||
@@ -67,7 +73,6 @@ NewPing sonar(TRIGGER_PIN, ECHO_PIN, MAX_DISTANCE); // NewPing setup of pins and
|
||||
|
||||
#ifdef SEND_STATUS_TO_CONTROLLER
|
||||
#define CHILD_ID 1
|
||||
MySensor gw;
|
||||
MyMessage msg(CHILD_ID,V_TRIPPED);
|
||||
#endif
|
||||
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.
|
||||
Serial.println("Neopixels initialized");
|
||||
#ifdef SEND_STATUS_TO_CONTROLLER
|
||||
gw.begin();
|
||||
gw.sendSketchInfo("Parking Sensor", "1.0");
|
||||
gw.present(CHILD_ID, S_DOOR, "Parking Status");
|
||||
sendSketchInfo("Parking Sensor", "1.0");
|
||||
present(CHILD_ID, S_DOOR, "Parking Status");
|
||||
#endif
|
||||
}
|
||||
|
||||
void loop() {
|
||||
unsigned long now = millis();
|
||||
|
||||
int fullDist = sonar.ping_cm();
|
||||
unsigned int fullDist = (sonar.ping_median() / US_ROUNDTRIP_CM);
|
||||
// Serial.println(fullDist);
|
||||
int displayDist = min(fullDist, MAX_DISTANCE);
|
||||
if (displayDist == 0 && skipZero<10) {
|
||||
@@ -120,7 +124,7 @@ void loop() {
|
||||
else
|
||||
Serial.println("Car Gone");
|
||||
#ifdef SEND_STATUS_TO_CONTROLLER
|
||||
gw.send(msg.set(parked));
|
||||
send(msg.set(parked));
|
||||
#endif
|
||||
oldParkedStatus = parked;
|
||||
lastSend = now;
|
||||
|
||||
Reference in New Issue
Block a user