Я убрал лишнее, не тестировал.
#include <Wire.h>
#include <PT2314.h>
#include <Wire.h>
#include <LiquidCrystal.h>
//#include <LiquidCrystal_I2C.h>
#include <Encoder.h>
#include <EEPROM.h>
#include <MsTimer2.h>
#include <DS3231.h>
DS3231 clock;RTCDateTime DateTime;
PT2314 pt;
//LiquidCrystal_I2C lcd(0x27,20,4); // Устанавливаем дисплей
LiquidCrystal lcd(7, 6, 2, 3, 4, 5);// RS,E,D4,D5,D6,D7 подключение LCD
Encoder myEnc(11, 10);// DT, CLK
int menu,menu0,menu1,vol,bass,treb,in,balans,balans_d,vol_d,bass_d,treb_d,temp0,par,hour,minut,secon,z_old,gain0,loud;
int att_r,att_l,gain1,gain2,gain3,gain4,brig0,brig1;
byte w2[4],z,z0,z1,n,q,gr1,gr2,www,i,w,mute,power,in_x,save,i1,pin,pin2,hms,irr;
unsigned long time0,times_in;
unsigned int oldPosition = -999,newPosition;
const PROGMEM byte mesto2[4]={0,11,0,11};
const PROGMEM byte mesto3[4]={0,0,1,1};
unsigned long gainTimer;
byte maxValue, maxValue_f,spek;
int i2;
int ek;
void setup() {
lcd.begin(20, 4);
//lcd.init();lcd.backlight();
clock.begin();
Serial.begin(9600);
pinMode(12,INPUT); // МЕНЮ КНОПКА SW энкодера
pinMode(8,INPUT); // КНОПКА IN
pinMode(9,INPUT); // КНОПКА STANDBY / MUTE
pinMode(13,OUTPUT); // ВЫХОД УПРАВЛЕНИЯ STANDBY
lcd.setCursor(1,1);lcd.print("Sound Processor");lcd.setCursor(1,2);lcd.print("PT2314"); delay(2000);lcd.clear();
MsTimer2::set(3, to_Timer);MsTimer2::start();
// clock.setDateTime(__DATE__, __TIME__); // Устанавливаем время на часах, основываясь на времени компиляции скетча
if(EEPROM.read(100)!=0){for(int i=0;i<101;i++){EEPROM.update(i,0);}}// очистка памяти при первом включении
vol = EEPROM.read(0);treb = EEPROM.read(1)-7;bass = EEPROM.read(2)-7;in = EEPROM.read(3);
att_l = EEPROM.read(4);att_r = EEPROM.read(5);gain1 = EEPROM.read(6);gain2 = EEPROM.read(7);
gain3 = EEPROM.read(8);gain4 = EEPROM.read(9);loud = EEPROM.read(10);ek = EEPROM.read(13);
w2_arr();audio();cl();
}
void loop() {
DateTime = clock.getDateTime();hour = DateTime.hour;minut = DateTime.minute;secon = DateTime.second;
if (newPosition != oldPosition||digitalRead(12)==LOW) {if(spek==1){cl();spek=0;w=0;menu0=0;menu=0;w2_arr();time0=millis();w=1;}}
/////////////////////////////// УПРАВЛЕНИЕ //////////////////////////////////////////////
if(mute==0&&power==0){
if(menu0==0){menu++;gr1=0;gr2=0;cl1();time0=millis();w=1;w2_arr();if(menu>2){menu=0;}}//меню 1
if(menu0==0){menu--;gr1=0;gr2=0;cl1();time0=millis();w=1;w2_arr();if(menu<0){menu=2;}}//меню 1
if(menu0==1){menu1++;gr1=0;gr2=0;cl1();time0=millis();w=1;if(menu1>3){menu1=0;}}//меню 2
if(menu0==1){menu1--;gr1=0;gr2=0;cl1();time0=millis();w=1;if(menu1<0){menu1=3;}}//меню 2
if(digitalRead(12)==LOW){pin2++;}if(digitalRead(12)==HIGH){pin2=0;}
if(digitalRead(12)==LOW&&menu0==0){menu++;delay(200);time0=millis();w=1;w2_arr();if(menu>2){menu=0;}}// меню 0
if(digitalRead(12)==LOW&&menu0==1){menu1++;delay(200);time0=millis();w=1;if(menu1>3){menu1=0;}}// меню 1
if((pin2>5)&&menu0==0){pin2=0;menu0=1;cl();time0=millis();w=1;lcd.setCursor(6,1);lcd.print("SETTING"); delay(2000);lcd.clear();}
if((pin2>5)&&menu0==1){pin2=0;menu0=0;menu=0;cl();w2_arr();time0=millis();w=1;lcd.setCursor(8,1);lcd.print("MENU"); delay(2000);lcd.clear();}
if(digitalRead(8)==HIGH){in++;cl();time0=millis();w=1;times_in=millis();in_x=1;www=1;w=1;menu0=100;if(in>3){in=0;}}// IN
}
if(digitalRead(9)==HIGH){delay(5);pin++;}
if((pin>0&&pin<10&&digitalRead(9)==LOW)&&mute==0&&power==0){pin=0;mute=1;pt.setAttR(31);pt.setAttL(31);menu0=100;cl();w=1;w2_arr();lcd.setCursor(8,1);lcd.print("MUTE");delay(300);}// mute on
if((pin>0&&pin<10&&digitalRead(9)==LOW)&&mute==1&&power==0){pin=0;mute=0;cl();time0=millis();w=1;w2_arr();menu0=0;myEnc.write(0);audio();}// mute off
if((pin>10)&&power==0){pin=0;power=1;save=1;pt.setAttR(31);pt.setAttL(31);cl();lcd.setCursor(5,1);lcd.print("POWER OFF");menu0=100;delay(3000);}// power off
if((pin>0)&&power==1){pin=0;power=0;lcd.clear();lcd.setCursor(5,1);lcd.print("POWER ON ");time0=millis();w=1;w2_arr();menu0=0;myEnc.write(0);audio();delay(3000);cl();}// power on
/////////////////////////////////////////////////////////////////////////////////////////////
if(power==0){digitalWrite(13,HIGH);
if(spek==0){
byte v1[8] = {0b00000,0b10101,0b10101,0b10101,0b10101,0b10101,0b10101,0b00000};
byte v2[8] = {0b00000,0b10100,0b10100,0b10100,0b10100,0b10100,0b10100,0b00000};
byte v3[8] = {0b00000,0b10000,0b10000,0b10000,0b10000,0b10000,0b10000,0b00000};
byte v4[8] = {0b10000,0b11000,0b11100,0b11110,0b11100,0b11000,0b10000,0b00000}; //>
byte v5[8] = {0b00000,0b00000,0b00000,0b00000,0b00000,0b00000,0b00000,0b00000};
lcd.createChar(0,v1);lcd.createChar(1,v2);lcd.createChar(2,v3);lcd.createChar(3,v4);lcd.createChar(4,v5);}
}
if(power==1){digitalWrite(13,LOW);
byte v1[8] = {7,7,7,7,7,7,7,7};
byte v2[8] = {7,7,0, 0, 0, 0, 0, 0};
byte v3[8] = { 0, 0, 0, 0, 0,0,31,31};
byte v4[8] = {31,31, 0, 0, 0, 0,31,31};
byte v5[8] = { 28, 28, 0, 0, 0, 0, 28, 28};
byte v6[8] = {28,28,28,28,28,28,28,28};
byte v7[8] = { 0, 0, 0, 0, 0, 0,7,7};
byte v8[8] = { 31, 31,0,0,0,0,0, 0};
byte a[6];
byte i0,d1,d2,d3,d4,d5,d6,e1,e2,e3;
lcd.createChar(1, v1);lcd.createChar(2, v2);lcd.createChar(3, v3);lcd.createChar(4, v4);lcd.createChar(5, v5);lcd.createChar(6, v6);lcd.createChar(7, v7);lcd.createChar(8, v8);
a[0]=DateTime.hour/10;
a[1]=DateTime.hour%10;
a[2]=DateTime.minute/10;
a[3]=DateTime.minute%10;
a[4]=DateTime.second/10;
a[5]=DateTime.second%10;
for(i=0;i<6;i++){
switch(i){
case 0: e1=0,e2=1,e3=2;break;
case 1: e1=3,e2=4,e3=5;break;
case 2: e1=7,e2=8,e3=9;break;
case 3: e1=10,e2=11,e3=12;break;
case 4: e1=14,e2=15,e3=16;break;
case 5: e1=17,e2=18,e3=19;break;
}
switch(a[i]){
case 0: d1=1,d2=8,d3=6,d4=1,d5=3,d6=6;break;
case 1: d1=32,d2=2,d3=6,d4=32,d5=32,d6=6;break;
case 2: d1=2,d2=8,d3=6,d4=1,d5=4,d6=5;break;
case 3: d1=2,d2=4,d3=6,d4=7,d5=3,d6=6;break;
case 4: d1=1,d2=3,d3=6,d4=32,d5=32,d6=6;break;
case 5: d1=1,d2=4,d3=5,d4=7,d5=3,d6=6;break;
case 6: d1=1,d2=4,d3=5,d4=1,d5=3,d6=6;break;
case 7: d1=1,d2=8,d3=6,d4=32,d5=32,d6=6;break;
case 8: d1=1,d2=4,d3=6,d4=1,d5=3,d6=6;break;
case 9: d1=1,d2=4,d3=6,d4=7,d5=3,d6=6;break;
}
lcd.setCursor(e1,0);lcd.write((uint8_t)d1);lcd.setCursor(e2,0);lcd.write((uint8_t)d2);lcd.setCursor(e3,0);lcd.write((uint8_t)d3);
lcd.setCursor(e1,1);lcd.write((uint8_t)d4);lcd.setCursor(e2,1);lcd.write((uint8_t)d5);lcd.setCursor(e3,1);lcd.write((uint8_t)d6);
}
lcd.setCursor(6,0);lcd.print(".");lcd.setCursor(13,0);lcd.print(".");lcd.setCursor(6,1);lcd.print(".");lcd.setCursor(13,1);lcd.print(".");
lcd.setCursor(5,3);lcd.print("POWER OFF");
//// set time //////
if(digitalRead(12)==LOW){hms++;cl();delay(200);if(hms>3){hms=0;}}
switch(hms){
case 1: lcd.setCursor(1,2);lcd.print("------");break;
case 2: lcd.setCursor(7,2);lcd.print("------");break;
case 3: lcd.setCursor(14,2);lcd.print("------");break;
}
if(digitalRead(8)==HIGH&&hms==1){hour++;if(hour>23){hour=0;} clock.setDateTime(2020, 9, 15, hour, minut, secon);delay(100);}
if(digitalRead(8)==HIGH&&hms==2){minut++;if(minut>59){minut=0;} clock.setDateTime(2020, 9, 15, hour, minut, secon);delay(100); }
if(digitalRead(8)==HIGH&&hms==3){secon=0; clock.setDateTime(2020, 9, 15, hour, minut, secon);hms=0; }
}
/////////////////////////////// MENU0 = VOLUME TERBLE BASS BALANCE ///////////////////////////////////////////////////////////////////////
if(menu0==0){
switch(menu){
case 0: temp0 = vol;q=0;break;
case 1: temp0 = bass;q=1;break;
case 2: temp0 = treb;q=2;break;}
if (newPosition != oldPosition){oldPosition = newPosition;
temp0=temp0+newPosition;myEnc.write(0);newPosition=0;time0=millis();w=1;w2[q]=1;www=1;}
switch(menu){
case 0: vol = temp0;vol_func();break;
case 1: bass = temp0;bass_func();break;
case 2: treb = temp0;treb_func();break;}
au();
for(i=0;i<3;i++){if(menu==i){lcd.setCursor(0,i);lcd.write((uint8_t)3);}else{lcd.setCursor(0,i);lcd.print(" ");}}
lcd.setCursor(1,0);lcd.print("VOLUME ");if(vol>=0){lcd.print(" ");}lcd.print(vol);lcd.print(" ");vol_d=map(vol,0,56,1,24);
lcd.setCursor(1,1);lcd.print("BASS ");if(bass>=0){lcd.print(" ");}lcd.print(bass);lcd.print(" ");bass_d=map(bass,-7,7,1,24);
lcd.setCursor(1,2);lcd.print("TREBLE ");if(treb>=0){lcd.print(" ");}lcd.print(treb);lcd.print(" ");treb_d=map(treb,-7,7,1,24);
lcd.setCursor(1,3);lcd.print("INPUT ");lcd.print(in+1);lcd.print(" ");
lcd.print(DateTime.hour/10);lcd.print(DateTime.hour%10);lcd.print(":");lcd.print(DateTime.minute/10);lcd.print(DateTime.minute%10);lcd.print(":");
lcd.print(DateTime.second/10);lcd.print(DateTime.second%10);
for(n=0;n<3;n++){if(w2[n]==1){
switch(n){
case 0: par = vol_d;break;
case 1: par = bass_d;break;
case 2: par = treb_d;break;}
for(z=0,z0=0,z1=0;z<=par;z++,z1++){if(z1>2){z1=0;z0++;}
if(z1==1){lcd.setCursor(z0+12,n);lcd.write((uint8_t)0);lcd.setCursor(z0+1+12,n);Serial.println(z0);z_old=7-par/3;while(z_old>0){z_old=z_old-1;lcd.write((uint8_t)4);}}}
if(z1==3){lcd.setCursor(z0+12,n);lcd.write((uint8_t)1);}
if(z1==2){lcd.setCursor(z0+12,n);lcd.write((uint8_t)2);}w2[n]=0;}
}}// menu0 = 0
///////////////////////////////////////////////////////////////////////////////////////////////
if(menu0==1){
switch(menu1){
case 0: temp0 = att_l;break;
case 1: temp0 = att_r;break;
case 2: temp0 = loud;break;
case 3: temp0 = ek;break;
}
if (newPosition != oldPosition){oldPosition = newPosition;
temp0=temp0+newPosition;myEnc.write(0);newPosition=0;time0=millis();w=1;www=1;}
switch(menu1){
case 0: att_l = temp0;att_l_func();break;
case 1: att_r = temp0;att_r_func();break;
case 2: loud = temp0;loud_func();break;
case 3: ek = temp0;ek_func();break;
}
au();
for(i=0;i<4;i++){if(menu1==i){lcd.setCursor(pgm_read_byte(&mesto2[i]),pgm_read_byte(&mesto3[i]));lcd.write((uint8_t)3);}else{lcd.setCursor(pgm_read_byte(&mesto2[i]),pgm_read_byte(&mesto3[i]));lcd.print(" ");}}
lcd.setCursor(1,0);lcd.print("ATT_L ");lcd.print(att_l);lcd.print(" ");lcd.setCursor(12,0);lcd.print("ATT_R ");lcd.print(att_r);lcd.print(" ");
lcd.setCursor(1,1);lcd.print("LOUD ");if(loud==0){lcd.print("OFF");}else{lcd.print("ON ");}lcd.setCursor(12,1);lcd.print("SPEK ");lcd.print(ek);
} // menu0 = 1
////////////////////////// GAIN IN /////////////////////////////////////////////////////////////////////////////////////
if(in_x==1){ menu0=100;
switch(in){
case 0: gain0 = gain1;break;
case 1: gain0 = gain2;break;
case 2: gain0 = gain3;break;
case 3: gain0 = gain4;break;}
if (newPosition != oldPosition) {oldPosition = newPosition;
gain0=gain0+newPosition;myEnc.write(0);newPosition=0;time0=millis();times_in=millis();www=1;w=1;gain_func();}
switch(in){
case 0: gain1 = gain0;break;
case 1: gain2 = gain0;break;
case 2: gain3 = gain0;break;
case 3: gain4 = gain0;break;}
au();
lcd.setCursor(5,1);lcd.print("Gain IN ");lcd.print(in+1);lcd.setCursor(6,2);lcd.print(float(gain0*3.75));lcd.print(" ");lcd.print("dB ");
}
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
if(millis()-time0>10000&&w==1&&mute==0&&power==0){cl();w=0;spek=0;menu0=100;}
if(millis()-times_in>3000&&in_x==1&&mute==0&&power==0){cl();in_x=0;menu0=0;menu=0;w2_arr();}
if(save==1){save=0;
EEPROM.update(0,vol);EEPROM.update(1,treb+7);EEPROM.update(2,bass+7);EEPROM.update(3,in);
EEPROM.update(4,att_l);EEPROM.update(5,att_r);EEPROM.update(6,gain1);EEPROM.update(7,gain2);
EEPROM.update(8,gain3);EEPROM.update(9,gain4);EEPROM.update(10,loud);EEPROM.update(13,ek);}
}// loop
void ek_func(){if(ek>5){ek=5;}if(ek<0){ek=0;}}
void w2_arr(){w2[0]=1;w2[1]=1;w2[2]=1;w2[3]=1;}
void au(){if(www==1){audio();www=0;}}
void in_func(){if(in>3){in=3;}if(in<0){in=0;}}
void loud_func(){if(loud<0){loud=0;}if(loud>1){loud=1;}}
void gain_func(){if(gain0<0){gain0=0;}if(gain0>3){gain0=3;}}
void att_r_func(){if(att_r<0){att_r=0;}if(att_r>24){att_r=24;}}
void att_l_func(){if(att_l<0){att_l=0;}if(att_l>24){att_l=24;}}
void treb_func(){if(treb<-7){treb=-7;}if(treb>7){treb=7;}}
void bass_func(){if(bass<-7){bass=-7;}if(bass>7){bass=7;}}
void vol_func(){if(vol<0){vol=0;}if(vol>56){vol=56;}}
void cl(){spek=0;delay(300);lcd.clear();}
void cl1(){spek=0;delay(200);}
void audio(){
pt.setVolume(vol); // int 0...56 === -70...0 dB step 1.25 dB
pt.setAttL(att_l); // int 0...24 === 0...-30 db step 1.25 dB > int 31 === mute on
pt.setAttR(att_r); // int 0...24 === 0...-30 dB step 1.25 dB > int 31 === mute on
pt.setSwitch(in, loud, gain0);
// input int 0..3 === IN 1...4
// loudness int 0...1 === 1-on 0-off
// input gain int 0...3 === 0...11.25dB step 3.75 dB
pt.setBass(bass); // int -7...+7 === -14...+14 dB step 2 dB
pt.setTreble(treb); // int -7...+7 === -14...+14 dB step 2 dB
}
void to_Timer(){newPosition = myEnc.read()/4;}