part of the pill dispenser project. Used to detect motion of pill passing through the channel. calls an interrupt when pill is detected.

Dependencies:   mbed

Fork of Seeed_Grove_PIR_Motion_Sensor_Example by Seeed

Committer:
khp007
Date:
Fri Mar 23 22:29:51 2018 +0000
Revision:
1:b962fe76b826
Parent:
0:cc930b964211
motion sensor to detect the pill passing through the channel..

Who changed what in which revision?

UserRevisionLine numberNew contents of line
sam_grove 0:cc930b964211 1
sam_grove 0:cc930b964211 2 #include "mbed.h"
khp007 1:b962fe76b826 3 Serial pc(USBTX, USBRX); // tx, rx
sam_grove 0:cc930b964211 4 InterruptIn motion(D2);
khp007 1:b962fe76b826 5 DigitalOut Green(LED2);
sam_grove 0:cc930b964211 6
sam_grove 0:cc930b964211 7 int motion_detected = 0;
sam_grove 0:cc930b964211 8
sam_grove 0:cc930b964211 9 void irq_handler(void)
sam_grove 0:cc930b964211 10 {
sam_grove 0:cc930b964211 11 motion_detected = 1;
sam_grove 0:cc930b964211 12 }
sam_grove 0:cc930b964211 13
sam_grove 0:cc930b964211 14 int main(void)
sam_grove 0:cc930b964211 15 {
sam_grove 0:cc930b964211 16 int cnt = 0;
khp007 1:b962fe76b826 17 motion.fall(&irq_handler);
khp007 1:b962fe76b826 18 Green=1;
sam_grove 0:cc930b964211 19
khp007 1:b962fe76b826 20 while(1)
khp007 1:b962fe76b826 21 {
khp007 1:b962fe76b826 22 if(motion_detected)
khp007 1:b962fe76b826 23 {
sam_grove 0:cc930b964211 24 cnt++;
sam_grove 0:cc930b964211 25 motion_detected = 0;
khp007 1:b962fe76b826 26 pc.printf("Hello! I've detected %d times since reset\r\n", cnt);
khp007 1:b962fe76b826 27 Green=0;
khp007 1:b962fe76b826 28 wait(.2);
khp007 1:b962fe76b826 29 Green=1;
khp007 1:b962fe76b826 30 wait(1);
khp007 1:b962fe76b826 31 } else{
khp007 1:b962fe76b826 32 pc.printf("did not detect\r\n");
sam_grove 0:cc930b964211 33 }
sam_grove 0:cc930b964211 34 }
khp007 1:b962fe76b826 35
sam_grove 0:cc930b964211 36 }