Browse Source

Add "calibration" for PIR at startup

Robert Marshall 5 years ago
parent
commit
728b0ba3b2
2 changed files with 12 additions and 0 deletions
  1. 11 0
      Transmitter/src/PIR.cpp
  2. 1 0
      Transmitter/src/main.cpp

+ 11 - 0
Transmitter/src/PIR.cpp

@@ -1,5 +1,7 @@
 #include <Arduino.h>
 
+#define CALIBRATION_DURATION 30 //seconds
+
 class PIR{
 	unsigned int _pin;
 	unsigned long _triggerDuration, _motionDetectedTime;
@@ -13,8 +15,17 @@ public:
 		_triggerDuration = triggerDuration;
 		_startCallback = startCallback;
 		_stopCallback = stopCallback;
+	}
 
+	void setup() {
+		Serial.print("Starting PIR sensor");
 		pinMode(_pin, INPUT);
+		digitalWrite(_pin, LOW);
+		for (int i=0; i<CALIBRATION_DURATION; i++){
+			Serial.print(".");
+			delay(1000); // 30 second "calibration" time
+		}
+		Serial.println("done");
 	}
 
 	void loop(){

+ 1 - 0
Transmitter/src/main.cpp

@@ -42,6 +42,7 @@ void setup() {
 	Serial.begin(9600);
 	Serial.println("Starting");
 	_transmitter.setup();
+	_pir.setup();
 	Serial.println("Started");
 }