Advertisement
RuiViana

Meu relógio

Jun 1st, 2016
244
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.40 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. unsigned long valor = 0;
  10. #include <LiquidCrystal.h>
  11.  
  12. LiquidCrystal lcd(6, 7, 4, 5, 2, 3); //Configura os pinos do Arduino para se comunicar com o LCD
  13. //---------------------------------
  14. void setup()
  15. {
  16. lcd.begin(16,2);
  17. Serial.begin(9600);
  18. pinMode(13, OUTPUT);
  19. Timer1.initialize(1000000); // initialize timer1, and set a 1/2 second period
  20. Timer1.attachInterrupt(callback); // attaches callback() as a timer overflow interrupt
  21. }
  22. //--------------------------------------
  23. void callback()
  24. {
  25. digitalWrite(13, digitalRead(13) ^ 1);
  26. tempo++;
  27. if (tempo >= 86400) tempo = 0;
  28. }
  29. //--------------------------------------
  30. void loop()
  31. {
  32. if (Serial.available() > 0)
  33. {
  34. valor = Serial.parseInt();
  35. tempo = tempo + valor;
  36. }
  37. hora = tempo / 3600;
  38. hora1 = hora * 3600;
  39. minu1 = tempo - hora1;
  40. minu = minu1/60;
  41. segu1 = minu*60 + hora1;
  42. segu = tempo - segu1;
  43.  
  44. lcd.setCursor(1,0);
  45. if (hora < 10)
  46. lcd.print("0");
  47. lcd.print(hora);
  48. lcd.print(":");
  49. if (minu < 10)
  50. lcd.print("0");
  51. lcd.print(minu);
  52. lcd.print(":");
  53. if (segu < 10)
  54. lcd.print("0");
  55. lcd.print(segu);
  56. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement