bambangSud

Cuplikan sketch pake timer

Aug 16th, 2013
194
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.75 KB | None | 0 0
  1. void timerIsr() // interupt timernya
  2. {
  3. // Toggle LED
  4. second++;
  5. //Serial.print(second);
  6. if(second==60)
  7. {
  8. second=0;
  9. minute++;
  10. }
  11.  
  12. if(minute==60)
  13. {
  14. minute=0;
  15. hour++;
  16. }
  17.  
  18. if(hour==24)
  19. {
  20. hour=0;
  21. }
  22. }
  23.  
  24.  
  25. void setup(){
  26. Timer1.initialize(100000); // set a timer of length 100000 microseconds (or 0.1 sec - or 10Hz => the led will blink 5 times, 5 cycles of on-and-off, per second)
  27. Timer1.attachInterrupt( timerIsr ); // attach the service routine here
  28. ............
  29. ............
  30.  
  31. }
  32.  
  33. void loop()
  34. {
  35. sprintf(buf, "@twistedclever coba kirim tweet# %2d%02d%02d",hour,minute,second);
  36.  
  37. sendTweet(buf);
  38. delay(1000);
  39.  
  40.  
  41. }
Advertisement
Add Comment
Please, Sign In to add comment