Bonsoir à tous, voici le code avec plusieurs essais de création de menu pour régler la luminosité et plus tard le réglage de l'heure, cela ne fonctionne pas
pourriez vous jeter un oeil ?
merci
//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
// Menu setup
const int buttonLess = 2;
const int buttonPlus = 3;
const int setMenu = 4;
const int maxBrightness = 15;
int Brightness = maxBrightness;
int interval = 1;
// 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)
char menu1[8];
// RTC setup :
RTC_DS3231 RTC; // Establish clock object
DateTime Clock; // Holds current clock time
byte hourval, minuteval, secondval;
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());
sprintf(Time, "%02d:%02d:%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()
{
sprintf(menu1, "Bright");
P.setFont(0, numeric7Se);
P.displayText(menu1, 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;}
P.setIntensity(Brightness);
}
void DisplaySetRtc()
{
// 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, "%02d:%02d:%02d", now.hour(), now.minute(), now.second());
P.setFont(0, numeric7Se);
P.displayText(Time, PA_CENTER, 0, 0, PA_PRINT, PA_NO_EFFECT);
P.setIntensity(0);
delay(500);
P.setIntensity(4);
delay(500);
P.displayAnimate();
}
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()
{
byte menu = 0;
// check if you press the SET button and increase the menu index
if (digitalRead(setMenu) == HIGH)
{
delay(30);
if (digitalRead(setMenu) == HIGH)
{
menu = menu + interval;
}
}
switch (menu)
{
case 0:
DisplayDateTime();
break;
case 1:
DisplaySetBrightness();
break;
case 2:
DisplaySetRtc();
break;
case 3:
menu = 0;
break;
}
/*//in wich subroutine should we go ?
if (menu == 0)
{
DisplayDateTime(); // void DisplayDateTime
}
if (menu == 1)
{
DisplaySetRtc();
}
if (menu == 2)
{
DisplaySetBrightness();
}
if (menu == 3)
{
menu=0;
}
//delay(100);*/
}