voici le code test "menu"
#include <Adafruit_GFX.h>
#include <Adafruit_GC9A01A.h>
#define BUTTON_PIN 2 // Pin pour le bouton (interrupteur)
#define TFT_DC 9
#define TFT_CS 10
Adafruit_GC9A01A tft(TFT_CS, TFT_DC);
#define BLACK 0x0000
#define RED 0xF800
#define GREEN 0x07E0
#define CYAN 0x07FF
#define YELLOW 0xFFE0
#define WHITE 0xFFFF
#define Maroon 0x7800
#include <Fonts/FreeSansBold12pt7b.h>
volatile bool buttonPressed = false;
volatile unsigned long lastDebounceTime = 0;
volatile unsigned long debounceDelay = 50;
enum Menu {
MAIN_MENU,
CLOCK_MENU,
TIMER_MENU
};
Menu currentMenu = MAIN_MENU;
void setup() {
Serial.begin(9600);
tft.begin();
tft.fillScreen(BLACK);
tft.setFont(&FreeSansBold12pt7b);
pinMode(BUTTON_PIN, INPUT_PULLUP);
attachInterrupt(digitalPinToInterrupt(BUTTON_PIN), buttonInterrupt, FALLING);
drawMainMenu();
}
void loop() {
if (buttonPressed) {
switch (currentMenu) {
case MAIN_MENU:
currentMenu = CLOCK_MENU;
drawClockMenu();
break;
case CLOCK_MENU:
currentMenu = TIMER_MENU;
drawTimerMenu();
break;
case TIMER_MENU:
currentMenu = MAIN_MENU;
drawMainMenu();
break;
}
buttonPressed = false;
}
}
void drawMainMenu() {
tft.fillScreen(BLACK);
tft.setCursor(30, 100);
tft.setTextColor(YELLOW); // Texte noir
tft.println("Menu Principal");
}
void drawClockMenu() {
tft.fillScreen(BLACK);
tft.setCursor(30, 120);
tft.setTextColor(CYAN); // Texte noir
tft.println("Menu Horloge");
}
void drawTimerMenu() {
tft.fillScreen(BLACK);
tft.setCursor(30, 140);
tft.setTextColor(GREEN); // Texte noir
tft.println("Menu Chrono");
}
void buttonInterrupt() {
if (millis() - lastDebounceTime > debounceDelay) {
buttonPressed = true;
}
lastDebounceTime = millis();
}