Advertisement
RuiViana

Contador de segundos

May 30th, 2016
394
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.93 KB | None | 0 0
  1. #include "TimerOne.h"
  2. byte hora = 0;
  3. int hora1 = 0;
  4. byte minu = 0;
  5. int minu1 = 0;
  6. byte segu = 0;
  7. int segu1 = 0;
  8. unsigned long tempo = 0;
  9.  
  10. //---------------------------------
  11. void setup()
  12. {
  13. Serial.begin(9600);
  14. pinMode(13, OUTPUT);
  15. Timer1.initialize(1000000); // initialize timer1, and set a 1 second period
  16. Timer1.attachInterrupt(callback); // attaches callback() as a timer overflow interrupt
  17. }
  18. //--------------------------------------
  19. void callback()
  20. {
  21. digitalWrite(13, digitalRead(13) ^ 1);
  22. tempo++;
  23. }
  24. //--------------------------------------
  25. void loop()
  26. {
  27. hora = tempo / 3600;
  28. hora1 = hora * 3600;
  29. minu1 = tempo - hora1;
  30. minu = minu1/60;
  31. segu1 = minu*60 + hora1;
  32. segu = tempo - segu1;
  33. Serial.print(hora);
  34. Serial.print(":");
  35. Serial.print(minu);
  36. Serial.print(":");
  37. Serial.println(segu);
  38. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement