Advertisement
RuiViana

JB_Ver01

Jun 26th, 2016
276
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.95 KB | None | 0 0
  1. #include "TimerOne.h"
  2. volatile unsigned int tempo = 1;
  3. volatile unsigned int tempo2 = 1;
  4. unsigned int Duracao1 = 3;                // pretendo 60, mas para testar e nao esperar muito pus 3
  5. unsigned int Duracao2 = 5;                // pretendo 60, mas para testar e nao esperar muito pus 5
  6. //---------------------------------
  7. void setup()
  8. {
  9.   pinMode(13, OUTPUT);
  10.   digitalWrite(13, LOW);
  11.   Timer1.initialize(1000000);         // initialize timer1, and set a 1 second period
  12.   Timer1.attachInterrupt(callback);  // attaches callback() as a timer overflow interrupt
  13. }
  14. //--------------------------------------
  15. void callback()
  16. {
  17.   tempo++;
  18.   tempo2++;
  19. }
  20. //--------------------------------------
  21. void loop()
  22. {
  23.   if (tempo <= Duracao1)              
  24.   {
  25.     digitalWrite(13, HIGH);
  26.     tempo2 = 0;
  27.   }
  28.   else
  29.   {
  30.     if (tempo2 <= Duracao2)        
  31.     {
  32.       digitalWrite(13, LOW);
  33.     }
  34.     if (tempo2 > Duracao2)
  35.       tempo = 0;
  36.   }
  37. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement