PIR SENSOR HCSR501

Dependencies:   mbed

Files at this revision

API Documentation at this revision

Comitter:
Jorge_Beltran
Date:
Tue Dec 01 23:45:42 2015 +0000
Commit message:
PIR Sensor HCSR 501

Changed in this revision

SensorPIR.cpp Show annotated file Show diff for this revision Revisions of this file
SensorPIR.h Show annotated file Show diff for this revision Revisions of this file
main.cpp Show annotated file Show diff for this revision Revisions of this file
mbed.bld Show annotated file Show diff for this revision Revisions of this file
--- /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;
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/SensorPIR.h	Tue Dec 01 23:45:42 2015 +0000
@@ -0,0 +1,8 @@
+#include "mbed.h"
+
+/*Extern Defines*/
+
+/*Extern Variables*/
+
+/*Extern Functions*/
+extern int GetPersonStatus(int RoomPrescence);
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp	Tue Dec 01 23:45:42 2015 +0000
@@ -0,0 +1,9 @@
+#include "mbed.h"
+#include "SensorPIR.h"
+ 
+int main() {
+    while(1)
+    {
+        GetPersonStatus(1);
+    }
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mbed.bld	Tue Dec 01 23:45:42 2015 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/mbed_official/code/mbed/builds/9296ab0bfc11
\ No newline at end of file