daily pastebin goal
13%
SHARE
TWEET

Untitled

Full_Throttle Jan 20th, 2019 71 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. //Librairy
  2. #include <RTClib.h>
  3. #include <Wire.h>
  4. #include <MD_Parola.h>
  5. #include <MD_MAX72xx.h>
  6. #include <SPI.h>
  7. #include <Font_Data.h>
  8.  
  9. // MAX7219 setup :
  10. #define HARDWARE_TYPE MD_MAX72XX::FC16_HW
  11. #define MAX_DEVICES 4
  12. #define CLK_PIN   13
  13. #define DATA_PIN  11
  14. #define CS_PIN    10
  15.  
  16. // Brightness setup
  17. const int buttonLess = 2;
  18. const int buttonPlus = 3;
  19. const int maxBrightness = 15;
  20. int Brightness = maxBrightness;
  21. int interval = 1;
  22.  
  23. //Menu setup
  24. const int setMenu = 4;
  25. int menu = 0;
  26.  
  27.  
  28. // MD_Parola Setup
  29. MD_Parola P = MD_Parola(HARDWARE_TYPE, DATA_PIN, CLK_PIN, CS_PIN, MAX_DEVICES);
  30. char Time[8];          // Actual Time (hh:mm:ss)
  31.  
  32. // RTC setup :
  33. RTC_DS3231 RTC; // Establish clock object
  34. DateTime Clock; // Holds current clock time
  35. byte hourval, minuteval, secondval;
  36.  
  37. void setup() {
  38.  
  39.   Serial.begin(9600);
  40.   Wire.begin();  // Begin I2C
  41.   RTC.begin();   // Begin clock
  42.   P.begin();     // Begin Max7219
  43.   P.setIntensity(0); // Intensité de l'écran minimum au démarrage
  44.  
  45.    //Brightness
  46.   pinMode(buttonLess, INPUT);
  47.   pinMode(buttonPlus, INPUT);
  48.   pinMode(setMenu, INPUT);
  49.  
  50. }
  51.  
  52. void loop()
  53. {
  54.   // check if you press the SET button and increase the menu index
  55.   if (digitalRead(setMenu) == HIGH)
  56.   {
  57.     menu = menu+1;
  58.   }
  59.  
  60.   // in wich subroutine should we go ?
  61.   if (menu==0)
  62.   {
  63.     DisplayDateTime(); // void DisplayDateTime
  64.   }
  65.  
  66.   if (menu==1)
  67.   {
  68.     DisplaySetBrightness();
  69.   }
  70.  
  71.   if (menu == 2)
  72.   {
  73.     menu=0;
  74.   }
  75.   delay(100);
  76. }  
  77.  
  78. void DisplayDateTime()
  79. {
  80.   // We show the current time
  81.  
  82.   Clock = RTC.now(); // get the RTC time
  83.   secondval = Clock.second();  // get seconds
  84.   minuteval = Clock.minute();  // get minutes
  85.   hourval = Clock.hour();      // get hours
  86.  
  87.   // RTC values for the MAX7219 Matrix :
  88.   DateTime now = RTC.now();
  89.  
  90.   // Messages displayed ont the MAX7219 Matrix :
  91.   sprintf(Time, "%2d%c%02d%c%02d", now.hour(), ':', now.minute(), ':', now.second());
  92.  
  93.   P.setFont(0, numeric7Se);
  94.   P.displayText(Time, PA_CENTER, 0, 0, PA_PRINT, PA_NO_EFFECT);
  95.   P.displayAnimate();
  96.  
  97. void DisplaySetBrightness()
  98. {
  99.   P.setfont(0, numeric7Se);
  100.   P.displayText("Brightness", PA_CENTER, 0, 0, PA_PRINT, PA_NO_EFFECT);
  101.   P.displayAnimate();
  102.  
  103.   if (digitalRead(buttonLess) == HIGH && Brightness > 0)
  104.   {Brightness = Brightness - interval;}
  105.  
  106.   if (digitalRead(buttonPlus) == HIGH && Brightness < maxBrightness)
  107.   {Brightness = Brightness + interval;}
  108.  
  109.   delay(100);
  110.  
  111.   P.setIntensity(Brightness);
  112. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top