Advertisement
LeventeDaradici

Digital clock - Max 7219 dot matrix display - DS1307 RTC module - DHT11 sensor

Sep 15th, 2021
6,799
1
Never
3
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 5.50 KB | None | 1 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.  
  20. MD_Parola P = MD_Parola(HARDWARE_TYPE, CS_PIN, MAX_DEVICES);
  21.  
  22. char daysOfTheWeek[7][12] = {"Duminica", "Luni", "Marti", "Miercuri", "Joi", "Vineri", "Sambata"};
  23. char monthOfTheYear[12][12] = {"Ianuarie", "Februarie", "Martie", "Aprilie", "Mai", "Iunie", "Iulie", "August", "Septembrie", "Octombrie", "Noiembrie", "Decembrie"};
  24.  
  25. // Sprite Definitions
  26. const uint8_t F_PMAN1 = 6;
  27. const uint8_t W_PMAN1 = 8;
  28. static const uint8_t PROGMEM pacman1[F_PMAN1 * W_PMAN1] =  // gobbling pacman animation
  29. {
  30.   0x00, 0x81, 0xc3, 0xe7, 0xff, 0x7e, 0x7e, 0x3c,
  31.   0x00, 0x42, 0xe7, 0xe7, 0xff, 0xff, 0x7e, 0x3c,
  32.   0x24, 0x66, 0xe7, 0xff, 0xff, 0xff, 0x7e, 0x3c,
  33.   0x3c, 0x7e, 0xff, 0xff, 0xff, 0xff, 0x7e, 0x3c,
  34.   0x24, 0x66, 0xe7, 0xff, 0xff, 0xff, 0x7e, 0x3c,
  35.   0x00, 0x42, 0xe7, 0xe7, 0xff, 0xff, 0x7e, 0x3c,
  36. };
  37.  
  38. const uint8_t F_PMAN2 = 6;
  39. const uint8_t W_PMAN2 = 18;
  40. static const uint8_t PROGMEM pacman2[F_PMAN2 * W_PMAN2] =  // ghost pursued by a pacman
  41. {
  42.   0x00, 0x81, 0xc3, 0xe7, 0xff, 0x7e, 0x7e, 0x3c, 0x00, 0x00, 0x00, 0xfe, 0x7b, 0xf3, 0x7f, 0xfb, 0x73, 0xfe,
  43.   0x00, 0x42, 0xe7, 0xe7, 0xff, 0xff, 0x7e, 0x3c, 0x00, 0x00, 0x00, 0xfe, 0x7b, 0xf3, 0x7f, 0xfb, 0x73, 0xfe,
  44.   0x24, 0x66, 0xe7, 0xff, 0xff, 0xff, 0x7e, 0x3c, 0x00, 0x00, 0x00, 0xfe, 0x7b, 0xf3, 0x7f, 0xfb, 0x73, 0xfe,
  45.   0x3c, 0x7e, 0xff, 0xff, 0xff, 0xff, 0x7e, 0x3c, 0x00, 0x00, 0x00, 0xfe, 0x73, 0xfb, 0x7f, 0xf3, 0x7b, 0xfe,
  46.   0x24, 0x66, 0xe7, 0xff, 0xff, 0xff, 0x7e, 0x3c, 0x00, 0x00, 0x00, 0xfe, 0x73, 0xfb, 0x7f, 0xf3, 0x7b, 0xfe,
  47.   0x00, 0x42, 0xe7, 0xe7, 0xff, 0xff, 0x7e, 0x3c, 0x00, 0x00, 0x00, 0xfe, 0x73, 0xfb, 0x7f, 0xf3, 0x7b, 0xfe,
  48. };
  49.  
  50.  
  51. void setup()
  52. {
  53.   //Serial.begin(9600);
  54.  
  55.   P.begin();
  56.   P.setInvert(false);
  57.   P.setIntensity(1);
  58.   dht.begin();
  59.   Wire.begin();
  60.   RTC.begin();
  61.   if (! RTC.isrunning())
  62.       {
  63.         //Serial.println("RTC is NOT running!");
  64.         RTC.adjust(DateTime(__DATE__, __TIME__));
  65.       }
  66. #if ENA_SPRITE
  67.   P.setSpriteData(pacman1, W_PMAN1, F_PMAN1, pacman2, W_PMAN2, F_PMAN2);
  68. #endif
  69.         P.displayText("Digital clock   Andrei & Levente Daradici" , PA_CENTER, 25, 0, PA_SCROLL_LEFT, PA_SCROLL_LEFT);
  70.          while (!P.displayAnimate());
  71. }
  72.  
  73. const char *ZiuaCurenta = " ";
  74.  
  75. String Hour;
  76. String TIMP=" ";
  77. String ORA=" ";
  78. String MINUT=" ";
  79. String SECUNDA=" ";
  80. String DATA="";
  81.  
  82. String Day;
  83. String Month;
  84. String Year;
  85. String HumSTR;
  86. String CelSTR;
  87. String FarSTR;
  88.  
  89. void loop()
  90. {
  91.   now = RTC.now();
  92.  
  93.   float h = dht.readHumidity();
  94.   float t = dht.readTemperature();
  95.   float f = dht.readTemperature(true);
  96.  
  97.   if (isnan(h) || isnan(t) || isnan(f)) {
  98.     //Serial.println(F("Failed to read from DHT sensor!"));
  99.     return;
  100.   }
  101.  
  102.   float z = (float)h/1.0;
  103.   HumSTR = String(z,1);
  104.   HumSTR = HumSTR + " %";
  105.   const char *HumC = HumSTR.c_str();
  106.  
  107.   float q = (float)t/1.0;
  108.   CelSTR = String(q,1);
  109.   CelSTR = CelSTR + " C";
  110.   const char *CelC = CelSTR.c_str();
  111.  
  112.   float w = (float)f/1.0;
  113.   FarSTR = String(w,1);
  114.   FarSTR = FarSTR + " F";
  115.   const char *FarC = FarSTR.c_str();
  116.  
  117.   String DayOfWeek = daysOfTheWeek[now.dayOfTheWeek()];
  118.   String MonthOfYear = monthOfTheYear[now.month() - 1];
  119.   const char *DayOfWeekC = DayOfWeek.c_str();
  120.   const char *MonthOfYearC = MonthOfYear.c_str();
  121.  
  122.   ORA = (now.hour());
  123.   if (ORA.length() < 2)
  124.          {
  125.            ORA = "0"+ ORA;
  126.          }
  127.  
  128.   MINUT = (now.minute());
  129.   if (MINUT.length() < 2)
  130.          {
  131.            MINUT = "0"+ MINUT;
  132.          }
  133.  
  134.   TIMP = ORA + ":" + MINUT;
  135.  
  136.   const char *Timp = TIMP.c_str();
  137.  
  138.   Day = now.day();
  139.   Month = now.month();
  140.   Year = now.year();
  141.  
  142.   const char *Ziua = Day.c_str();
  143.   const char *Luna = Month.c_str();
  144.   const char *Anul = Year.c_str();
  145.  
  146.   String Date = Day + "/" + Month + "/" + Year;
  147.   const char *Data = Date.c_str();
  148.  
  149.     if (i = 1)
  150.     {
  151.         P.displayText(DayOfWeekC, PA_CENTER, 50, 0, PA_SCROLL_LEFT, PA_SCROLL_LEFT);
  152.          while (!P.displayAnimate());
  153.     }
  154.     if (i = 2)
  155.     {
  156.         P.displayText(Ziua, PA_CENTER, 100, 1000, PA_SCROLL_DOWN_RIGHT, PA_SCROLL_DOWN_RIGHT);
  157.          while (!P.displayAnimate());
  158.     }
  159.     if (i = 3)
  160.     {
  161.         P.displayText(MonthOfYearC, PA_CENTER, 50, 0, PA_SCROLL_LEFT, PA_SCROLL_LEFT);
  162.          while (!P.displayAnimate());
  163.     }
  164.     if (i = 4)
  165.     {
  166.         P.displayText(Anul, PA_CENTER, 10, 3000, PA_SLICE, PA_SLICE);
  167.          while (!P.displayAnimate());
  168.     }
  169.    // if (i = 5)
  170.    // {
  171.    //     P.displayText(Data, PA_CENTER, 50, 0, PA_SCROLL_LEFT, PA_SCROLL_LEFT);
  172.    //      while (!P.displayAnimate());
  173.     //}
  174.     if (i = 6)
  175.     {
  176.         P.displayText(Timp, PA_CENTER, 50, 3000, PA_SPRITE, PA_SPRITE);
  177.          while (!P.displayAnimate());
  178.     }
  179.     if (i = 7)
  180.     {
  181.         String Celsius = String(t) + "°C";
  182.  
  183.         P.displayText(CelC, PA_CENTER, 100, 3000, PA_MESH, PA_MESH);
  184.          while (!P.displayAnimate());
  185.     }
  186.     if (i = 8)
  187.     {
  188.         P.displayText(FarC, PA_CENTER, 150, 3000, PA_BLINDS, PA_BLINDS);
  189.          while (!P.displayAnimate());
  190.     }
  191.     if (i = 9)
  192.     {
  193.         P.displayText(HumC, PA_CENTER, 25, 3000, PA_RANDOM, PA_RANDOM);
  194.          while (!P.displayAnimate());
  195.     }
  196.        i= i+1;
  197.        if (i > 9)
  198.        {
  199.          i=0;
  200.        };
  201.  
  202. }
  203.  
  204.  
  205.  
Advertisement
Comments
Add Comment
Please, Sign In to add comment
Advertisement