Advertisement
Guest User

Untitled

a guest
May 29th, 2015
286
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.99 KB | None | 0 0
  1.  
  2. #include "mbed.h"
  3.  
  4. PwmOut alarm(p21);
  5. DigitalOut led(LED1);
  6. AnalogIn door(p20);
  7. Timer timer1;
  8. InterruptIn switchEvent(p8);
  9. Serial pc(USBTX, USBRX);
  10.  
  11. int button=0;
  12.  
  13. void switchPressed()
  14. {
  15.     wait(0.05);
  16.     if(switchEvent==0)
  17.     {
  18.         button = 1;
  19.     }
  20. }
  21.  
  22. int main()
  23. {
  24.         alarm.period(0.010);
  25.         alarm = 0;
  26.         led = 1;
  27.         switchEvent.fall(switchPressed);
  28.  
  29.     while(1)
  30.     {
  31.         led = 1;
  32.  
  33.         if(door < 0.15 ) //door open
  34.         {
  35.             led = 0;
  36.             timer1.start();
  37.  
  38.             while(1)
  39.             {
  40.                 wait(0.1);
  41.  
  42.                 if(timer1.read() >= 5) // buzzer 10sec
  43.                 {
  44.                     alarm = 0.5;
  45.                 }
  46.  
  47.                 if((door > 0.15 && timer1.read() < 5) || button == 1) //door close
  48.                 {
  49.                     button = 0;
  50.                     alarm = 0;
  51.                     break;
  52.                 }
  53.  
  54.             }
  55.         }        
  56.     }
  57. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement