Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //Librairy
- #include <RTClib.h>
- #include <Wire.h>
- #include <MD_Parola.h>
- #include <MD_MAX72xx.h>
- #include <SPI.h>
- #include <Font_Data.h>
- // MAX7219 setup :
- #define HARDWARE_TYPE MD_MAX72XX::FC16_HW
- #define MAX_DEVICES 4
- #define CLK_PIN 13
- #define DATA_PIN 11
- #define CS_PIN 10
- // Brightness setup
- const int buttonLess = 2;
- const int buttonPlus = 3;
- const int maxBrightness = 15;
- int Brightness = maxBrightness;
- int interval = 1;
- //Menu setup
- const int setMenu = 4;
- int menu = 0;
- // MD_Parola Setup
- MD_Parola P = MD_Parola(HARDWARE_TYPE, DATA_PIN, CLK_PIN, CS_PIN, MAX_DEVICES);
- char Time[8]; // Actual Time (hh:mm:ss)
- // RTC setup :
- RTC_DS3231 RTC; // Establish clock object
- DateTime Clock; // Holds current clock time
- byte hourval, minuteval, secondval;
- void setup() {
- Serial.begin(9600);
- Wire.begin(); // Begin I2C
- RTC.begin(); // Begin clock
- P.begin(); // Begin Max7219
- P.setIntensity(0); // Intensité de l'écran minimum au démarrage
- //Brightness
- pinMode(buttonLess, INPUT);
- pinMode(buttonPlus, INPUT);
- pinMode(setMenu, INPUT);
- }
- void loop()
- {
- // check if you press the SET button and increase the menu index
- if (digitalRead(setMenu) == HIGH)
- {
- menu = menu+1;
- }
- // in wich subroutine should we go ?
- if (menu==0)
- {
- DisplayDateTime(); // void DisplayDateTime
- }
- if (menu==1)
- {
- DisplaySetBrightness();
- }
- if (menu == 2)
- {
- menu=0;
- }
- delay(100);
- }
- void DisplayDateTime()
- {
- // We show the current time
- Clock = RTC.now(); // get the RTC time
- secondval = Clock.second(); // get seconds
- minuteval = Clock.minute(); // get minutes
- hourval = Clock.hour(); // get hours
- // RTC values for the MAX7219 Matrix :
- DateTime now = RTC.now();
- // Messages displayed ont the MAX7219 Matrix :
- sprintf(Time, "%2d%c%02d%c%02d", now.hour(), ':', now.minute(), ':', now.second());
- P.setFont(0, numeric7Se);
- P.displayText(Time, PA_CENTER, 0, 0, PA_PRINT, PA_NO_EFFECT);
- P.displayAnimate();
- void DisplaySetBrightness()
- {
- P.setfont(0, numeric7Se);
- P.displayText("Brightness", PA_CENTER, 0, 0, PA_PRINT, PA_NO_EFFECT);
- P.displayAnimate();
- if (digitalRead(buttonLess) == HIGH && Brightness > 0)
- {Brightness = Brightness - interval;}
- if (digitalRead(buttonPlus) == HIGH && Brightness < maxBrightness)
- {Brightness = Brightness + interval;}
- delay(100);
- P.setIntensity(Brightness);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement