motion sensor is used to detect the any object
Fork of HelloWorld by
main.cpp@2:e78cebb5a0d5, 2016-12-01 (annotated)
- Committer:
- sumanshavi
- Date:
- Thu Dec 01 10:39:34 2016 +0000
- Revision:
- 2:e78cebb5a0d5
- Parent:
- 0:fb6bbc10ffa0
- Child:
- 3:085dbf0f0726
motionsensor
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
sumanshavi | 2:e78cebb5a0d5 | 1 | |
simon | 0:fb6bbc10ffa0 | 2 | #include "mbed.h" |
sumanshavi | 2:e78cebb5a0d5 | 3 | |
sumanshavi | 2:e78cebb5a0d5 | 4 | DigitalOut buzzer(p19); |
simon | 0:fb6bbc10ffa0 | 5 | |
sumanshavi | 2:e78cebb5a0d5 | 6 | DigitalIn motion(p29); |
sumanshavi | 2:e78cebb5a0d5 | 7 | int main() { |
sumanshavi | 2:e78cebb5a0d5 | 8 | |
sumanshavi | 2:e78cebb5a0d5 | 9 | wait(2); //Wait for sensor to take snap shot of still room |
sumanshavi | 2:e78cebb5a0d5 | 10 | |
simon | 0:fb6bbc10ffa0 | 11 | while(1) { |
sumanshavi | 2:e78cebb5a0d5 | 12 | if (motion==0){ |
sumanshavi | 2:e78cebb5a0d5 | 13 | buzzer=1; |
sumanshavi | 2:e78cebb5a0d5 | 14 | wait(2); |
sumanshavi | 2:e78cebb5a0d5 | 15 | } |
sumanshavi | 2:e78cebb5a0d5 | 16 | else |
sumanshavi | 2:e78cebb5a0d5 | 17 | buzzer=0; |
sumanshavi | 2:e78cebb5a0d5 | 18 | |
simon | 0:fb6bbc10ffa0 | 19 | } |
sumanshavi | 2:e78cebb5a0d5 | 20 | } |