#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
#include <Fonts/FreeSansBold9pt7b.h>
#include <Fonts/Picopixel.h>
#define ENCODER_CLK 2
#define ENCODER_DT 3
#define ENCODER_SW 4
uint8_t volume = 0;
uint8_t bass = 25;
uint8_t treble = 66;
uint8_t reglage = 10;
typedef enum {
SET_VOLUME,
SET_BASS,
SET_TREBLE,
SET_REGLAGE,
} Mode;
Mode mode = SET_VOLUME;
Adafruit_SSD1306 display(128, 64, &Wire, -1);
//************************************************************************************
int menuitem = 1;
int frame = 1;
int page = 1;
int lastMenuItem = 1;
String menuItem1 = "Select Out";
String menuItem2 = "I/O Name";
String menuItem3 = "Reset Mode";
String menuItem4 = "Setup";
String menuItem5 = "Exit";
String menuItem6 = "Dispo";
String menuPrin[5] = { "Select Out", "Name", "Reset Mode", "Setup", "Exit" };
int selectedPrin = 0;
String menuOut[2] = { "Out A", "Out B" };
int selectedOut = 0;
String menuIn[4] = { "In 1", "In 2", "In 3", "In 4" };
int selectedIn = 0;
/*
String menuName[6] = { "HP Hifi", "HP Studio", "PC AAAA", "PC BBBB", "Hifi", "Rack" };
int selectedName = 0;
String menuReset[2] = { "A/B", "All" };
int selectedReset = 0;
*/
boolean backlight = true;
boolean up = false;
boolean down = false;
boolean middle = false;
//**************************************************************************
void setup() {
Serial.begin(9600);
display.begin(SSD1306_SWITCHCAPVCC, 0x3C);
pinMode(ENCODER_CLK, INPUT);
pinMode(ENCODER_DT, INPUT);
pinMode(ENCODER_SW, INPUT_PULLUP);
updateDisplay();
}
//******************************ss prog desc menu***************************************
void nextMode() {
switch (mode) {
case SET_VOLUME:
mode = SET_BASS;
break;
case SET_BASS:
mode = SET_TREBLE;
break;
case SET_TREBLE:
mode = SET_REGLAGE;
break;
case SET_REGLAGE:
mode = SET_VOLUME;
break;
}
}
//***********************************ss prog mont menu*************************************
void precMode() {
switch (mode) {
case SET_VOLUME:
mode = SET_REGLAGE;
break;
case SET_BASS:
mode = SET_VOLUME;
break;
case SET_TREBLE:
mode = SET_BASS;
break;
case SET_REGLAGE:
mode = SET_TREBLE;
break;
}
}
//************************************ss prog modif valeur*************************************
void updateValue(int delta) {
switch (mode) {
case SET_VOLUME:
volume = constrain(volume + delta, 0, 100);
break;
case SET_BASS:
bass = constrain(bass + delta, 0, 100);
break;
case SET_TREBLE:
treble = constrain(treble + delta, 0, 100);
break;
case SET_REGLAGE:
reglage = constrain(reglage + delta, 0, 100);
break;
}
}
void updateDisplay() {
display.setTextSize(2);
display.clearDisplay();
display.setTextColor(WHITE,BLACK );
display.setCursor(14, 0);//(x, y) max 10 caract MAJ/min (2), max 20 min (1)
display.println("Main Menu");//
display.setTextSize(1);
display.drawFastHLine(0,15,128,WHITE);//BLACK
display.setFont();
display.setTextColor(1);
display.setCursor(32, 22);
display.print("Select Out");
// display.drawRoundRect(10, 12, 102, 9, 2, WHITE); //dessin rect
// display.fillRect(11, 13, volume, 7, WHITE); //remplissage rect
if (mode == SET_VOLUME) {
display.setCursor(22, 22);
display.print(">");
}
display.setCursor(32, 32);
display.print("I/O Name");
// display.drawRoundRect(10, 32, 102, 9, 2, WHITE);
//display.fillRect(11, 33, bass, 7, WHITE);
if (mode == SET_BASS) {
display.setCursor(22, 32);
display.print(">");
}
display.setCursor(32, 42);
display.print("Reset Mode");
//display.drawRoundRect(10, 52, 102, 9, 2, WHITE);
// display.fillRect(11, 53, treble, 7, WHITE);
if (mode == SET_TREBLE) {
display.setCursor(22, 42);
display.print(">");
}
display.setCursor(32, 52);
display.print("Setup");
//display.drawRoundRect(10, 52, 102, 9, 2, WHITE);
// display.fillRect(11, 53, treble, 7, WHITE);
if (mode == SET_REGLAGE) {
display.setCursor(22, 52);
display.print(">");
}
display.display();
}
//*************************SS prog encoder*******************************************
long int modeLastChanged = 0;
int prevClk = HIGH;
void loop() {
if (digitalRead(ENCODER_SW) == LOW && millis() - modeLastChanged > 300) {
modeLastChanged = millis();
//nextMode();
updateDisplay();
//Serial.print(F("millis = "));
// Serial.println(millis());
}
int clk = digitalRead(ENCODER_CLK);
if (clk != prevClk && clk == LOW) {
int dt = digitalRead(ENCODER_DT);
// int delta = dt == HIGH ? 5 : -5;
if (dt == 1){
nextMode();
}
else {
precMode();
}
updateDisplay();
}
prevClk = clk;
}