part of the pill dispenser project. Used to detect motion of pill passing through the channel. calls an interrupt when pill is detected.
Fork of Seeed_Grove_PIR_Motion_Sensor_Example by
Revision 1:b962fe76b826, committed 2018-03-23
- Comitter:
- khp007
- Date:
- Fri Mar 23 22:29:51 2018 +0000
- Parent:
- 0:cc930b964211
- Commit message:
- motion sensor to detect the pill passing through the channel..
Changed in this revision
main.cpp | Show annotated file Show diff for this revision Revisions of this file |
diff -r cc930b964211 -r b962fe76b826 main.cpp --- a/main.cpp Fri Aug 15 23:18:16 2014 +0000 +++ b/main.cpp Fri Mar 23 22:29:51 2018 +0000 @@ -1,7 +1,8 @@ #include "mbed.h" - +Serial pc(USBTX, USBRX); // tx, rx InterruptIn motion(D2); +DigitalOut Green(LED2); int motion_detected = 0; @@ -13,13 +14,23 @@ int main(void) { int cnt = 0; - motion.rise(&irq_handler); + motion.fall(&irq_handler); + Green=1; - while(1) { - if(motion_detected) { + while(1) + { + if(motion_detected) + { 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); + Green=0; + wait(.2); + Green=1; + wait(1); + } else{ + pc.printf("did not detect\r\n"); } } + }