Freedom Seeed PIR Sensor Example

Dependencies:   mbed

Fork of frdm_Grove_PIR_Example by Freescale

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers main.cpp Source File

main.cpp

00001 
00002 #include "mbed.h"
00003 
00004 InterruptIn motion(D2);
00005 
00006 int motion_detected = 0;
00007 
00008 void irq_handler(void)
00009 {
00010     motion_detected = 1;
00011 }
00012     
00013 int main(void)
00014 {
00015     int cnt = 0;
00016     motion.rise(&irq_handler);
00017     
00018     while(1) {
00019         if(motion_detected) {
00020             cnt++;
00021             motion_detected = 0;
00022             printf("Hello! I've detected %d times since reset\n", cnt);
00023         }
00024     }
00025 }