PIR SENSOR HCSR501

Dependencies:   mbed

Revision:
0:820c81f96055
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/SensorPIR.cpp	Tue Dec 01 23:45:42 2015 +0000
@@ -0,0 +1,52 @@
+#include "SensorPIR.h"
+
+/*Defines*/
+Serial UARTPIR(USBTX, USBRX);
+DigitalOut dout(LED1);
+DigitalIn enable1(D0);
+//DigitalIn enable2(D1);
+//DigitalIn enable3(D2);
+//DigitalIn enable4(D3);
+
+/*Functions*/
+int GetPersonStatus(int RoomPrescence) {
+    bool print = 0;
+    bool RoomStatus = 0;   
+    UARTPIR.baud(115200);
+    wait(2); //Wait for sensor to take snap shot of still room
+    
+    switch(RoomPrescence)
+    {
+      case 1:
+            if(enable1==1 /*|| enable2==1 || enable3==1 || enable4==1*/)
+            {
+                RoomStatus = 1;
+                dout=1;
+                if(print == 0)
+                {
+                    UARTPIR.printf("Presencia detectada\n\r");
+                    print = 1;
+                }
+            }
+            else
+            {
+                RoomStatus = 0;
+                dout=0;
+                if(print == 1)
+                {
+                    UARTPIR.printf("Ninguna presencia detectada\n\r");
+                    print = 0;
+                }
+            }
+            break;
+            
+        case 2:
+        /*ADD NEW ROOM*/
+            break;
+            
+        default:
+        /*Do Nothing*/
+            break;
+    }
+    return RoomStatus;
+}