// test pour fixer boutton
#include <Wire.h>
#include <U8g2lib.h>
// Configuration de l'écran OLED en I2C (128x64)
U8G2_SSD1306_128X64_NONAME_F_HW_I2C u8g2(U8G2_R0, /* reset=*/U8X8_PIN_NONE);
// Configuration des boutons
const int playPauseButton = 12;
const int nextButton = 14;
const int prevButton = 27;
// Variables pour la gestion de l’état
bool isPlaying = false;
int currentTrack = 1; // Piste actuelle
unsigned long previousMillis = 0;
int trackDuration = 180; // Durée de la piste en secondes (exemple)
// Vos images en format XBM
static const uint8_t image_download_bits[] = {0x03,0x00,0x07,0x00,0x19,0x00,0x61,0x00,0x81,0x01,0x01,0x06,0x01,0x18,0x01,0x60,0x01,0x18,0x01,0x06,0x81,0x01,0x61,0x00,0x19,0x00,0x07,0x00,0x03,0x00,0x00,0x00};
static const uint8_t image_ButtonRight_bits[] = {0x01,0x03,0x07,0x0f,0x07,0x03,0x01};
static const uint8_t image_download_1_bits[] = {0xe0,0x03,0xf8,0x0f,0x7c,0x1f,0x7e,0x3e,0x6e,0x3d,0x5f,0x7b,0x3f,0x7d,0x7f,0x7e,0x3f,0x7d,0x5f,0x7b,0x6e,0x3d,0x7e,0x3e,0x7c,0x1f,0xf8,0x0f,0xe0,0x03};
static const uint8_t image_download_2_bits[] = {0x00,0x00,0x00,0xf0,0xff,0x7f,0x08,0x00,0x80,0x08,0xdb,0xb6,0x0e,0xdb,0xb6,0x01,0xdb,0xb6,0x01,0xdb,0xb6,0x01,0xdb,0xb6,0x01,0xdb,0xb6,0x0e,0xdb,0xb6,0x08,0xdb,0xb6,0x08,0x00,0x80,0xf0,0xff,0x7f,0x00,0x00,0x00,0x00,0x00,0x00};
static const uint8_t image_download_3_bits[] = {0xfc,0xff,0xff,0xff,0x7f,0x00,0x10,0x02,0x00,0x00,0x00,0x80,0x00,0x20,0x01,0x00,0x00,0x00,0x18,0x01,0x42,0x01,0x03,0x6c,0xdb,0x24,0x01,0x44,0x01,0x03,0x6c,0xdb,0x24,0x01,0x88,0x01,0x03,0x0c,0x00,0x18,0x81,0x88,0x01,0x00,0x60,0xdb,0x00,0x07,0x89,0x71,0x3b,0x6c,0xdb,0x00,0x09,0x89,0x71,0x3b,0x0c,0x00,0x00,0x09,0x89,0x01,0x00,0x6c,0xdb,0x00,0x07,0x89,0x01,0x03,0x60,0xdb,0x18,0x81,0x88,0x01,0x03,0x00,0x00,0x3c,0x01,0x88,0x01,0xe3,0xbd,0xf7,0x3c,0x01,0x44,0x01,0xe0,0xbd,0xf7,0x18,0x01,0x42,0x02,0x00,0x00,0x00,0x80,0x00,0x20,0xfc,0xff,0xff,0xff,0x7f,0x00,0x10};
void setup() {
// Initialisation de l'écran
u8g2.begin();
// Configuration des boutons
pinMode(playPauseButton, INPUT_PULLUP);
pinMode(nextButton, INPUT_PULLUP);
pinMode(prevButton, INPUT_PULLUP);
}
void simulatePlayTrack(int track) {
Serial.print("Lecture de la piste ");
Serial.println(track);
}
void loop() {
// Gestion des boutons
if (digitalRead(playPauseButton) == LOW) {
delay(200); // Débounce
isPlaying = !isPlaying;
if (isPlaying) {
simulatePlayTrack(currentTrack);
} else {
Serial.println("Pause");
}
}
if (digitalRead(nextButton) == LOW) {
delay(200); // Débounce
currentTrack++;
simulatePlayTrack(currentTrack);
isPlaying = true;
}
if (digitalRead(prevButton) == LOW) {
delay(200); // Débounce
currentTrack--;
simulatePlayTrack(currentTrack);
isPlaying = true;
}
// Mise à jour du temps de lecture simulé
unsigned long currentMillis = millis();
int secondsPlayed = (currentMillis - previousMillis) / 1000;
int minutes = secondsPlayed / 60;
int seconds = secondsPlayed % 60;
// Efface le tampon (buffer)
u8g2.clearBuffer();
// Affiche les images et le texte
u8g2.setBitmapMode(1);
u8g2.setFontMode(1);
u8g2.drawXBM(11, 36, 15, 16, image_download_bits);
// Affiche le temps de lecture
char timeString[6];
sprintf(timeString, "%02d:%02d", minutes, seconds);
u8g2.setFont(u8g2_font_profont29_tr);
u8g2.drawStr(40, 62, timeString);
// Affiche le nom de la piste audio (exemple)
u8g2.setFont(u8g2_font_profont10_tr);
u8g2.drawStr(40, 39, "Piste audio");
// Affiche d'autres informations
u8g2.setFont(u8g2_font_profont15_tr);
u8g2.drawStr(41, 30, "Nom de la piste");
// Affiche d'autres images
u8g2.drawXBM(29, 0, 15, 15, image_download_1_bits);
u8g2.drawXBM(1, 0, 24, 16, image_download_2_bits);
u8g2.drawXBM(72, 0, 56, 16, image_download_3_bits);
// Envoie le contenu du tampon à l'écran
u8g2.sendBuffer();
delay(100); // Temps d'attente pour rafraîchissement
}