Advertisement
LeventeDaradici

Digital clock - Max 7219 with random animations

Sep 26th, 2021
6,382
0
Never
1
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 7.27 KB | None | 0 0
  1. #include <MD_Parola.h>
  2. #include "RTClib.h"
  3. #include <DHT.h>
  4.  
  5. #define DHTPIN 2
  6. #define DHTTYPE DHT11
  7. DHT dht(DHTPIN, DHTTYPE);
  8.  
  9. RTC_DS1307 RTC;
  10. DateTime now;
  11.  
  12. #define HARDWARE_TYPE MD_MAX72XX::FC16_HW
  13. #define MAX_DEVICES 4
  14. #define CLK_PIN   13
  15. #define DATA_PIN  11
  16. #define CS_PIN    10
  17.  
  18. int i = 9;
  19. int Animation;
  20. String RandAn;
  21.  
  22. MD_Parola P = MD_Parola(HARDWARE_TYPE, CS_PIN, MAX_DEVICES);
  23.  
  24. char daysOfTheWeek[7][12] = {"Dum", "Luni", "Marti", "Mierc", "Joi", "Vineri", "Sambat"};
  25. char monthOfTheYear[12][12] = {"Ian", "Feb", "Mart", "April", "Mai", "Iun", "Iul", "Aug", "Sept", "Oct", "Noi", "Dec"};
  26.  
  27. struct sCatalog
  28. {
  29.   textEffect_t  effect;  
  30.   const char *  psz;      
  31.   uint16_t      speed;    
  32.   uint16_t      pause;    
  33. };
  34.  
  35. sCatalog catalog[] =
  36. {
  37.   { PA_PRINT,"",80,3000 },
  38.   { PA_SCROLL_UP,"",80,3000 },
  39.   { PA_SCROLL_DOWN,"",80,3000 },
  40.   { PA_SCROLL_LEFT,"",80,3000 },
  41.   { PA_SCROLL_RIGHT,"",80,3000 },
  42.   { PA_SPRITE,"",80,3000  },
  43.   { PA_SLICE,"",15,3000  },
  44.   { PA_MESH,"",150,3000  },
  45.   { PA_FADE,"",250,3000  },
  46.   { PA_DISSOLVE,"",500,3000  },
  47.   { PA_BLINDS,"",120,3000  },
  48.   { PA_RANDOM,"",50,3000  },
  49.   { PA_WIPE,"",80,3000  },
  50.   { PA_WIPE_CURSOR,"",80,3000  },
  51.   { PA_SCAN_HORIZ,"",80,3000  },
  52.   { PA_SCAN_HORIZX,"",80,3000  },
  53.   { PA_SCAN_VERT,"",80,3000  },
  54.   { PA_SCAN_VERTX,"",80,3000  },
  55.   { PA_OPENING,"",80,3000  },
  56.   { PA_OPENING_CURSOR,"",80,3000  },
  57.   { PA_CLOSING,"",80,3000  },
  58.   { PA_CLOSING_CURSOR,"",80,3000  },
  59.   { PA_SCROLL_UP_LEFT,"",80,3000  },
  60.   { PA_SCROLL_UP_RIGHT,"",80,3000   },
  61.   { PA_SCROLL_DOWN_LEFT,"",80,3000  },
  62.   { PA_SCROLL_DOWN_RIGHT,"",80,3000  },
  63.   { PA_GROW_UP,"",80,3000  },
  64.   { PA_GROW_DOWN,"",80,3000  },
  65. };
  66.  
  67.  
  68. // Sprite Definitions
  69. const uint8_t F_PMAN1 = 6;
  70. const uint8_t W_PMAN1 = 8;
  71. static const uint8_t PROGMEM pacman1[F_PMAN1 * W_PMAN1] =  // gobbling pacman animation
  72. {
  73.   0x00, 0x81, 0xc3, 0xe7, 0xff, 0x7e, 0x7e, 0x3c,
  74.   0x00, 0x42, 0xe7, 0xe7, 0xff, 0xff, 0x7e, 0x3c,
  75.   0x24, 0x66, 0xe7, 0xff, 0xff, 0xff, 0x7e, 0x3c,
  76.   0x3c, 0x7e, 0xff, 0xff, 0xff, 0xff, 0x7e, 0x3c,
  77.   0x24, 0x66, 0xe7, 0xff, 0xff, 0xff, 0x7e, 0x3c,
  78.   0x00, 0x42, 0xe7, 0xe7, 0xff, 0xff, 0x7e, 0x3c,
  79. };
  80.  
  81. const uint8_t F_PMAN2 = 6;
  82. const uint8_t W_PMAN2 = 18;
  83. static const uint8_t PROGMEM pacman2[F_PMAN2 * W_PMAN2] =  // ghost pursued by a pacman
  84. {
  85.   0x00, 0x81, 0xc3, 0xe7, 0xff, 0x7e, 0x7e, 0x3c, 0x00, 0x00, 0x00, 0xfe, 0x7b, 0xf3, 0x7f, 0xfb, 0x73, 0xfe,
  86.   0x00, 0x42, 0xe7, 0xe7, 0xff, 0xff, 0x7e, 0x3c, 0x00, 0x00, 0x00, 0xfe, 0x7b, 0xf3, 0x7f, 0xfb, 0x73, 0xfe,
  87.   0x24, 0x66, 0xe7, 0xff, 0xff, 0xff, 0x7e, 0x3c, 0x00, 0x00, 0x00, 0xfe, 0x7b, 0xf3, 0x7f, 0xfb, 0x73, 0xfe,
  88.   0x3c, 0x7e, 0xff, 0xff, 0xff, 0xff, 0x7e, 0x3c, 0x00, 0x00, 0x00, 0xfe, 0x73, 0xfb, 0x7f, 0xf3, 0x7b, 0xfe,
  89.   0x24, 0x66, 0xe7, 0xff, 0xff, 0xff, 0x7e, 0x3c, 0x00, 0x00, 0x00, 0xfe, 0x73, 0xfb, 0x7f, 0xf3, 0x7b, 0xfe,
  90.   0x00, 0x42, 0xe7, 0xe7, 0xff, 0xff, 0x7e, 0x3c, 0x00, 0x00, 0x00, 0xfe, 0x73, 0xfb, 0x7f, 0xf3, 0x7b, 0xfe,
  91. };
  92.  
  93.  
  94. void setup()
  95. {
  96.   //Serial.begin(9600);
  97.   P.begin();
  98.   P.setInvert(false);
  99.   P.setIntensity(0);
  100.   dht.begin();
  101.   Wire.begin();
  102.   RTC.begin();
  103.   if (! RTC.isrunning())
  104.       {
  105.         //Serial.println("RTC is NOT running!");
  106.         RTC.adjust(DateTime(__DATE__, __TIME__));
  107.       }
  108. #if ENA_SPRITE
  109.   P.setSpriteData(pacman1, W_PMAN1, F_PMAN1, pacman2, W_PMAN2, F_PMAN2);
  110. #endif
  111.         P.displayText("Digital clock ARDUINO - Andrei & Levente Daradici" , PA_CENTER, 50, 0, PA_SCROLL_LEFT, PA_SCROLL_LEFT);
  112.          while (!P.displayAnimate());
  113. }
  114.  
  115. const char *ZiuaCurenta = " ";
  116.  
  117. String Hour;
  118. String TIMP=" ";
  119. String ORA=" ";
  120. String MINUT=" ";
  121. String SECUNDA=" ";
  122. String DATA="";
  123.  
  124. String Day;
  125. String Month;
  126. String Year;
  127. String HumSTR;
  128. String CelSTR;
  129. String FarSTR;
  130.  
  131. void loop()
  132. {
  133.   now = RTC.now();
  134.   float h = dht.readHumidity();
  135.   float t = dht.readTemperature();
  136.   float f = dht.readTemperature(true);
  137.  
  138.   if (isnan(h) || isnan(t) || isnan(f)) {
  139.     //Serial.println(F("Failed to read from DHT sensor!"));
  140.     return;
  141.   }
  142.  
  143.   float z = (float)h/1.0;
  144.   HumSTR = String(z,1);
  145.   HumSTR = HumSTR + " %";
  146.   const char *HumC = HumSTR.c_str();
  147.  
  148.   float q = (float)t/1.0;
  149.   CelSTR = String(q,1);
  150.   CelSTR = CelSTR + " C";
  151.   const char *CelC = CelSTR.c_str();
  152.  
  153.   float w = (float)f/1.0;
  154.   FarSTR = String(w,1);
  155.   FarSTR = FarSTR + " F";
  156.   const char *FarC = FarSTR.c_str();
  157.  
  158.   String DayOfWeek = daysOfTheWeek[now.dayOfTheWeek()];
  159.   String MonthOfYear = monthOfTheYear[now.month() - 1];
  160.   const char *DayOfWeekC = DayOfWeek.c_str();
  161.   const char *MonthOfYearC = MonthOfYear.c_str();
  162.  
  163.   ORA = (now.hour());
  164.   if (ORA.length() < 2)
  165.          {
  166.            ORA = "0"+ ORA;
  167.          }
  168.  
  169.   MINUT = (now.minute());
  170.   if (MINUT.length() < 2)
  171.          {
  172.            MINUT = "0"+ MINUT;
  173.          }
  174.  
  175.   TIMP = ORA + ":" + MINUT;
  176.  
  177.   const char *Timp = TIMP.c_str();
  178.  
  179.   Day = now.day();
  180.   Month = now.month();
  181.   Year = now.year();
  182.  
  183.   const char *Ziua = Day.c_str();
  184.   const char *Luna = Month.c_str();
  185.   const char *Anul = Year.c_str();
  186.  
  187.   String Date = Day + "/" + Month + "/" + Year;
  188.   const char *Data = Date.c_str();
  189.  
  190.  
  191.    if (i == 1)
  192.     {
  193.         Animation = random(1, 29);
  194.         P.displayText(DayOfWeekC, PA_CENTER, catalog[Animation].speed, catalog[Animation].pause, catalog[Animation].effect, catalog[Animation].effect);
  195.          while (!P.displayAnimate());
  196.     }
  197.   if (i == 2)
  198.     {
  199.         Animation = random(1, 29);
  200.         P.displayText(Ziua, PA_CENTER, catalog[Animation].speed, catalog[Animation].pause, catalog[Animation].effect, catalog[Animation].effect);
  201.          while (!P.displayAnimate());
  202.     }
  203.     if (i == 3)
  204.     {
  205.         Animation = random(1, 29);
  206.         P.displayText(MonthOfYearC, PA_CENTER, catalog[Animation].speed, catalog[Animation].pause, catalog[Animation].effect, catalog[Animation].effect);
  207.          while (!P.displayAnimate());
  208.     }
  209.     if (i == 4)
  210.     {
  211.         Animation = random(1, 29);
  212.         P.displayText(Anul, PA_CENTER, catalog[Animation].speed, catalog[Animation].pause, catalog[Animation].effect, catalog[Animation].effect);
  213.          while (!P.displayAnimate());
  214.     }
  215.  
  216.     if (i == 5)
  217.     {
  218.         Animation = random(1, 29);
  219.         P.displayText(Timp, PA_CENTER, catalog[Animation].speed, catalog[Animation].pause, catalog[Animation].effect, catalog[Animation].effect);
  220.          while (!P.displayAnimate());
  221.     }
  222.     if (i == 6)
  223.     {
  224.         String Celsius = String(t) + "°C";
  225.         Animation = random(1, 29);
  226.         P.displayText(CelC, PA_CENTER, catalog[Animation].speed, catalog[Animation].pause, catalog[Animation].effect, catalog[Animation].effect);
  227.          while (!P.displayAnimate());
  228.     }
  229.     if (i == 7)
  230.     {
  231.         Animation = random(1, 29);
  232.         P.displayText(FarC, PA_CENTER, catalog[Animation].speed, catalog[Animation].pause, catalog[Animation].effect, catalog[Animation].effect);
  233.          while (!P.displayAnimate());
  234.     }
  235.     if (i ==8)
  236.     {
  237.         Animation = random(1, 29);
  238.         P.displayText(HumC, PA_CENTER, catalog[Animation].speed, catalog[Animation].pause, catalog[Animation].effect, catalog[Animation].effect);
  239.          while (!P.displayAnimate());
  240.     }
  241.     //Serial.println(Animation);
  242.        i= i+1;
  243.        if (i > 8)
  244.        {
  245.          i=1;
  246.        };
  247.  
  248. }
  249.  
  250.  
Advertisement
Comments
Add Comment
Please, Sign In to add comment
Advertisement