Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "mbed.h"
- PwmOut alarm(p21);
- DigitalOut led(LED1);
- AnalogIn door(p20);
- Timer timer1;
- InterruptIn switchEvent(p8);
- Serial pc(USBTX, USBRX);
- int button=0;
- void switchPressed()
- {
- wait(0.05);
- if(switchEvent==0)
- {
- button = 1;
- }
- }
- int main()
- {
- alarm.period(0.010);
- alarm = 0;
- led = 1;
- switchEvent.fall(switchPressed);
- while(1)
- {
- led = 1;
- if(door < 0.15 ) //door open
- {
- led = 0;
- timer1.start();
- while(1)
- {
- wait(0.1);
- if(timer1.read() >= 5) // buzzer 10sec
- {
- alarm = 0.5;
- }
- if((door > 0.15 && timer1.read() < 5) || button == 1) //door close
- {
- button = 0;
- alarm = 0;
- break;
- }
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement