Frank Girald
/
CNY_timer
Sensores
Diff: main.cpp
- Revision:
- 0:03d37798399d
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/main.cpp Wed Nov 29 21:14:19 2017 +0000 @@ -0,0 +1,44 @@ +#include "mbed.h" + +DigitalOut led_alarm(LED1); +Timer Timer2; +InterruptIn s0(PTD2); +InterruptIn s1(PTD4); + +bool flag_alarm,time_max; + +void ISR_S0() +{ + time_max=0; + Timer2.start(); + flag_alarm=0; +} + +void ISR_S1() +{ + time_max=1; + Timer2.stop(); + flag_alarm=1; +} + +int main() +{ + s0.mode(PullUp); + s0.rise(&ISR_S0); + s1.mode(PullUp); + s1.rise(&ISR_S1); + flag_alarm=1; + time_max=0; + while(1) { + if(flag_alarm==0) { + if(Timer2.read_ms()>=3000) { + if(time_max==0) { + led_alarm=1; + Timer2.stop(); + flag_alarm=1; + time_max=0; + } + } + } + } +}