Advertisement
elektronek

Tomáš Nitronaut Hora - matrix hodiny

Dec 1st, 2022
1,359
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #define USE_DS1307  0
  2.  
  3. #include <MD_Parola.h>
  4. #include <MD_MAX72xx.h>
  5. #include <SPI.h>
  6. #include "Font7Seg.h"
  7.  
  8. #define HARDWARE_TYPE MD_MAX72XX::PAROLA_HW
  9. #define MAX_CLK_ZONES 2
  10. #define ZONE_SIZE 8
  11. #define MAX_DEVICES (MAX_CLK_ZONES * ZONE_SIZE)
  12.  
  13. #define ZONE_UPPER  1
  14. #define ZONE_LOWER  0
  15.  
  16. #define CLK_PIN   13
  17. #define DATA_PIN  11
  18. #define CS_PIN    10
  19.  
  20. #if USE_DS1307
  21. #include <MD_DS1307.h>
  22. #include <Wire.h>
  23. #endif
  24.  
  25. MD_Parola P = MD_Parola(HARDWARE_TYPE, CS_PIN, MAX_DEVICES);
  26.  
  27. #define SPEED_TIME  75
  28. #define PAUSE_TIME  0
  29. #define MAX_MESG  6
  30. #define  DEBUG  0
  31.  
  32. char  szTimeL[MAX_MESG];    // mm:ss\0
  33. char  szTimeH[MAX_MESG];
  34.  
  35. void getTime(char *psz, bool f = true){
  36. #if USE_DS1307
  37.   RTC.readTime();
  38.   sprintf(psz, "%02d%c%02d", RTC.h, (f ? ':' : ' '), RTC.m);
  39. #else
  40.   uint16_t  h, m;
  41.   m = millis()/1000;
  42.   h = (m/60) % 24;
  43.   m %= 60;
  44.   sprintf(psz, "%02d%c%02d", h, (f ? ':' : ' '), m);
  45. #endif
  46. }
  47.  
  48. void createHString(char *pH, char *pL)
  49. {
  50.   for (; *pL != '\0'; pL++)
  51.     *pH++ = *pL | 0x80;   // offset character
  52.   *pH = '\0'; // terminate the string
  53. }
  54.  
  55. void setup(void)
  56. {
  57.   P.begin(MAX_CLK_ZONES);
  58.   P.setZone(ZONE_LOWER, 0, ZONE_SIZE - 1);
  59.   P.setZone(ZONE_UPPER, ZONE_SIZE, MAX_DEVICES - 1);
  60.   P.setFont(numeric7SegDouble);
  61.   P.setCharSpacing(P.getCharSpacing() * 2);
  62.   P.setZoneEffect(ZONE_UPPER, true, 2);
  63.   P.setZoneEffect(ZONE_LOWER, false, 0);
  64.   P.displayZoneText(ZONE_LOWER, szTimeL, PA_CENTER, SPEED_TIME, PAUSE_TIME, PA_PRINT, PA_NO_EFFECT);
  65.   P.displayZoneText(ZONE_UPPER, szTimeH, PA_CENTER, SPEED_TIME, PAUSE_TIME, PA_PRINT, PA_NO_EFFECT);
  66.  
  67. #if USE_DS1307
  68.   RTC.control(DS1307_CLOCK_HALT, DS1307_OFF);
  69.   RTC.control(DS1307_12H, DS1307_OFF);
  70. #endif
  71. }
  72.  
  73. void loop(void)
  74. {
  75.   static uint32_t   lastTime = 0; // millis() memory
  76.   static bool   flasher = false;  // seconds passing flasher
  77.  
  78.   P.displayAnimate();
  79.   if (P.getZoneStatus(ZONE_LOWER) && P.getZoneStatus(ZONE_UPPER))
  80.   {
  81.     if (millis() - lastTime >= 1000)
  82.     {
  83.       lastTime = millis();
  84.       getTime(szTimeL, flasher);
  85.       createHString(szTimeH, szTimeL);
  86.       flasher = !flasher;
  87.       P.displayReset();
  88.       P.synchZoneStart();
  89.     }
  90.   }
  91. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement