pir sensor from digital pin

Dependents:   Mytemperature_Motion Garage_Control

Files at this revision

API Documentation at this revision

Comitter:
sharifdeens
Date:
Sun Apr 21 03:29:19 2019 +0000
Commit message:
Pirsensor

Changed in this revision

Pir_sensor.h Show annotated file Show diff for this revision Revisions of this file
diff -r 000000000000 -r f2af0cabf955 Pir_sensor.h
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Pir_sensor.h	Sun Apr 21 03:29:19 2019 +0000
@@ -0,0 +1,33 @@
+#include "mbed.h"
+ 
+//Setup a new class for TMP36 sensor
+class Pir_sensor
+{
+public:
+    Pir_sensor(PinName pin1);
+    Pir_sensor();
+    operator int ();
+    int read();
+private:
+//class sets up the AnalogIn pin
+    DigitalIn _pin1;
+};
+ 
+Pir_sensor::Pir_sensor(PinName pin1) : _pin1(pin1)
+{
+// _pin(pin) means pass pin to the AnalogIn constructor
+}
+ 
+int Pir_sensor::read()
+{
+//convert sensor reading to temperature in degrees C
+    return _pin1.read();
+  //    return 1;
+}
+//overload of float conversion (avoids needing to type .read() in equations)
+Pir_sensor::operator int ()
+{
+//convert sensor reading to temperature in degrees C
+    return _pin1.read();
+   //    return 1;
+}
\ No newline at end of file