Example using a PIR sensor

Dependencies:   EthernetInterface mbed-rtos mbed

Fork of Seeed_Grove_PIR_Motion_Sensor_Example by Seeed

Revision:
1:9f54cd329503
Parent:
0:cc930b964211
--- a/main.cpp	Fri Aug 15 23:18:16 2014 +0000
+++ b/main.cpp	Wed Mar 04 15:35:17 2015 +0000
@@ -1,25 +1,38 @@
-
 #include "mbed.h"
 
 InterruptIn motion(D2);
+DigitalOut gLed(LED2);
+Serial pc(USBTX, USBRX);
 
 int motion_detected = 0;
+float blinkTime = .2;
 
 void irq_handler(void)
 {
     motion_detected = 1;
 }
-    
+
+void BlinkGreen(){
+            gLed = 0;  // turn myled on
+            pc.printf("LED Green \r\n");
+            wait(blinkTime);
+            gLed = 1;  // turn myled off
+            wait(blinkTime);
+}
 int main(void)
 {
+    pc.baud(115200);
     int cnt = 0;
+    gLed = 1;
     motion.rise(&irq_handler);
-    
+
     while(1) {
         if(motion_detected) {
+            BlinkGreen();
             cnt++;
             motion_detected = 0;
-            printf("Hello! I've detected %d times since reset\n", cnt);
+            pc.printf("Hello! I've detected %d times since reset\r\n", cnt);
         }
     }
 }
+