ziad eldebri
/
pir_sensor
Expo2017_example
main.cpp@0:493a823a2708, 2017-05-14 (annotated)
- Committer:
- ziadeldebri
- Date:
- Sun May 14 20:14:10 2017 +0000
- Revision:
- 0:493a823a2708
Expo2017;
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
ziadeldebri | 0:493a823a2708 | 1 | #include "mbed.h" |
ziadeldebri | 0:493a823a2708 | 2 | |
ziadeldebri | 0:493a823a2708 | 3 | DigitalOut led1(LED2); |
ziadeldebri | 0:493a823a2708 | 4 | DigitalIn alarm(PTB0, PullNone); //internal pull up |
ziadeldebri | 0:493a823a2708 | 5 | PwmOut buzzer(PTE31); |
ziadeldebri | 0:493a823a2708 | 6 | |
ziadeldebri | 0:493a823a2708 | 7 | |
ziadeldebri | 0:493a823a2708 | 8 | float freq[] = {659,554,659,554,440,494,554,587,494,659,554,400}; |
ziadeldebri | 0:493a823a2708 | 9 | float beat[] = {1,1,1,1,1,0.5,0.5,1,1,1,1,2}; |
ziadeldebri | 0:493a823a2708 | 10 | |
ziadeldebri | 0:493a823a2708 | 11 | int main() { |
ziadeldebri | 0:493a823a2708 | 12 | wait(2); //Wait for sensor to take snap shot of still room |
ziadeldebri | 0:493a823a2708 | 13 | |
ziadeldebri | 0:493a823a2708 | 14 | while(1) { |
ziadeldebri | 0:493a823a2708 | 15 | if (alarm){ |
ziadeldebri | 0:493a823a2708 | 16 | led1=0; |
ziadeldebri | 0:493a823a2708 | 17 | for(int i = 0 ; i <= 4; i++){ |
ziadeldebri | 0:493a823a2708 | 18 | buzzer.period(1/(2*freq[i])); |
ziadeldebri | 0:493a823a2708 | 19 | buzzer = 0.5; |
ziadeldebri | 0:493a823a2708 | 20 | wait(0.4*beat[i]); |
ziadeldebri | 0:493a823a2708 | 21 | } |
ziadeldebri | 0:493a823a2708 | 22 | } |
ziadeldebri | 0:493a823a2708 | 23 | else { |
ziadeldebri | 0:493a823a2708 | 24 | led1=1; |
ziadeldebri | 0:493a823a2708 | 25 | buzzer = 0; |
ziadeldebri | 0:493a823a2708 | 26 | } |
ziadeldebri | 0:493a823a2708 | 27 | wait(1); |
ziadeldebri | 0:493a823a2708 | 28 | } |
ziadeldebri | 0:493a823a2708 | 29 | |
ziadeldebri | 0:493a823a2708 | 30 | } |