#include <Arduino.h>
//String Version = "V0.00"; //Version INITIALE
#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd(0x27,16,2);
#include <SPIFFS.h>
/*#include <sqlite3.h>
sqlite3 *db_base;*/
#include <OneButton.h>
OneButton button4(26, true); OneButton button5(27, true); OneButton button6(14, true); OneButton button7(5, true);
OneButton button1(32, true); OneButton button2(33, true); OneButton button3(25, true); OneButton button8(23, true);
#include <ESP32Encoder.h>
ESP32Encoder encoder1;
ESP32Encoder encoder2;
int enc1last, enc2last;
#include <Wire.h>
const byte rgbcolor [8] = {0b000, 0b100, 0b010, 0b001, 0b101, 0b011, 0b110, 0b111};
int pied = 1; int piedavant = 1; int i = 0; int j = 0; int k = 0; int id = 1; int count = 1;
int bank = 1; int nbbank = 3; int menus = 0; int couleur1 = 1; int couleur2 = 1; int count1 = 1; int count2 = 1;
unsigned long previousMillis=0 ;
unsigned long interval = 1200L;
//int MIDICanal[17] = {0, 176, 177, 178, 179, 180, 181, 182, 183, 184, 185, 186, 187, 188, 189, 190, 191};
//int MIDIPC[17] = {0, 192, 193, 194, 195, 196, 197, 198, 199, 200, 201, 202, 203, 204, 205, 206, 207};
// 04 05 06 07 08 09 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56
int totalCC [54] = {0, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 16, 18, 20, 13, 7, 102, 23, 25, 28, 79, 19, 15, 106, 107, 103, 14, 16, 17, 18, 20, 21, 22, 24, 26, 27, 29, 30, 104, 75, 85, 76, 77, 78, 108, 109, 110, 111, 112, 113, 114, 115};
int Amperoquick [2] [7] = {{0, 7, 16, 18, 20, 13, 0}, {0, 20, 17, 18, 19, 16, 0}};
int toneXquick [2] [7] = {{0, 102, 106, 107, 103, 18, 26}, {0, 21, 28, 29, 30, 35, 39}};
int value[4]; String t;
String namequickAmp [7] {"", "Volume : ", "Param 1 : ", "Param 2 : ", "Param 2 : ", "Exp : ", ""};
String namequickTone [7] {"", "GAIN : ", "COMPRESSOR : ", "REVERB : ", "MODEL.VOL : ", "DEPTH : ", "PRESENCE : "};
String namesCC[55] = { "",
"Slot A1 : ", "Slot A2 : ", "Slot A3 : ", "Slot A4 : ", "Slot A5 : ", "Slot A6 : ",
"Slot B1 : ", "Slot B2 : ", "Slot B3 : ", "Slot B4 : ", "Slot B5 : ", "Slot B6 : ",
"Exp : ", "Param 1 : ", "Param 2 : ", "Param 2 : ", "Volume : ",
"GAIN : ", "BASS : ", "MID : ", "TREBLE : ", "REVERB : ", "COMPRESSOR : ",
"NOISE GATE : ", "PRESENCE : ", "DEPTH : ", "MODEL.VOL : ", "NOISE GT : ", "NG REL : ",
"NG DPTH : ", "COMP : ", "CMP GAIN : ", "COMP ATK : ", "COMP PATC : ",
"BASS FRQ : ", "MID Q : ", "MID FRQ : ", "TRBL FRQ : ", "EQ PATCH : ", "MIX : ",
"REVERB : ", "REV TYPE : ", "TIME : ", "PREDELAY : ", "COLOR : ", "RESO : ",
"MIC 1 : ", "MIC 1 X : ", "MIC 1 Z : ", "MIC 2 : ", "MIC 2 X : ", "MIC 2 Z : ", "MICS MIX : ", "NB FX MAX : "
};
int valmaxCC [55] = {0,
127,127,127,127,127,127,
127,127,127,127,127,127,
100,100,100,100,100,
100,100,100,100,100,100,
127,127,127,127,127,127,
127,127,127,127,127,
127,127,127,127,127,127,
127,127,127,127,127,127,
127,127,127,127,127,127,127,58
};
int leds [7] = {0,21,22,23,24,25,26};
int ledscolor [7] = {0,1,2,3,4,5,6};
int encvalmax1 [7] = {0,100, 127, 100, 127, 127, 100};
int encvalmin1 [7] = {0,0, 0, 0, 0, 0, 0};
int encvalmax2 [7] = {0,100, 127, 100, 127, 127, 100};
int encvalmin2 [7] = {0,0, 0, 0, 0, 0, 0};
int params[61][61]; int paramscopy[61][61];
String sql;
// ---------------------------------------------------------------ECRANS
void screen1() {
lcd.clear();
lcd.setCursor(1,0);
lcd.print("AMPERO 2 STOMP");
lcd.setCursor(5,1);
lcd.print("TONE_X");
}
void screenAllCC() {
String texte;
if (count > 0 && count < 14 && menus == 1){
lcd.clear();
lcd.setCursor(0,0);
lcd.print("**** AMPERO ****");
lcd.setCursor(0,1);
texte = namesCC[count];
lcd.print(texte);
lcd.setCursor(13,1);
if (params[id + pied][count+3] == 0) {lcd.print("OFF");} else {lcd.print("ON");};
}
if (count > 13 && count < 18 && menus == 1){
lcd.clear();
lcd.setCursor(0,0);
lcd.print("**** AMPERO ****");
lcd.setCursor(0,1);
texte = namesCC[count];
lcd.print(texte);
lcd.setCursor(14,1);
texte = params[id + pied][count+3];
lcd.print(texte);
}
if (count > 17 && count < 55 && menus == 1){
lcd.clear();
lcd.setCursor(0,0);
lcd.print("**** TONE_X ****");
lcd.setCursor(0,1);
texte = namesCC[count];
lcd.print(texte);
lcd.setCursor(14,1);
texte = params[id + pied][count+3];
lcd.print(texte);
}
}
void selectBank() {
if (id < 61) {bank = 1;}
if (id > 60 && id < 121) {bank = 2;}
if (id > 120 && id < 181) {bank = 3;}
}
void displayColor1(byte color) {
digitalWrite(ledscolor[0], !bitRead(color, 2));
digitalWrite(ledscolor[1], !bitRead(color, 1));
digitalWrite(ledscolor[2], !bitRead(color, 0));
}
void displayColor2(byte color) {
digitalWrite(ledscolor[5], !bitRead(color, 2));
digitalWrite(ledscolor[4], !bitRead(color, 1));
digitalWrite(ledscolor[5], !bitRead(color, 0));
}
void initEncoder(int val1) {
switch (val1) {
case 1 :
encoder1.setCount(params[id + pied][Amperoquick[1][count1]]);
enc1last = params[id + pied][Amperoquick[1][count1]];
encoder2.setCount(params[id + pied] [toneXquick[1][count2]]);
enc2last = params[id + pied] [toneXquick[1][count2]];
break;
case 2 :
encoder1.setCount(count);
enc1last = count;
encoder2.setCount(count);
enc2last = count;
break;
case 3 :
encoder1.setCount(params[id + pied][count + 3]);
enc1last = params[id + pied][count + 3];
encoder2.setCount(params[id + pied][count + 3]);
enc2last = params[id + pied] [count + 3];
break;
}
}
void encod1(int valmini, int valmaxi, int pot, int sel){
switch (sel) {
case 0 :
if (enc1last != encoder1.getCount()) {
pot = encoder1.getCount();
if (pot > valmaxi) {pot = valmaxi;}
if (pot < valmini) {pot = valmini;}
params[id + pied][Amperoquick[1][count1]] = pot;
encoder1.setCount(pot);
enc1last = pot;
Serial.println(pot);
}
break;
case 1 :
if (sel == 1) {value[0] = valmaxi; value[1] = valmaxi; value[2] = valmini; value[3] = valmini;}
else {value[0] = valmaxi; value[1] = valmini; value[2] = valmini; value[3] = valmaxi;}
if (enc1last != encoder1.getCount()) {
pot = encoder1.getCount();
if (pot > value[0]) {pot = value[1];}
if (pot < value[2]) {pot = value[3];}
count = pot;
encoder1.setCount(pot);
enc1last = pot;
screenAllCC();
}
break;
}
}
void encod2(int valmini, int valmaxi, int pot, int sel){
switch (sel) {
case 0 :
if (enc2last != encoder2.getCount()) {
value[0] = valmaxi; value[1] = valmaxi; value[2] = valmini; value[3] = valmini;
pot = encoder2.getCount();
if (pot > value[0]) {pot = value[1];}
if (pot < value[2]) {pot = value[3];}
enc2last = pot;
params[id + pied][toneXquick[1][count2]] = pot;
//Serial.println(params[id + pied][toneXquick[1][count2]]);
Serial.println("Encoder 2");
}
break;
case 1 :
break;
}
}
void Rotatif(int choixrot, int menu) {
switch (choixrot) {
case 1 :
switch (menu) {
case 0 :
if (couleur1 == 1) {displayColor1(rgbcolor[count1]); couleur1 = 2;}
else {
if (count1 > 0 && count1 < 6) {
count1 = count1+1;
}
else {count1 = 1;}
initEncoder(1);
displayColor1(rgbcolor[count1]);
Serial.println();
Serial.print("Mini : ");
Serial.println(encvalmin1[params[id+pied][count1]]);
Serial.print("Maxi : ");
Serial.println(encvalmax1[params[id+pied][count1]]);
Serial.print("Val : ");
Serial.println(params[id + pied][Amperoquick[1][count1]]);
Serial.println();
Serial.print("Nb : ");
Serial.println(count1);
Serial.print("CC : ");
Serial.println(Amperoquick[0][count1]);
Serial.print("Param : ");
Serial.println(Amperoquick[1][count1]);
Serial.print("Val : ");
Serial.println(params[id + pied][Amperoquick[1][count1]]);
break;
}
case 1 :
screenAllCC();
while (menus == 1) {
initEncoder(2);
encod1(1,54,count,1);
encod2(1,127,params[id + pied][count+3],1);
if (digitalRead(5) == 1) {}
if (digitalRead(23) == 0) {
delay(100);
if (digitalRead(23) == 1) {}
else{menus = 0; screen1(); break;}
}
}
break;
}
break;
case 2 :
switch (menu) {
case 0 :
if (couleur2 == 1) {displayColor2(rgbcolor[count2]); couleur2 = 2;}
else {
if (count2 > 0 && count2 < 6) {
count2 = count2+1;
}
else {count2 = 1;}
initEncoder(1);
displayColor2(rgbcolor[count2]);
/*Serial.println();
Serial.print("Nb : ");
Serial.println(count2);
Serial.print("CC : ");
Serial.println(toneXquick[0][count2]);
Serial.print("Param : ");
Serial.println(toneXquick[1][count2]);
Serial.print("Val : ");
Serial.println(params[id + pied][toneXquick[1][count2]]);**/
break;
}
case 1 :
break;
}
break;
}
}
void chgtPedal() {
delay(50);
for (i = 21; i < params[id + pied][58]; i++){
}
for (i = 4; i < 21; i++){
}
}
void setup() {
//pinMode(5, OUTPUT); pinMode(15, OUTPUT); pinMode(4, OUTPUT);
pied = 0; piedavant = -1;
lcd.init(); // initialize the lcd
lcd.backlight();
screen1();
Serial.begin(115200);
Wire.begin(22, 21);
/*if(SPIFFS.begin(true)){
File root = SPIFFS.open("/"); readData(); selectBank(); chgtPedal(); Rotatif(1, 0); Rotatif(2, 0);}
else {Serial.println("SPIFFS marche pas");} */
button1.setPressTicks(500);
button2.setPressTicks(500);
button3.setPressTicks(500);
button4.setPressTicks(500);
button5.setPressTicks(500);
button6.setPressTicks(500);
button7.setPressTicks(500);
button8.setPressTicks(500);
button1.attachClick([] () {if(menus == 0) {piedavant = pied; pied = 0; chgtPedal();}});
button2.attachClick([] () {if(menus == 0) {piedavant = pied; pied = 1; chgtPedal();}});
button3.attachClick([] () {if(menus == 0) {piedavant = pied; pied = 2; chgtPedal();}});
button4.attachClick([] () {if(menus == 0) {piedavant = pied; pied = 3; chgtPedal();}});
button5.attachClick([] () {if(menus == 0) {piedavant = pied; pied = 4; chgtPedal();}});
button6.attachClick([] () {if(menus == 0) {piedavant = pied; pied = 5; chgtPedal();}});
button7.attachClick([] () {if(menus == 0) {Rotatif(1, menus);} if(menus == 1) {Rotatif(1, menus);}});
button8.attachClick([] () {if(menus == 0) {Rotatif(2, menus);} if(menus == 1) {Rotatif(2, menus);}});
button1.attachLongPressStop([] () {});
button2.attachLongPressStop([] () {});
button3.attachLongPressStop([] () {});
button4.attachLongPressStop([] () {});
button5.attachLongPressStop([] () {});
button6.attachLongPressStop([] () {});
button7.attachLongPressStop([] () {Serial.println("Bouton 7"); menus = 1; Rotatif(1, menus);});
button8.attachLongPressStop([] () {Serial.println("Bouton 8");});
ESP32Encoder::useInternalWeakPullResistors=NONE;
encoder1.attachSingleEdge(15, 4);
encoder2.attachSingleEdge(18, 19);
encoder1.clearCount();
encoder1.setFilter(1023);
encoder2.clearCount();
encoder2.setFilter(1023);
previousMillis = millis();
initEncoder(1);
Serial.println();
Serial.print("Mini : ");
Serial.println(encvalmin1[params[id+pied][count1]]);
Serial.print("Maxi : ");
Serial.println(encvalmax1[params[id+pied][count1]]);
Serial.print("Val : ");
Serial.println(params[id + pied][Amperoquick[1][count1]]);
}
//----------------------------------------------------------------------------------END SETUP
void loop(){
button1.tick();
button2.tick();
button3.tick();
button4.tick();
button5.tick();
button6.tick();
button7.tick();
button8.tick();
encod1(encvalmin1[params[id+pied][count1]],encvalmax1[params[id+pied][count1]],params[id + pied][Amperoquick[1][count1]],0);
encod2(encvalmin2[params[id+pied][count2]],encvalmax2[params[id+pied][count2]],params[id + pied] [toneXquick[1][count2]],0);
}