#define IR_1 0xFF9186B7 // Кнопка вверх
#define IR_2 0x52A3D41F // Кнопка вниз
#define IR_3 0xD7E84B1B // Кнопка >
#define IR_4 0xEE886D7F // Кнопка <
#define IR_5 0x12209C7B // Кнопка IN
#define IR_6 0xF076C13B // Кнопка SET
#define IR_7 0x8AB3679B // Кнопка MUTE
#define IR_8 0x13549BDF // Кнопка STANDBY (POWER)
#define BRIG_H 200 // Яркость 0...255 POWER ON
#define BRIG_L 50 // Яркость 0...255 POWER OFF
#include <Wire.h>
#include <LiquidCrystal_I2C.h> // http://forum.rcl-radio.ru/misc.php?action=pan_download&item=45&download=1
#include <BD37534FV.h> // https://github.com/liman324/BD37534FV/archive/master.zip
#include <Encoder.h> // http://rcl-radio.ru/wp-content/uploads/2019/05/Encoder.zip
#include <EEPROM.h>
#include <MsTimer2.h> // http://rcl-radio.ru/wp-content/uploads/2018/11/MsTimer2.zip
#include <boarddefs.h>
#include <IRremote.h> // http://rcl-radio.ru/wp-content/uploads/2019/06/IRremote.zip
#include <DS3231.h> //https://github.com/jarzebski/Arduino-DS3231/archive/master.zip
BD37534FV bd;
DS3231 clock;RTCDateTime DateTime;
LiquidCrystal_I2C lcd(0x27,20,4); // Устанавливаем дисплей
IRrecv irrecv(11); // указываем вывод модуля IR приемника
Encoder myEnc(9, 8);// DT, CLK
decode_results ir;
unsigned long time0,times_in,oldPosition = -999,newPosition;
byte in,in_x,w,w1,w2[4],w3,z,z0,z1,q,i,n,www,gr1,gr2,mute,power;
int menu,menu0,menu1,menu2,vol,bass,treb,mid,vol_d,bass_d,treb_d,mid_d,in_time;
int temp0,gain0,gain1,gain2,gain3,gain_d;
int bass_f,bass_q,treb_f,treb_q,mid_f,mid_q,loud_f,loud_g;
int lf,rf,lr,rr,sub,sub_f,faza,par,hour,minut,secon,date,mont,year,korr;
const PROGMEM byte mesto[8] ={4,13,4,13,4,13,4,13};
const PROGMEM byte mesto1[8]={0,0,1,1,2,2,3,3};
const PROGMEM byte mesto2[7]={0,11,0,11,11,0,11};
const PROGMEM byte mesto3[7]={0,0,1,1,2,3,3};
char * bass_nam[4] ={"60 Hz", "80 Hz", "100 Hz", "120 Hz"};
char * treb_nam[4]= {"7.5 kHz", "10 kHz", "12.5kHz", "15 kHz"};
char * mid_nam[4] ={"500 Hz", "1 kHz", "1.5 kHz", "2.5 kHz"};
char * lon_nam[4] ={"250 Hz", "400 Hz", "800 Hz", "disable"};
char * sub_nam[5] ={" OFF ", " 55 Hz", " 85 Hz", " 120 Hz", " 160 Hz"};
const PROGMEM float bass_nam_1[4]={0.5, 1.0, 1.5, 2.0};
const PROGMEM float mid_nam_1[4]={0.75, 1.0, 1.25, 1.5};
const PROGMEM float treb_nam_1[2]={0.75, 1.25};
bool power_off=1;
String dn[]={" ","DUW","SEW","CHO","PAY","JUM","SHA","YAK"};
void setup() {
irrecv.enableIRIn();lcd.init();lcd.backlight();clock.begin();Serial.begin(9600);
pinMode(10,INPUT); // МЕНЮ КНОПКА SW энкодера
pinMode(2,INPUT_PULLUP); // КНОПКА SET
pinMode(3,INPUT_PULLUP); // КНОПКА IN
pinMode(4,INPUT_PULLUP); // КНОПКА MUTE
pinMode(5,INPUT_PULLUP); // КНОПКА STANDBY
pinMode(7,OUTPUT); // ВЫХОД УПРАВЛЕНИЯ STANDBY
pinMode(6,OUTPUT); // ВЫХОД УПРАВЛЕНИЯ ПОДСВЕТКОЙ
pinMode(12,OUTPUT); // ВЫХОД УПРАВЛЕНИЯ Bluetooth
analogWrite(6, BRIG_H);// больше 200 не делать
lcd.setCursor(3,1);lcd.print("Sound Processor");lcd.setCursor(7,2);lcd.print("BD37534FV"); delay(2000);lcd.clear();
MsTimer2::set(4, to_Timer);MsTimer2::start();
if(EEPROM.read(100)!=0){for(int i=0;i<101;i++){EEPROM.update(i,0);}}// очистка памяти при первом включении
vol = EEPROM.read(0)-79;treb = EEPROM.read(1)-20;mid = EEPROM.read(2)-20;bass = EEPROM.read(3)-20;
in = EEPROM.read(4);gain1 = EEPROM.read(5);gain2 = EEPROM.read(6);gain3 = EEPROM.read(7);
bass_f = EEPROM.read(8);bass_q = EEPROM.read(9);treb_f = EEPROM.read(10);treb_q = EEPROM.read(11);
mid_f = EEPROM.read(12);mid_q = EEPROM.read(13);loud_f = EEPROM.read(14);loud_g= EEPROM.read(15);
lf = EEPROM.read(16)-79;rf = EEPROM.read(17)-79;lr = EEPROM.read(18)-79;rr = EEPROM.read(19)-79;sub = EEPROM.read(20)-79;sub_f = EEPROM.read(21);
faza = EEPROM.read(22);
w2_arr();audio();cl();
//clock.begin();// Инициализируем работу с объектом библиотеки DS3231
// УСТАНОВКА ВРЕМЕНИ
// clock.setDateTime(2016, 9, 15, 0, 0, 0);// Установка времени вручную (Год, Месяц, День, Час, Минута, Секунда)
}
void to_Timer(){newPosition = myEnc.read()/4;}
void loop() {
DateTime = clock.getDateTime();hour = DateTime.hour;minut = DateTime.minute;secon = DateTime.second;
date = DateTime.day;mont = DateTime.month;year = DateTime.year;byte wesk = DateTime.dayOfWeek;
/////////////////////////////// УПРАВЛЕНИЕ //////////////////////////////////////////////
if ( irrecv.decode( &ir )) {Serial.print("0x");Serial.println( ir.value,HEX);irrecv.resume();}// IR приемник - чтение, в мониторе порта отображаются коды кнопок
if(ir.value==0){gr1=0;gr2=0;}// запрет нажатий не активных кнопок пульта
if(power==0){
if(mute==1){
if(digitalRead(10)==LOW&&menu0==0){menu++;delay(200);time0=millis();w=1;w2_arr();if(menu>3){menu=0;}}// меню 0
if(digitalRead(10)==LOW&&menu0==1){menu1++;delay(200);time0=millis();w=1;if(menu1>7){menu1=0;}}// меню 1
if(digitalRead(10)==LOW&&menu0==2){menu2++;delay(200);time0=millis();w=1;if(menu2>6){menu2=0;}}// меню 2
if(ir.value==IR_2&&menu0==0){menu++;gr1=0;gr2=0;cl1();time0=millis();w=1;if(menu>3){menu=0;}}// кнопка вверх
if(ir.value==IR_1&&menu0==0){menu--;gr1=0;gr2=0;cl1();time0=millis();w=1;if(menu<0){menu=3;}}// кнопка вниз
if(ir.value==IR_2&&menu0==1){menu1++;gr1=0;gr2=0;cl1();time0=millis();w=1;if(menu1>7){menu1=0;}}// кнопка вверх
if(ir.value==IR_1&&menu0==1){menu1--;gr1=0;gr2=0;cl1();time0=millis();w=1;if(menu1<0){menu1=7;}}// кнопка вниз
if(ir.value==IR_2&&menu0==2){menu2++;gr1=0;gr2=0;cl1();time0=millis();w=1;if(menu2>6){menu2=0;}}// кнопка вверх
if(ir.value==IR_1&&menu0==2){menu2--;gr1=0;gr2=0;cl1();time0=millis();w=1;if(menu2<0){menu2=6;}}// кнопка вниз
if(ir.value==IR_6||digitalRead(2)==LOW){menu0++;if(menu0>2){menu0=0;}cl();in_x=0;w2_arr();time0=millis();w=1;lcd.setCursor(5,1);
lcd.print("SETTING_");lcd.print(menu0);delay(500);lcd.clear();}
if(ir.value==IR_5||digitalRead(3)==LOW){in++;gr1=0;gr2=0;cl();times_in=millis();in_x=1;w3=1;www=1;menu0=100;if(in>2){in=0;}}// кнопка IN
} // mute off
if((ir.value==IR_7||digitalRead(4)==LOW)&&mute==1&&power==0){mute=0;in_x=0;mute=0;menu0=100;cl();w=1;w2_arr();lcd.setCursor(8,1);lcd.print("MUTE");audio();delay(300);}// mute on
if((ir.value==IR_7||digitalRead(4)==LOW)&&mute==0&&power==0){mute=1;cl();time0=millis();w=1;w2_arr();menu0=0;menu=0;myEnc.write(0);audio();}// mute off
}// power on
if((ir.value==IR_8||digitalRead(5)==LOW||power_off==1)&&power==0){power_off=0;power=1;in_x=0;mute=0;cl();audio();lcd.setCursor(5,1);lcd.print("POWER OFF");menu0=100;delay(3000);analogWrite(6,BRIG_L);}// power off
if((ir.value==IR_8||digitalRead(5)==LOW)&&power==1){power=0;analogWrite(6, BRIG_H);cl();lcd.setCursor(5,1);lcd.print("POWER ON ");w=1;w2_arr();menu0=0;myEnc.write(0);mute=1;audio();delay(3000);cl();}// power on
if(power==0){digitalWrite(7,HIGH);
if(in==2){digitalWrite(12,HIGH);}else{digitalWrite(12,LOW);}
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};
byte a4[8] = {0b10000,0b11000,0b11100,0b11110,0b11100,0b11000,0b10000,0b00000}; //>
byte a5[8] = {0b00000,0b00000,0b00000,0b00000,0b00000,0b00000,0b00000,0b00000};
lcd.createChar(0,a1);lcd.createChar(1,a2);lcd.createChar(2,a3);lcd.createChar(3,a4);lcd.createChar(4,a5);
}
if(power==1){digitalWrite(7,LOW);digitalWrite(12,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(int 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(0,3);lcd.print(date/10);lcd.print(date%10),lcd.print(".");lcd.print(mont/10);lcd.print(mont%10);lcd.print(".");lcd.print(year);lcd.print(" ");
lcd.print(clock.readTemperature(),1);lcd.print((char)223);lcd.print(" ");
lcd.print(dn[wesk]);
//lcd.setCursor(5,3);lcd.print("POWER OFF");
if(digitalRead(10)==LOW&&digitalRead(2)==LOW){korr++;if(korr>6){korr=0;}delay(100);} // SET
if(digitalRead(10)==LOW&&digitalRead(3)==LOW&&korr==1){hour++;if(hour>23){hour=23;} clock.setDateTime(year, mont, date, hour, minut, secon);delay(100);} // IN
if(digitalRead(10)==LOW&&digitalRead(4)==LOW&&korr==1){hour--;if(hour<0){hour=0;} clock.setDateTime(year, mont, date, hour, minut, secon);delay(100);} // MUTE
if(digitalRead(10)==LOW&&digitalRead(3)==LOW&&korr==2){minut++;if(minut>59){minut=59;} clock.setDateTime(year, mont, date, hour, minut, secon);delay(100);}
if(digitalRead(10)==LOW&&digitalRead(4)==LOW&&korr==2){minut--;if(minut<0){minut=0;} clock.setDateTime(year, mont, date, hour, minut, secon);delay(100);}
if(digitalRead(10)==LOW&&digitalRead(3)==LOW&&korr==3){secon=0;clock.setDateTime(year, mont, date, hour, minut, secon);delay(100);}
if(digitalRead(10)==LOW&&digitalRead(4)==LOW&&korr==3){secon=0;clock.setDateTime(year, mont, date, hour, minut, secon);delay(100);}
if(digitalRead(10)==LOW&&digitalRead(3)==LOW&&korr==4){date++;if(date>31){date=31;} clock.setDateTime(year, mont, date, hour, minut, secon);delay(100);}
if(digitalRead(10)==LOW&&digitalRead(4)==LOW&&korr==4){date--;if(date<1){date=1;} clock.setDateTime(year, mont, date, hour, minut, secon);delay(100);}
if(digitalRead(10)==LOW&&digitalRead(3)==LOW&&korr==5){mont++;if(mont>12){mont=12;} clock.setDateTime(year, mont, date, hour, minut, secon);delay(100);}
if(digitalRead(10)==LOW&&digitalRead(4)==LOW&&korr==5){mont--;if(mont<1){mont=1;} clock.setDateTime(year, mont, date, hour, minut, secon);delay(100);}
if(digitalRead(10)==LOW&&digitalRead(3)==LOW&&korr==6){year++;if(year>2050){year=2050;} clock.setDateTime(year, mont, date, hour, minut, secon);delay(100);}
if(digitalRead(10)==LOW&&digitalRead(4)==LOW&&korr==6){year--;if(year<2022){year=2022;} clock.setDateTime(year, mont, date, hour, minut, secon);delay(100);}
lcd.setCursor(0,2);
switch(korr){
case 0 : lcd.print(" ");lcd.print(" ");break;
case 1 : lcd.print("Time correction ");lcd.print("HOUR");break;
case 2 : lcd.print("Time correction ");lcd.print("MIN ");break;
case 3 : lcd.print("Time correction ");lcd.print("SEC ");break;
case 4 : lcd.print("Time correction ");lcd.print("DATE");break;
case 5 : lcd.print("Time correction ");lcd.print("MON ");break;
case 7 : lcd.print("Time correction ");lcd.print("YEAR");break;
}
}
/////////////////////////////// MENU0 = VOLUME TERBLE MIDDLE BASS ///////////////////////////////////////////////////////////////////////
if(menu0==0){
switch(menu){
case 0: temp0 = vol;q=0;break;
case 1: temp0 = bass;q=1;break;
case 2: temp0 = mid;q=2;break;
case 3: temp0 = treb;q=3;break;}
if(ir.value==IR_3){temp0++;gr1=1;gr2=0;cl1();time0=millis();w=1;w2[q]=1;www=1;}// кнопка >
if(ir.value==0xFFFFFFFF and gr1==1){temp0++;gr2=0;cl1();time0=millis();;w=1;w2[q]=1;www=1;}// кнопка >>>>>>
if(ir.value==IR_4){temp0--;gr1=0;gr2=1;cl1();time0=millis();;w=1;w2[q]=1;www=1;}// кнопка <
if(ir.value==0xFFFFFFFF and gr2==1){temp0--;gr1=0;cl1();time0=millis();w=1;w2[q]=1;www=1;}// кнопка <<<<<<
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: mid = temp0;mid_func();break;
case 3: treb = temp0;treb_func();break;}
au();
for(i=0;i<4;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,-79,15,0,24);
lcd.setCursor(1,1);lcd.print("BASS ");if(bass>=0){lcd.print(" ");}lcd.print(bass);lcd.print(" ");bass_d=map(bass,-20,20,0,24);
lcd.setCursor(1,2);lcd.print("MIDDLE ");if(mid>=0){lcd.print(" ");}lcd.print(mid);lcd.print(" ");mid_d=map(mid,-20,20,0,24);
lcd.setCursor(1,3);lcd.print("TREBLE ");if(treb>=0){lcd.print(" ");}lcd.print(treb);lcd.print(" ");treb_d=map(treb,-20,20,0,24);
for(n=0;n<4;n++){if(w2[n]==1){
switch(n){
case 0: par = vol_d;break;
case 1: par = bass_d;break;
case 2: par = mid_d;break;
case 3: 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);lcd.print(" ");}}
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
///////////////////////////////////////////////////////////////////////////////////////////////
///////////////////// MENU 2 ////////////////////////////////////////////////////////
if(menu0==1){
switch(menu1){
case 0: temp0 = bass_f;break;
case 1: temp0 = bass_q;break;
case 2: temp0 = mid_f;break;
case 3: temp0 = mid_q;break;
case 4: temp0 = treb_f;break;
case 5: temp0 = treb_q;break;
case 6: temp0 = loud_f;break;
case 7: temp0 = loud_g;break;}
if(ir.value==IR_3){temp0++;gr1=1;gr2=0;cl1();time0=millis();w=1;www=1;}// кнопка >
if(ir.value==0xFFFFFFFF and gr1==1){temp0++;gr2=0;cl1();time0=millis();w=1;www=1;}// кнопка >>>>>>
if(ir.value==IR_4){temp0--;gr1=0;gr2=1;cl1();time0=millis();;w=1;www=1;}// кнопка <
if(ir.value==0xFFFFFFFF and gr2==1){temp0--;gr1=0;cl1();time0=millis();w=1;www=1;}// кнопка <<<<<<
if (newPosition != oldPosition){oldPosition = newPosition;
temp0=temp0+newPosition;myEnc.write(0);newPosition=0;time0=millis();w=1;www=1;}
switch(menu1){
case 0: bass_f = temp0;bass_f_func();break;
case 1: bass_q = temp0;bass_q_func();break;
case 2: mid_f = temp0;mid_f_func();break;
case 3: mid_q = temp0;mid_q_func();break;
case 4: treb_f = temp0;treb_f_func();break;
case 5: treb_q = temp0;treb_q_func();break;
case 6: loud_f = temp0;loud_f_func();break;
case 7: loud_g = temp0;loud_g_func();break;}
au();
for(i=0;i<8;i++){if(menu1==i){lcd.setCursor(pgm_read_byte(&mesto[i]),pgm_read_byte(&mesto1[i]));lcd.write((uint8_t)3);}else{lcd.setCursor(pgm_read_byte(&mesto[i]),pgm_read_byte(&mesto1[i]));lcd.print(" ");}}
lcd.setCursor(0,0);lcd.print("BASS");lcd.setCursor(5,0);lcd.print(bass_nam[bass_f]);lcd.setCursor(14,0);lcd.print("Q ");lcd.print(pgm_read_float(&bass_nam_1[bass_q]));
lcd.setCursor(0,1);lcd.print("MIDD");lcd.setCursor(5,1);lcd.print(mid_nam[mid_f]);lcd.setCursor(14,1);lcd.print("Q ");lcd.print(pgm_read_float(&mid_nam_1[mid_q]));
lcd.setCursor(0,2);lcd.print("TREB");lcd.setCursor(5,2);lcd.print(treb_nam[treb_f]);lcd.setCursor(14,2);lcd.print("Q ");lcd.print(pgm_read_float(&treb_nam_1[treb_q]));
lcd.setCursor(0,3);lcd.print("LOUD");lcd.setCursor(5,3);lcd.print(lon_nam[loud_f]);lcd.setCursor(14,3);lcd.print("G ");lcd.print(loud_g/10);lcd.print(loud_g%10);lcd.setCursor(18,3);lcd.print("dB");
}// menu0 = 1
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
if(menu0==2){
switch(menu2){
case 0: temp0 = lf;break;
case 1: temp0 = rf;break;
case 2: temp0 = lr;break;
case 3: temp0 = rr;break;
case 4: temp0 = faza;break;
case 5: temp0 = sub;break;
case 6: temp0 = sub_f;break;}
if(ir.value==IR_3){temp0++;gr1=1;gr2=0;cl1();time0=millis();w=1;www=1;}// кнопка >
if(ir.value==0xFFFFFFFF and gr1==1){temp0++;gr2=0;cl1();time0=millis();w=1;www=1;}// кнопка >>>>>>
if(ir.value==IR_4){temp0--;gr1=0;gr2=1;cl1();time0=millis();;w=1;www=1;}// кнопка <
if(ir.value==0xFFFFFFFF and gr2==1){temp0--;gr1=0;cl1();time0=millis();w=1;www=1;}// кнопка <<<<<<
if (newPosition != oldPosition){oldPosition = newPosition;
temp0=temp0+newPosition;myEnc.write(0);newPosition=0;time0=millis();w=1;www=1;}
switch(menu2){
case 0: lf = temp0;lf_func();break;
case 1: rf = temp0;rf_func();break;
case 2: lr = temp0;lr_func();break;
case 3: rr = temp0;rr_func();break;
case 4: faza = temp0;faza_func();break;
case 5: sub = temp0;sub_func();break;
case 6: sub_f = temp0;sub_f_func();break;}
au();
for(i=0;i<7;i++){if(menu2==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("LF");lcd.setCursor(4,0);lcd.print(lf);lcd.print(" ");lcd.setCursor(7,0);lcd.print(" dB");lcd.setCursor(12,0);lcd.print("RF");lcd.print(rf);lcd.print(" ");lcd.setCursor(18,0);lcd.print("dB");
lcd.setCursor(1,1);lcd.print("LR");lcd.setCursor(4,1);lcd.print(lr);lcd.print(" ");lcd.setCursor(7,1);lcd.print(" dB");lcd.setCursor(12,1);lcd.print("RR");lcd.print(rr);lcd.print(" ");lcd.setCursor(18,1);lcd.print("dB");
lcd.setCursor(1,2);lcd.print("Subwoofer");lcd.setCursor(12,2);lcd.print("Faza ");if(faza==0){lcd.print(" 0");}else{lcd.print("180");}
lcd.setCursor(1,3);lcd.print("G ");lcd.setCursor(4,3);lcd.print(sub);lcd.print(" ");lcd.setCursor(7,3);lcd.print(" dB");lcd.setCursor(12,3);lcd.print(sub_nam[sub_f]);
} // menu0 = 2
////////////////////////// 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;}
if(ir.value==IR_3){gain0++;gr1=1;gr2=0;cl1();time0=millis();times_in=millis();www=1;w=1;w3=1;gain_func();}// кнопка >
if(ir.value==0xFFFFFFFF and gr1==1){gain0++;gr2=0;cl1();time0=millis();times_in=millis();www=1;w=1;w3=1;gain_func();}// кнопка >>>>>>
if(ir.value==IR_4){gain0--;gr1=0;gr2=1;cl1();time0=millis();times_in=millis();www=1;w=1;w3=1;gain_func();}// кнопка <
if(ir.value==0xFFFFFFFF and gr2==1){gain0--;gr1=0;cl1();time0=millis();times_in=millis();www=1;w=1;w3=1;gain_func();}// кнопка <<<<<<
if (newPosition != oldPosition) {oldPosition = newPosition;
gain0=gain0+newPosition;myEnc.write(0);newPosition=0;time0=millis();times_in=millis();www=1;w=1;w3=1;gain_func();}
switch(in){
case 0: gain1 = gain0;break;
case 1: gain2 = gain0;break;
case 2: gain3 = gain0;break;}
au();
lcd.setCursor(2,1);lcd.print("Gain IN ");lcd.print(in+1);lcd.setCursor(12,1);lcd.print(" ");lcd.print(gain0);lcd.print(" ");lcd.setCursor(16,1);lcd.print("dB");gain_d=gain0+1;
if(w3==1){
for(z=0,z0=0,z1=0;z<=gain_d;z++,z1++){if(z1>2){z1=0;z0++;}
if(z1==1){lcd.setCursor(z0+7,2);lcd.write((uint8_t)0);lcd.setCursor(z0+1+7,2);lcd.print(" ");}}
if(z1==3){lcd.setCursor(z0+7,2);lcd.write((uint8_t)1);}
if(z1==2){lcd.setCursor(z0+7,2);lcd.write((uint8_t)2);}} w3=0;
if(millis()-times_in>3000){in_x=0;cl();menu0=0;w2_arr();}}
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
///////////////////// EEPROM ///////////////////////////////////////////////////////////////
if(millis()-time0>10000 && w==1){
EEPROM.update(0,vol+79);EEPROM.update(1,treb+20);EEPROM.update(2,mid+20);EEPROM.update(3,bass+20);
EEPROM.update(4,in);EEPROM.update(5,gain1);EEPROM.update(6,gain2);EEPROM.update(7,gain3);
EEPROM.update(8,bass_f);EEPROM.update(9,bass_q);EEPROM.update(10,treb_f);EEPROM.update(11,treb_q),
EEPROM.update(12,mid_f);EEPROM.update(13,mid_q);EEPROM.update(14,loud_f);EEPROM.update(15,loud_g);
EEPROM.update(16,lf+79);EEPROM.update(17,rf+79);EEPROM.update(18,lr+79);EEPROM.update(19,rr+79);EEPROM.update(20,sub+79);EEPROM.update(21,sub_f);
EEPROM.update(22,faza);
menu=0;menu1=0;menu2=0;w=0;w2_arr();}
}// loop
void faza_func(){if(faza>1){faza=0;}if(faza<0){faza=1;}}
void sub_f_func(){if(sub_f>4){sub_f=0;}if(sub_f<0){sub_f=4;}}
void lf_func(){if(lf<-79){lf=-79;}if(lf>15){lf=15;}};
void rf_func(){if(rf<-79){rf=-79;}if(rf>15){rf=15;}};
void lr_func(){if(lr<-79){lr=-79;}if(lr>15){lr=15;}};
void rr_func(){if(rr<-79){rr=-79;}if(rr>15){rr=15;}};
void sub_func(){if(sub<-79){sub=-79;}if(sub>15){sub=15;}};
void au(){if(www==1){audio();www=0;}}
void loud_f_func(){if(loud_f>3){loud_f=0;}if(loud_f<0){loud_f=3;}}
void loud_g_func(){if(loud_g>20){loud_g=20;}if(loud_g<0){loud_g=0;}}
void mid_q_func(){if(mid_q>3){mid_q=0;}if(mid_q<0){mid_q=3;}}
void treb_q_func(){if(treb_q>1){treb_q=0;}if(treb_q<0){treb_q=1;}}
void bass_q_func(){if(bass_q>3){bass_q=0;}if(bass_q<0){bass_q=3;}}
void mid_f_func(){if(mid_f>3){mid_f=0;}if(mid_f<0){mid_f=3;}}
void treb_f_func(){if(treb_f>3){treb_f=0;}if(treb_f<0){treb_f=3;}}
void bass_f_func(){if(bass_f>3){bass_f=0;}if(bass_f<0){bass_f=3;}}
void gain_func(){if(gain0<0){gain0=0;}if(gain0>20){gain0=20;}}
void bass_func(){if(bass>20){bass=20;}if(bass<-20){bass=-20;}}
void mid_func(){if(mid>20){mid=20;}if(mid<-20){mid=-20;}}
void treb_func(){if(treb>20){treb=20;}if(treb<-20){treb=-20;}}
void vol_func(){if(vol<-79){vol=-79;}if(vol>15){vol=15;}}
void w2_arr(){w2[0]=1;w2[1]=1;w2[2]=1;w2[3]=1;}
void cl(){ir.value=0;delay(300);lcd.clear();}
void cl1(){ir.value=0;delay(200);}
void audio(){
bd.setSetup_1(1,2,0); // default (1,2,0)
bd.setSetup_2(sub_f,1,0,faza);
// int sub_f ------ OFF 55Hz 85Hz 120Hz 160Hz = int 0...4
// int sub_out ---- LPF Front Rear Prohibition = int 0...3
// int level_metr - HOLD REST = int 0..1
// int faza ------- 0 180 = int 0...1
bd.setLoudness_f(loud_f); // 250Hz 400Hz 800Hz Prohibition = int 0...3
bd.setIn(in); // 0...2
bd.setIn_gain(gain0,mute); // in_gain -- 0...20 = 0...20 dB, mute -- 0 default
bd.setVol(vol); // -79...+15 dB = int -79...15
bd.setFront_1(rf); // -79...+15 dB = int -79...15
bd.setFront_2(lf); // -79...+15 dB = int -79...15
bd.setRear_1(rr); // -79...+15 dB = int -79...15
bd.setRear_2(lr); // -79...+15 dB = int -79...15
bd.setSub(sub); // -79...+15 dB = int -79...15
bd.mix();
bd.setBass_setup(bass_q,bass_f); // 0.5 1.0 1.5 2.0 --- int 0...3, 60Hz 80Hz 100Hz 120Hz --- int 0...3
bd.setMiddle_setup(mid_q,mid_f); // 0.75 1.0 1.25 1.5 --- int 0...3, 500Hz 1kHz 1.5kHz 2.5kHz --- int 0...3
bd.setTreble_setup(treb_q,treb_f); // 0.75 1.25 --- int 0...1, 7.5kHz 10kHz 12.5kHz 15kHz --- int 0...3
bd.setBass_gain(bass); // --20 ... +20 dB = int -20 ... 20
bd.setMiddle_gain(mid); // --20 ... +20 dB = int -20 ... 20
bd.setTreble_gain(treb); // --20 ... +20 dB = int -20 ... 20
bd.setLoudness_gain(loud_g); // 0 ... 20 dB = int 0 ... 20
}