Advertisement
MrLunk

17 LED Binary Clock 24h with Seconds - Arduino no time sync

Jan 4th, 2018
362
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 2.09 KB | None | 0 0
  1. // Arduino 24h Binary Clock with Seconds. (17 LEDs total)
  2. // You can find a demonstration video of this project
  3. // here on Youtube: https://www.youtube.com/watch?v=R1rWMhTKyh0
  4. // Greetings, www.MrLunk.net
  5.  
  6. // pins 2 - 13 are the regular digital pwm pins.
  7. int ledPinsSec[] = {2, 3, 4, 5, 6, 7};
  8. int ledPinsMin[] = {8, 9, 10, 11, 12, 13};
  9.  
  10. // pins 14 - 20 are the analog pins 0 - 5 used as digital pwm pins  
  11. int ledPinsHr[] = {14, 15, 16, 17, 18, 19};
  12.  
  13. // set Start time
  14. int countS = 0;   // Seconds
  15. int countM = 13;  // Minutes
  16. int countH = 23;  // Hours
  17.  
  18. byte countSec;
  19. byte countMin;
  20. byte countHr;
  21. #define nBitsSec sizeof(ledPinsSec)/sizeof(ledPinsSec[0])
  22. #define nBitsMin sizeof(ledPinsMin)/sizeof(ledPinsMin[0])
  23. #define nBitsHr sizeof(ledPinsHr)/sizeof(ledPinsHr[0])
  24.  
  25. void setup(void)
  26. {
  27.   for (byte i = 0; i < nBitsSec; i++) {
  28.     pinMode(ledPinsSec[i], OUTPUT);
  29.   }
  30.  
  31.   for (byte i = 0; i < nBitsMin; i++) {
  32.     pinMode(ledPinsMin[i], OUTPUT);
  33.   }
  34.  
  35.   for (byte i = 0; i < nBitsHr; i++) {
  36.     pinMode(ledPinsHr[i], OUTPUT);
  37.   }
  38. }
  39.  
  40. // ----- Main Routine -------------------------------------------------
  41.  
  42. void loop(void)
  43. {
  44.   countS = (countS + 1);
  45.   if (countS > 59)
  46.   {
  47.     countS = 0;
  48.     countM = (countM + 1);
  49.     if (countM > 59)
  50.     {
  51.       countM = 0;
  52.       countH = (countH + 1);
  53.       if (countH > 23)
  54.       {
  55.         countH = 0;
  56.         countM = 0;
  57.         countS = 0;
  58.       }
  59.     }
  60.   }
  61.  
  62.   dispBinarySec(countS);
  63.   dispBinaryMin(countM);
  64.   dispBinaryHr(countH);
  65.  
  66.   delay(1000);   // 1 second delay - ADJUST for fast or slow running clock here, in milliseconds.
  67. }
  68.  
  69. // ----- Subroutines ---------------------------------------------------
  70.  
  71. void dispBinarySec(byte nSec)
  72. {
  73.   for (byte i = 0; i < nBitsSec; i++) {
  74.     digitalWrite(ledPinsSec[i], nSec & 1);
  75.     nSec /= 2;
  76.   }
  77. }
  78.  
  79. void dispBinaryMin(byte nMin)
  80. {
  81.   for (byte i = 0; i < nBitsMin; i++) {
  82.     digitalWrite(ledPinsMin[i], nMin & 1);
  83.     nMin /= 2;
  84.   }
  85. }
  86.  
  87. void dispBinaryHr(byte nHr)
  88. {
  89.   for (byte i = 0; i < nBitsHr; i++) {
  90.     digitalWrite(ledPinsHr[i], nHr & 1);
  91.     nHr /= 2;
  92.   }
  93. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement