Я забрал 4 дБ у громкости для баланса, будет немного тише при максимуме громкости.
#define IR_1 0x2FDD02F // Кнопка вверх
#define IR_2 0x2FD32CD // Кнопка вниз
#define IR_3 0x2FD906F // Кнопка >
#define IR_4 0x2FDF20D // Кнопка <
#define IR_5 0x2FD708F // Кнопка IN
#define IR_6 0x2FD6A95 // Кнопка MUTE
#define IR_7 0x2FD00FF // Кнопка POWER
#define IR_8 0x2FDB24D // Кнопка MENU
#include <Wire.h>
#include <TDA7468.h> //-V2-// http://forum.rcl-radio.ru/misc.php?action=pan_download&item=892&download=1
#include <EEPROM.h>
#include <boarddefs.h>
#include <IRremote.h> // http://rcl-radio.ru/wp-content/uploads/2019/06/IRremote.zip
#include <Encoder.h> // http://rcl-radio.ru/wp-content/uploads/2019/05/Encoder.zip
#include <MsTimer2.h> // http://rcl-radio.ru/wp-content/uploads/2018/11/MsTimer2.zip
#include <LiquidCrystal_I2C.h> //Библиотека - http://forum.rcl-radio.ru/misc.php?action=pan_download&item=45&download=1
LiquidCrystal_I2C lcd(0x27,16,2); // Устанавливаем дисплей
Encoder myEnc(8, 9);//CLK, DT
TDA7468 tda;
IRrecv irrecv(11); // D11 = IR
decode_results ir;
byte a1[8] = {0b00000,0b10101,0b10101,0b10101,0b10101,0b10101,0b10101,0b00000};
byte a2[8] = {0b00000,0b10100,0b10100,0b10100,0b10100,0b10100,0b10100,0b00000};
byte a3[8] = {0b00000,0b10000,0b10000,0b10000,0b10000,0b10000,0b10000,0b00000};
int power=0,menu,in,gain0,gain1,gain2,gain3,gain4,w,w2,www,vol,vol_d,z,z0,z1;
int bas,treb,in_x,gain_d,menu_high,mute_mic,menu0,mic_gain,menu1,sur_mode,sur_gain;
unsigned long oldPosition = -999,newPosition,times,times1,times_in;
int mix,buff,mod,rez,cur,dec,acl_mode,menu2,mv,mute=1,gr1,gr2,balanc;
void setup(){
Wire.begin();
Serial.begin(9600);irrecv.enableIRIn();
MsTimer2::set(1, to_Timer);MsTimer2::start();
lcd.init();lcd.backlight();irrecv.enableIRIn();
pinMode(10,INPUT); // SW кнопка энкодера
pinMode(12,INPUT_PULLUP); // INPUT LOW
pinMode(A0,INPUT_PULLUP); // INPUT HIGH
pinMode(A1,INPUT_PULLUP); // MUTE
pinMode(A2,INPUT_PULLUP); // POWER
pinMode(3,OUTPUT); // выход IN5
pinMode(2,OUTPUT); // выход POWER
lcd.createChar(0,a1);lcd.createChar(1,a2);lcd.createChar(2,a3);
if(EEPROM.read(100)!=0){for(int i=0;i<101;i++){EEPROM.update(i,0);}}
in=EEPROM.read(0);vol=EEPROM.read(1);gain1=EEPROM.read(2);gain2=EEPROM.read(3);gain3=EEPROM.read(4);
gain4=EEPROM.read(5);bas=EEPROM.read(6)-7;treb=EEPROM.read(7)-7;mute_mic=EEPROM.read(8);mic_gain=EEPROM.read(9);
buff=EEPROM.read(10);mix=EEPROM.read(11);sur_mode=EEPROM.read(12);sur_gain=EEPROM.read(13);
mod=EEPROM.read(14);rez=EEPROM.read(15);cur=EEPROM.read(16);dec=EEPROM.read(17);
acl_mode=EEPROM.read(18);mv=EEPROM.read(19);balanc=EEPROM.read(20)-4;
audio();
}
void loop(){
////////////////////// IR /////////////////////////////////////////////////
if ( irrecv.decode( &ir )) {Serial.print("0x");Serial.println( ir.value,HEX);irrecv.resume();times=millis();w=1;w2=1;}// IR приемник - чтение, в мониторе порта отображаются коды кнопок
if(ir.value==0){gr1=0;gr2=0;}// запрет нажатий не активных кнопок пульта
//// POWER
if((digitalRead(A2)==LOW||ir.value==IR_7)&&power==0){power=1;cl();menu_high=100;mute=0;audio();lcd.print(" POWER OFF ");delay(1000);lcd.noBacklight();}
if((digitalRead(A2)==LOW||ir.value==IR_7)&&power==1){power=0;cl();w=0;w2=1;mute=1;audio();lcd.backlight();lcd.print(" POWER ON ");delay(1000);menu_high=0;menu=0;cl();}
//// MUTE .......................................................................................................................
if((digitalRead(A1)==LOW||ir.value==IR_6)&&mute==1&&power==0){mute=0;cl();w=0;w2=1;lcd.print(" MUTE ");menu_high=100;audio();delay(500);}// mute on
if((digitalRead(A1)==LOW||ir.value==IR_6)&&mute==0&&power==0){mute=1;cl();times=millis();w=1;w2=1;menu=0;menu_high=0;audio();delay(500);}// mute off
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
if(mic_gain<4){digitalWrite(3,HIGH);}else{digitalWrite(3,LOW);} // IN5
if(power==0){digitalWrite(2,HIGH);}else{digitalWrite(2,LOW);}// POWER
// HIGH MENU //////////////////////////
if((digitalRead(A0)==LOW||ir.value==IR_8)&&power==0&&mute==1){menu_high++;cl();times=millis();w=1;w2=1,www=1;if(menu_high>3){menu_high=0;}
switch(menu_high){
case 0:lcd.setCursor(5,0);lcd.print(" MENU ");lcd.setCursor(0,1);lcd.print(" VOLUME ");break;
case 1:lcd.setCursor(5,0);lcd.print(" MENU ");lcd.setCursor(0,1);lcd.print(" SELECTION MIC ");break;
case 2:lcd.setCursor(5,0);lcd.print(" MENU ");lcd.setCursor(0,1);lcd.print(" SURROUND ");break;
case 3:lcd.setCursor(5,0);lcd.print(" MENU ");lcd.setCursor(0,1);lcd.print(" BASS ALC ");break;
}
delay(1000);cl();}
//////////////////////////////////////
if(digitalRead(10)==LOW && menu_high==0&&power==0&&mute==1){menu++;cl();delay(200);times=millis();w=1;w2=1,www=1;if(menu>3){menu=0;}}// LOW MENU VOLUME
if(ir.value==IR_1 && menu_high==0&&power==0&&mute==1){menu++;cl();delay(200);times=millis();w=1;w2=1,www=1;if(menu>3){menu=0;}}// LOW MENU VOLUME
if(ir.value==IR_2 && menu_high==0&&power==0&&mute==1){menu--;cl();delay(200);times=millis();w=1;w2=1,www=1;if(menu<0){menu=3;}}// LOW MENU VOLUME
if(digitalRead(10)==LOW && menu_high==1&&power==0&&mute==1){menu0++;cl();delay(200);times=millis();w=1;w2=1,www=1;if(menu0>1){menu0=0;}}// LOW MENU MIC
if(ir.value==IR_1 && menu_high==1&&power==0&&mute==1){menu0++;cl();delay(200);times=millis();w=1;w2=1,www=1;if(menu0>1){menu0=0;}}// LOW MENU MIC
if(ir.value==IR_2 && menu_high==1&&power==0&&mute==1){menu0--;cl();delay(200);times=millis();w=1;w2=1,www=1;if(menu0<0){menu0=1;}}// LOW MENU MIC
if(digitalRead(10)==LOW && menu_high==2&&power==0&&mute==1){menu1++;cl();delay(200);times=millis();w=1;w2=1,www=1;if(menu1>3){menu1=0;}}// LOW MENU SURROUND
if(ir.value==IR_1 && menu_high==2&&power==0&&mute==1){menu1++;cl();delay(200);times=millis();w=1;w2=1,www=1;if(menu1>3){menu1=0;}}// LOW MENU SURROUND
if(ir.value==IR_2 && menu_high==2&&power==0&&mute==1){menu1--;cl();delay(200);times=millis();w=1;w2=1,www=1;if(menu1<0){menu1=3;}}// LOW MENU SURROUND
if(digitalRead(10)==LOW && menu_high==3&&power==0&&mute==1){menu2++;cl();delay(200);times=millis();w=1;w2=1,www=1;if(menu2>5){menu2=0;}}// LOW MENU BASS ALC
if(ir.value==IR_1 && menu_high==3&&power==0&&mute==1){menu2++;cl();delay(200);times=millis();w=1;w2=1,www=1;if(menu2>5){menu2=0;}}// LOW MENU SURROUND
if(ir.value==IR_2 && menu_high==3&&power==0&&mute==1){menu2--;cl();delay(200);times=millis();w=1;w2=1,www=1;if(menu2<0){menu2=5;}}// LOW MENU SURROUND
if((digitalRead(12)==LOW||ir.value==IR_5)&&power==0){if(in_x==1){in++;};cl();times_in=millis();in_x=1;w2=1;www=1;menu=100;if(in>3){in=0;}}// INPUT
if(menu_high==0){
/////////////////////////////// VOLUME 0...62 ////////////////////////////////////////////////
if(menu==0){
if(ir.value==IR_3){vol++;gr1=1;gr2=0;cl1();w=1;w2=1;vol_func();audio();}// кнопка >
if(ir.value==0xFFFFFFFF and gr1==1){vol++;gr2=0;cl1();w=1;w2=1;;vol_func();audio();}// кнопка >>>>>>
if(ir.value==IR_4){vol--;gr1=0;gr2=1;cl1();w=1;w2=1;vol_func();audio();}// кнопка <
if(ir.value==0xFFFFFFFF and gr2==1){vol--;gr1=0;cl1();w=1;w2=1;vol_func();audio();}// кнопка <<<<<<
if (newPosition != oldPosition){oldPosition = newPosition;
vol=vol+newPosition;myEnc.write(0);newPosition=0;times=millis();w=1;w2=1;vol_func();audio();}
lcd.setCursor(0,0);lcd.print(("VOLUME "));
if(vol<10){lcd.setCursor(7,0);lcd.print(" ");}else{lcd.setCursor(8,0);}lcd.print(vol);
vol_d=map(vol, 0,58, 0, 48);
lcd.setCursor(12,0);
switch(in){
case 0: lcd.print(F("AUX1"));break;
case 1: lcd.print(F("AUX2"));break;
case 2: lcd.print(F("AUX3"));break;
case 3: lcd.print(F("AUX4"));break;}
if(w2==1){
for(z=0,z0=0,z1=0;z<=vol_d;z++,z1++){if(z1>2){z1=0;z0++;}
if(z1==1){lcd.setCursor(z0,1);lcd.write((uint8_t)0);lcd.setCursor(z0+1,1);lcd.print(F(" "));}}
if(z1==3){lcd.setCursor(z0,1);lcd.write((uint8_t)1);}
if(z1==2){lcd.setCursor(z0,1);lcd.write((uint8_t)2);}w2=0;}}
////////////////////// VOLUME END ////////////////////////////////////////////
///////////////////////// BASS +/-14 dB /////////////////////////////////////////////////////////
if(menu==1){
if(ir.value==IR_3){bas++;gr1=1;gr2=0;cl1();w=1;w2=1;bass_func();audio();}// кнопка >
if(ir.value==0xFFFFFFFF and gr1==1){bas++;gr2=0;cl1();w=1;w2=1;;bass_func();audio();}// кнопка >>>>>>
if(ir.value==IR_4){bas--;gr1=0;gr2=1;cl1();w=1;w2=1;bass_func();audio();}// кнопка <
if(ir.value==0xFFFFFFFF and gr2==1){bas--;gr1=0;cl1();w=1;w2=1;bass_func();audio();}// кнопка <<<<<<
if (newPosition != oldPosition) {
oldPosition = newPosition;
bas=bas+newPosition;myEnc.write(0);newPosition=0;times=millis();w=1;w2=1;bass_func();audio();}
lcd.setCursor(0,0);lcd.print(("BASS "));
if(bas*2>=0){lcd.print(F("+"));}lcd.print(bas*2);lcd.print(" ");lcd.setCursor(13,0);lcd.print(F("dB"));
if(w2==1){
for(z=0,z0=0,z1=0;z<=(bas+1)*2+14;z++,z1++){if(z1>2){z1=0;z0++;}
if(z1==1){lcd.setCursor(z0+3,1);lcd.write((uint8_t)0);lcd.setCursor(z0+1+3,1);lcd.print(F(" "));}}
if(z1==3){lcd.setCursor(z0+3,1);lcd.write((uint8_t)1);}
if(z1==2){lcd.setCursor(z0+3,1);lcd.write((uint8_t)2);}w2=0;}}
/////////////////////// END BASS //////////////////////////////////
///////////////////////// TREBLE +/-14 dB /////////////////////////////////////////////////////////
if(menu==2){
if(ir.value==IR_3){treb++;gr1=1;gr2=0;cl1();w=1;w2=1;treb_func();audio();}// кнопка >
if(ir.value==0xFFFFFFFF and gr1==1){treb++;gr2=0;cl1();w=1;w2=1;;treb_func();audio();}// кнопка >>>>>>
if(ir.value==IR_4){treb--;gr1=0;gr2=1;cl1();w=1;w2=1;treb_func();audio();}// кнопка <
if(ir.value==0xFFFFFFFF and gr2==1){treb--;gr1=0;cl1();w=1;w2=1;treb_func();audio();}// кнопка <<<<<<
if (newPosition != oldPosition) {
oldPosition = newPosition;
treb=treb+newPosition;myEnc.write(0);newPosition=0;times=millis();w=1;w2=1;treb_func();audio();}
lcd.setCursor(0,0);lcd.print(("TREBLE "));
if(treb*2>=0){lcd.print(F("+"));}lcd.print(treb*2);lcd.print(" ");lcd.setCursor(13,0);lcd.print(F("dB"));
if(w2==1){
for(z=0,z0=0,z1=0;z<=(treb+1)*2+14;z++,z1++){if(z1>2){z1=0;z0++;}
if(z1==1){lcd.setCursor(z0+3,1);lcd.write((uint8_t)0);lcd.setCursor(z0+1+3,1);lcd.print(F(" "));}}
if(z1==3){lcd.setCursor(z0+3,1);lcd.write((uint8_t)1);}
if(z1==2){lcd.setCursor(z0+3,1);lcd.write((uint8_t)2);}w2=0;}}
/////////////////////// END TREBLE //////////////////////////////////
///////////////////////// BALANCE +/-4 dB /////////////////////////////////////////////////////////
if(menu==3){
if(ir.value==IR_3){balanc++;gr1=1;gr2=0;cl1();w=1;w2=1;balanc_func();audio();}// кнопка >
if(ir.value==0xFFFFFFFF and gr1==1){balanc++;gr2=0;cl1();w=1;w2=1;;balanc_func();audio();}// кнопка >>>>>>
if(ir.value==IR_4){balanc--;gr1=0;gr2=1;cl1();w=1;w2=1;balanc_func();audio();}// кнопка <
if(ir.value==0xFFFFFFFF and gr2==1){balanc--;gr1=0;cl1();w=1;w2=1;balanc_func();audio();}// кнопка <<<<<<
if (newPosition != oldPosition) {
oldPosition = newPosition;
balanc=balanc+newPosition;myEnc.write(0);newPosition=0;times=millis();w=1;w2=1;balanc_func();audio();}
lcd.setCursor(0,0);lcd.print(("BALANCE "));
if(balanc>=0){lcd.print(F("+"));}lcd.print(balanc);lcd.print(" ");lcd.setCursor(13,0);lcd.print(F("dB"));
if(w2==1){
if(balanc<0){lcd.setCursor(balanc-2+7,1);lcd.print(" ");lcd.write((uint8_t)0);lcd.print(" ");}
if(balanc==0){lcd.setCursor(balanc-2+7,1);lcd.print(" ");lcd.write((uint8_t)0);lcd.write((uint8_t)0);lcd.print(" ");}
if(balanc>0){lcd.setCursor(balanc-2+8,1);lcd.print(" ");lcd.write((uint8_t)0);lcd.print(" ");}w2=0;}}
/////////////////////// END BALANCE //////////////////////////////////
} // end menu
////////////////////////// GAIN IN /////////////////////////////////////////////////////////////////////////////////////
if(in_x==1){ menu=100;menu0=100;menu1=100;menu2=100;
switch(in){
case 0: gain0 = gain1;break;
case 1: gain0 = gain2;break;
case 2: gain0 = gain3;break;
case 3: gain0 = gain3;break;}
if(ir.value==IR_3){gain0++;gr1=1;gr2=0;cl1();w=1;w2=1;gain_func();audio();}// кнопка >
if(ir.value==0xFFFFFFFF and gr1==1){gain0++;gr2=0;cl1();w=1;w2=1;;gain_func();audio();}// кнопка >>>>>>
if(ir.value==IR_4){gain0--;gr1=0;gr2=1;cl1();w=1;w2=1;gain_func();audio();}// кнопка <
if(ir.value==0xFFFFFFFF and gr2==1){gain0--;gr1=0;cl1();w=1;w2=1;gain_func();audio();}// кнопка <<<<<<
if (newPosition != oldPosition) {oldPosition = newPosition;
gain0=gain0+newPosition;myEnc.write(0);newPosition=0;times=millis();times_in=millis();www=1;w=1;w2=1;gain_func();}
switch(in){
case 0: gain1 = gain0;break;
case 1: gain2 = gain0;break;
case 2: gain3 = gain0;break;
case 3: gain3 = gain0;break;}
if(www==1){audio();www=0;}
lcd.setCursor(0,0);lcd.print("Gain AUX");lcd.print(in+1);lcd.setCursor(10,0);lcd.print(" ");lcd.print(gain0*2);lcd.print(" ");lcd.setCursor(14,0);lcd.print("dB");gain_d=gain0+1;
if(w2==1){
for(z=0,z0=0,z1=0;z<=gain_d*4;z++,z1++){if(z1>2){z1=0;z0++;}
if(z1==1){lcd.setCursor(z0+3,1);lcd.write((uint8_t)0);lcd.setCursor(z0+1+3,1);lcd.print(" ");}}
if(z1==3){lcd.setCursor(z0+3,1);lcd.write((uint8_t)1);}
if(z1==2){lcd.setCursor(z0+3,1);lcd.write((uint8_t)2);}} w2=0;
if(millis()-times_in>3000){in_x=0;cl();w2=1;menu=0;menu_high=0;}}
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
///// MENU MIC /////////////////////////////
if(menu_high==1){
if(menu0==0){
if(ir.value==IR_3){mute_mic++;gr1=1;gr2=0;cl1();w=1;w2=1;func_mic_gain();audio();}// кнопка >
if(ir.value==0xFFFFFFFF and gr1==1){mute_mic++;gr2=0;cl1();w=1;w2=1;;func_mic_gain();audio();}// кнопка >>>>>>
if(ir.value==IR_4){mute_mic--;gr1=0;gr2=1;cl1();w=1;w2=1;func_mic_gain();audio();}// кнопка <
if(ir.value==0xFFFFFFFF and gr2==1){mute_mic--;gr1=0;cl1();w=1;w2=1;func_mic_gain();audio();}// кнопка <<<<<<
if (newPosition != oldPosition){oldPosition = newPosition;
mute_mic=mute_mic+newPosition;myEnc.write(0);newPosition=0;times=millis();w=1;w2=1;func_mic_mute();audio();}
lcd.setCursor(0,0);lcd.print((" MUTE SELECTION "));
if(mute_mic==1){lcd.setCursor(0,1);lcd.print((" MUTE ON "));}
else{lcd.setCursor(0,1);lcd.print((" MUTE OFF "));}}
/////////////////
if(menu0==1){
if(ir.value==IR_3){mic_gain++;gr1=1;gr2=0;cl1();w=1;w2=1;func_mic_gain();audio();}// кнопка >
if(ir.value==0xFFFFFFFF and gr1==1){mic_gain++;gr2=0;cl1();w=1;w2=1;;func_mic_gain();audio();}// кнопка >>>>>>
if(ir.value==IR_4){mic_gain--;gr1=0;gr2=1;cl1();w=1;w2=1;func_mic_gain();audio();}// кнопка <
if(ir.value==0xFFFFFFFF and gr2==1){mic_gain--;gr1=0;cl1();w=1;w2=1;func_mic_gain();audio();}// кнопка <<<<<<
if (newPosition != oldPosition){oldPosition = newPosition;
mic_gain=mic_gain+newPosition;myEnc.write(0);newPosition=0;times=millis();w=1;w2=1;func_mic_gain();audio();}
lcd.setCursor(0,0);lcd.print(F(" MUTE GAIN "));
switch(mic_gain){
case 0: lcd.setCursor(0,1);lcd.print(F(" MIC GAIN 14 dB "));break;
case 1: lcd.setCursor(0,1);lcd.print(F(" MIC GAIN 10 dB "));break;
case 2: lcd.setCursor(0,1);lcd.print(F(" MIC GAIN 6 dB "));break;
case 3: lcd.setCursor(0,1);lcd.print(F(" MIC GAIN 0 dB "));break;
case 4: lcd.setCursor(0,1);lcd.print(F(" MIC OFF "));break;
}}}
///////////////////////////////////////////
///// MENU SURROUND /////////////////////////////
if(menu_high==2){
if(menu1==0){
if(ir.value==IR_3){sur_mode++;gr1=1;gr2=0;cl1();w=1;w2=1;func_sur_mode();audio();}// кнопка >
if(ir.value==0xFFFFFFFF and gr1==1){sur_mode++;gr2=0;cl1();w=1;w2=1;;func_sur_mode();audio();}// кнопка >>>>>>
if(ir.value==IR_4){sur_mode--;gr1=0;gr2=1;cl1();w=1;w2=1;func_sur_mode();audio();}// кнопка <
if(ir.value==0xFFFFFFFF and gr2==1){sur_mode--;gr1=0;cl1();w=1;w2=1;func_sur_mode();audio();}// кнопка <<<<<<
if (newPosition != oldPosition){oldPosition = newPosition;
sur_mode=sur_mode+newPosition;myEnc.write(0);newPosition=0;times=millis();w=1;w2=1;func_sur_mode();audio();}
lcd.setCursor(0,0);lcd.print(F(" SURROUND "));
if(sur_mode==1){lcd.setCursor(0,1);lcd.print(F(" ON "));}
else{lcd.setCursor(0,1);lcd.print(F(" OFF "));}}
//////////
if(menu1==1){
if(ir.value==IR_3){sur_gain++;gr1=1;gr2=0;cl1();w=1;w2=1;func_sur_gain();audio();}// кнопка >
if(ir.value==0xFFFFFFFF and gr1==1){sur_gain++;gr2=0;cl1();w=1;w2=1;;func_sur_gain();audio();}// кнопка >>>>>>
if(ir.value==IR_4){sur_gain--;gr1=0;gr2=1;cl1();w=1;w2=1;func_sur_gain();audio();}// кнопка <
if(ir.value==0xFFFFFFFF and gr2==1){sur_gain--;gr1=0;cl1();w=1;w2=1;func_sur_gain();audio();}// кнопка <<<<<<
if (newPosition != oldPosition){oldPosition = newPosition;
sur_gain=sur_gain+newPosition;myEnc.write(0);newPosition=0;times=millis();w=1;w2=1;func_sur_gain();audio();}
lcd.setCursor(0,0);lcd.print(F(" SURROUND "));
switch(sur_gain){
case 0: lcd.setCursor(0,1);lcd.print(F(" GAIN 0 dB "));break;
case 1: lcd.setCursor(0,1);lcd.print(F(" GAIN 6 dB "));break;
case 2: lcd.setCursor(0,1);lcd.print(F(" GAIN 9 dB "));break;
case 3: lcd.setCursor(0,1);lcd.print(F(" GAIN 12 dB "));break;
}}
//////////
if(menu1==2){
if(ir.value==IR_3){mix++;gr1=1;gr2=0;cl1();w=1;w2=1;func_mix();audio();}// кнопка >
if(ir.value==0xFFFFFFFF and gr1==1){mix++;gr2=0;cl1();w=1;w2=1;;func_mix();audio();}// кнопка >>>>>>
if(ir.value==IR_4){mix--;gr1=0;gr2=1;cl1();w=1;w2=1;func_mix();audio();}// кнопка <
if(ir.value==0xFFFFFFFF and gr2==1){mix--;gr1=0;cl1();w=1;w2=1;func_mix();audio();}// кнопка <<<<<<
if (newPosition != oldPosition){oldPosition = newPosition;
mix=mix+newPosition;myEnc.write(0);newPosition=0;times=millis();w=1;w2=1;func_mix();audio();}
lcd.setCursor(0,0);lcd.print(F(" MIXING "));
switch(mix){
case 0: lcd.setCursor(0,1);lcd.print(F("inverting : 100%"));break;
case 1: lcd.setCursor(0,1);lcd.print(F("inverting : 50% "));break;
case 2: lcd.setCursor(0,1);lcd.print(F("inverting : 25% "));break;
case 3: lcd.setCursor(0,1);lcd.print(F("inverting : 0% "));break;
case 4: lcd.setCursor(0,1);lcd.print(F("non-inver : 100%"));break;
case 5: lcd.setCursor(0,1);lcd.print(F("non-inver : 75%"));break;
case 6: lcd.setCursor(0,1);lcd.print(F("non-inver : 50%"));break;
case 7: lcd.setCursor(0,1);lcd.print(F(" MUTE "));break;
}}
////////
if(menu1==3){
if(ir.value==IR_3){buff++;gr1=1;gr2=0;cl1();w=1;w2=1;func_buff();audio();}// кнопка >
if(ir.value==0xFFFFFFFF and gr1==1){buff++;gr2=0;cl1();w=1;w2=1;;func_buff();audio();}// кнопка >>>>>>
if(ir.value==IR_4){buff--;gr1=0;gr2=1;cl1();w=1;w2=1;func_buff();audio();}// кнопка <
if(ir.value==0xFFFFFFFF and gr2==1){buff--;gr1=0;cl1();w=1;w2=1;func_buff();audio();}// кнопка <<<<<<
if (newPosition != oldPosition){oldPosition = newPosition;
buff=buff+newPosition;myEnc.write(0);newPosition=0;times=millis();w=1;w2=1;func_buff();audio();}
lcd.setCursor(0,0);lcd.print(F(" BUFFER GAIN "));
if(buff==1){lcd.setCursor(0,1);lcd.print(F(" 0 dB "));}
else{lcd.setCursor(0,1);lcd.print(F(" 6 dB "));}}
}
///////////////////////////////////////////
///// MENU BASS ALC /////////////////////////////
if(menu_high==3){
if(menu2==0){
if(ir.value==IR_3){acl_mode++;gr1=1;gr2=0;cl1();w=1;w2=1;func_acl_mode();audio();}// кнопка >
if(ir.value==0xFFFFFFFF and gr1==1){acl_mode++;gr2=0;cl1();w=1;w2=1;;func_acl_mode();audio();}// кнопка >>>>>>
if(ir.value==IR_4){acl_mode--;gr1=0;gr2=1;cl1();w=1;w2=1;func_acl_mode();audio();}// кнопка <
if(ir.value==0xFFFFFFFF and gr2==1){acl_mode--;gr1=0;cl1();w=1;w2=1;func_acl_mode();audio();}// кнопка <<<<<<
if (newPosition != oldPosition){oldPosition = newPosition;
acl_mode=acl_mode+newPosition;myEnc.write(0);newPosition=0;times=millis();w=1;w2=1;func_acl_mode();audio();}
lcd.setCursor(0,0);lcd.print(F(" ALC Mode "));
if(acl_mode==1){lcd.setCursor(0,1);lcd.print(F(" ON "));}
else{lcd.setCursor(0,1);lcd.print(F(" OFF "));}}
//////////
if(menu2==1){
if(ir.value==IR_3){dec++;gr1=1;gr2=0;cl1();w=1;w2=1;func_dec();audio();}// кнопка >
if(ir.value==0xFFFFFFFF and gr1==1){dec++;gr2=0;cl1();w=1;w2=1;;func_dec();audio();}// кнопка >>>>>>
if(ir.value==IR_4){dec--;gr1=0;gr2=1;cl1();w=1;w2=1;func_dec();audio();}// кнопка <
if(ir.value==0xFFFFFFFF and gr2==1){dec--;gr1=0;cl1();w=1;w2=1;func_dec();audio();}// кнопка <<<<<<
if (newPosition != oldPosition){oldPosition = newPosition;
dec=dec+newPosition;myEnc.write(0);newPosition=0;times=millis();w=1;w2=1;func_dec();audio();}
lcd.setCursor(0,0);lcd.print(F(" Detector "));
if(dec==1){lcd.setCursor(0,1);lcd.print(F(" ON "));}
else{lcd.setCursor(0,1);lcd.print(F(" OFF "));}}
//////////
if(menu2==2){
if(ir.value==IR_3){cur++;gr1=1;gr2=0;cl1();w=1;w2=1;func_cur();audio();}// кнопка >
if(ir.value==0xFFFFFFFF and gr1==1){cur++;gr2=0;cl1();w=1;w2=1;;func_cur();audio();}// кнопка >>>>>>
if(ir.value==IR_4){cur--;gr1=0;gr2=1;cl1();w=1;w2=1;func_cur();audio();}// кнопка <
if(ir.value==0xFFFFFFFF and gr2==1){cur--;gr1=0;cl1();w=1;w2=1;func_cur();audio();}// кнопка <<<<<<
if (newPosition != oldPosition){oldPosition = newPosition;
cur=cur+newPosition;myEnc.write(0);newPosition=0;times=millis();w=1;w2=1;func_cur();audio();}
lcd.setCursor(0,0);lcd.print(F("Release Current"));
if(cur==1){lcd.setCursor(0,1);lcd.print(F(" Circuit ON "));}
else{lcd.setCursor(0,1);lcd.print(F(" Circuit OFF "));}}
//////////
if(menu2==3){
if(ir.value==IR_3){rez++;gr1=1;gr2=0;cl1();w=1;w2=1;func_rez();audio();}// кнопка >
if(ir.value==0xFFFFFFFF and gr1==1){rez++;gr2=0;cl1();w=1;w2=1;;func_rez();audio();}// кнопка >>>>>>
if(ir.value==IR_4){rez--;gr1=0;gr2=1;cl1();w=1;w2=1;func_rez();audio();}// кнопка <
if(ir.value==0xFFFFFFFF and gr2==1){rez--;gr1=0;cl1();w=1;w2=1;func_rez();audio();}// кнопка <<<<<<
if (newPosition != oldPosition){oldPosition = newPosition;
rez=rez+newPosition;myEnc.write(0);newPosition=0;times=millis();w=1;w2=1;func_rez();audio();}
lcd.setCursor(0,0);lcd.print(F(" Attack Time "));
switch(rez){
case 0: lcd.setCursor(0,1);lcd.print(F(" Resistor 12.5k "));break;
case 1: lcd.setCursor(0,1);lcd.print(F(" Resistor 25.0k "));break;
case 2: lcd.setCursor(0,1);lcd.print(F(" Resistor 50.0k "));break;
case 3: lcd.setCursor(0,1);lcd.print(F(" Resistor 100 k "));break;
}}
//////////
if(menu2==4){
if(ir.value==IR_3){mv++;gr1=1;gr2=0;cl1();w=1;w2=1;func_mv();audio();}// кнопка >
if(ir.value==0xFFFFFFFF and gr1==1){mv++;gr2=0;cl1();w=1;w2=1;;func_mv();audio();}// кнопка >>>>>>
if(ir.value==IR_4){mv--;gr1=0;gr2=1;cl1();w=1;w2=1;func_mv();audio();}// кнопка <
if(ir.value==0xFFFFFFFF and gr2==1){mv--;gr1=0;cl1();w=1;w2=1;func_mv();audio();}// кнопка <<<<<<
if (newPosition != oldPosition){oldPosition = newPosition;
mv=mv+newPosition;myEnc.write(0);newPosition=0;times=millis();w=1;w2=1;func_mv();audio();}
lcd.setCursor(0,0);lcd.print(F(" Threshold "));
switch(mv){
case 0: lcd.setCursor(0,1);lcd.print(F(" 700 mVrms "));break;
case 1: lcd.setCursor(0,1);lcd.print(F(" 485 mVrms "));break;
case 2: lcd.setCursor(0,1);lcd.print(F(" 320 mVrms "));break;
case 3: lcd.setCursor(0,1);lcd.print(F(" 170 mVrms "));break;
}}
////////
if(menu2==5){
if(ir.value==IR_3){mod++;gr1=1;gr2=0;cl1();w=1;w2=1;func_mod();audio();}// кнопка >
if(ir.value==0xFFFFFFFF and gr1==1){mod++;gr2=0;cl1();w=1;w2=1;;func_mod();audio();}// кнопка >>>>>>
if(ir.value==IR_4){mod--;gr1=0;gr2=1;cl1();w=1;w2=1;func_mod();audio();}// кнопка <
if(ir.value==0xFFFFFFFF and gr2==1){mod--;gr1=0;cl1();w=1;w2=1;func_mod();audio();}// кнопка <<<<<<
if (newPosition != oldPosition){oldPosition = newPosition;
mod=mod+newPosition;myEnc.write(0);newPosition=0;times=millis();w=1;w2=1;func_mod();audio();}
lcd.setCursor(0,0);lcd.print(F(" MODE "));
if(mod==0){lcd.setCursor(0,1);lcd.print(F(" Fixed Resistor "));}
else{lcd.setCursor(0,1);lcd.print(F(" Adaptive "));}}
}
///////////////////////////////////////////
////////////// EEPROM ///////////////////////////////////////////////////
if(millis()-times>20000 && w==1 && power==0){
EEPROM.update(0,in);EEPROM.update(1,vol);
EEPROM.update(2,gain1);EEPROM.update(3,gain2);EEPROM.update(4,gain3);EEPROM.update(5,gain4);
EEPROM.update(6,bas+7);EEPROM.update(7,treb+7);EEPROM.update(8,mute_mic);EEPROM.update(9,mic_gain);
EEPROM.update(10,buff);EEPROM.update(11,mix);EEPROM.update(12,sur_mode);EEPROM.update(13,sur_gain);
EEPROM.update(14,mod);EEPROM.update(15,rez);EEPROM.update(16,cur);EEPROM.update(17,dec);
EEPROM.update(18,acl_mode);EEPROM.update(19,mv);EEPROM.update(20,balanc+4);
menu=0;w=0;w2=1;cl();menu_high=0;}
}
void func_mv(){if(mv>3){mv=0;}if(mv<0){mv=3;}}
void func_mod(){if(mod>1){mod=0;}if(mod<0){mod=1;}}
void func_rez(){if(rez>3){rez=0;}if(rez<0){rez=3;}}
void func_cur(){if(cur>1){cur=0;}if(cur<0){cur=1;}}
void func_dec(){if(dec>1){dec=0;}if(dec<0){dec=1;}}
void func_acl_mode(){if(acl_mode>1){acl_mode=0;}if(acl_mode<0){acl_mode=1;}}
void func_buff(){if(buff>1){buff=0;}if(buff<0){buff=1;}}
void func_mix(){if(mix>7){mix=0;}if(mix<0){mix=7;}}
void func_sur_gain(){if(sur_gain>3){sur_gain=0;}if(sur_gain<0){sur_gain=3;}}
void func_sur_mode(){if(sur_mode>1){sur_mode=0;}if(sur_mode<0){sur_mode=1;}}
void func_mic_gain(){if(mic_gain>4){mic_gain=0;}if(mic_gain<0){mic_gain=4;}}
void func_mic_mute(){if(mute_mic>1){mute_mic=0;}if(mute_mic<0){mute_mic=1;}}
void cl(){ir.value=0;delay(300);lcd.clear();}
void cl1(){ir.value=0;delay(100);}
void vol_func(){if(vol>58){vol=58;}if(vol<0){vol=0;}}
void balanc_func(){if(balanc>4){balanc=4;}if(balanc<-4){balanc=-4;}}
void gain_func(){if(gain0>7){gain0=7;}if(gain0<0){gain0=0;}}
void treb_func(){if(treb>7){treb=7;}if(treb<-7){treb=-7;}}
void bass_func(){if(bas>7){bas=7;}if(bas<-7){bas=-7;}}
void audio(){
tda.setInput(in,mute_mic,mic_gain); // INPUT SELECT & MIC - установки входных цепей и микрофонного входа;
// INPUT SELECT 0...4 === IN1...IN4 - выбор входа;
// MUTE (IN5) 0 off 1 on (IN5) - при включении входы IN1...IN4 переходят в режим MUTE, в звуковом тракте остаётся микрофон (вход IN5), если он активирован;
// MIC 0...3 === gain 14dB...0dB // mic 4 === OFF - активация микрофонного входа (IN5) и установка предусиления для него;
///////////////////////////////////////////////////////////////
tda.setGain(gain0); // INPUT GAIN - установка предварительного усиления;
// gain 0...7 === 0...14 dB step 2dB;
//////////////////////////////////////////////////////////////
tda.setSurround(sur_mode,sur_gain,mix,buff); // SURROUND - установки режима объёмного звука;
// SURROUND MODE 1 on 0 off - активация режима объёмного звука;
// GAIN 0...3 === 0...12 dB - предусиление фазоинверторов перед подмешиванием сигнала в соседний канал;
// MIXING 0...7 === inverting 100%, 50%, 25%, 0%, non inverting 100%, 75%, 50%, mute - установка режима фазоинверторов;
// BUFFER GAIN 1...0 === 0dB...6dB - установка режима буферного каскада;
tda.setVol_R(vol+balanc); // VOLUME R 0...62 - регулирование уровня правого канала;
tda.setVol_L(vol-balanc); // VOLUME L 0...62 - регулирование уровня левого канала;
tda.setTreb_Bass(treb,bas); // TREBLE & BASS SELECTION -14...14 step 2 dB - коррекция тона ВЧ-НЧ. Когда бас установлен в диапазоне-14dB...0dB, ALC автоматически переключается в положение "OFF";
tda.setOutput(mute); // OUTPUT - установка выхода;
// MUTE 0...1 === ON...OFF - активация режима MUTE для выхода всего звукового тракта;
tda.setAlc(acl_mode,dec,cur,rez,mv,mod); // BASS ALC - установки автоматической регулировки уровня низких частот;
// ALC Mode 1 on 0 off - включение/выключение режима автоматического регулирования;
// Detector 1 on 0 off - включение/выключение детектора НЧ составляющей на выходе;
// Release Current Circuit 1 on 0 off - включение/выключение источника тока;
// Attack Time Resistor 0...3 === 12k5, 25k, 50k, 100k - резистор делителя, формирующего сигнал управления системой ALC;
// Threshold 0...3 === 700mVrms, 485mVrms, 320mVrms, 170mVrms, - пороговые уровни ограничения НЧ сигнала на выходе;
// Attack Mode - режим резистора делителя Attack Time Resistor - 0...1 === MODE 1: Fixed Resistor ... MODE 2: Adaptive - фиксированное значение/адаптивное значение;
}
void to_Timer(){newPosition = myEnc.read()/4;}