#define STANDBY 0x807F827D //
#define INPUT_5 0x807F02FD //
#define AUX1 0x807FA25D //
#define AUX2 0x807F22DD //
#define AUX3 0x807F20DF //
#define AUX4 0x807F629D //
#define GAIN_UP 0x807F926D //
#define GAIN_DOWN 0x807FB04F //
#define MUTE 0x807FF00F //
#define FRONT_LR_UP 0x807F40BF //
#define FRONT_LR_DOWN 0x807FC03F //
#define REAR_LR_UP 0x807F00FF //
#define REAR_LR_DOWN 0x807F807F //
#define CEN_UP 0x807F50AF //
#define CEN_DOWN 0x807F609F //
#define SUB_UP 0x807FD02F //
#define SUB_DOWN 0x807FE01F //
#define VOLUME_UP 0x807F906F //
#define VOLUME_DOWN 0x807FA05F //
#define BASS_UP 0x807F48B7 //
#define BASS_DOWN 0x807FC837 //
#define TREBLE_UP 0x807F08F7 //
#define TREBLE_DOWN 0x807F8877 //
#define COAXIAL 0x807F42BD //
#include <boarddefs.h>
#include <IRremote.h> // http://rcl-radio.ru/wp-content/uploads/2019/06/IRremote.zip
#include <LiquidCrystal.h>
#include <24LC.h> // http://rcl-radio.ru/wp-content/uploads/2020/03/24LC-2.zip
#include <Wire.h>
#include <Encoder.h> // http://rcl-radio.ru/wp-content/uploads/2019/05/Encoder.zip
#include <R2S15902FP.h> // http://forum.rcl-radio.ru/misc.php?action=pan_download&item=686&download=1
Encoder myEnc(10, 11);// D10, D11 = CLK, DT
IRrecv irrecv(12); // D12 = IR
decode_results ir;
LiquidCrystal lcd(4, 5, 6, 7, 8, 9);// lcd = RS,E,D4,D5,D6,D7
EEPROM24LC eeprom(0x50); // A2=0, A1=0, A0=0
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};
unsigned long oldPosition = -999,newPosition,times,times1;
int x,xd,menu,in,vol,bas,treb, f_lr,r_lr,cen,sub,gain0;
byte power,vol_d,z,z0,z1,vol_old, gain1,gain2,gain3,gain4,gain_6;
bool www,gr1,gr2,w,w2,menu_in,in6,mute,coax;
void setup() {
OCR2A = 200; TCCR1B |= (1 << WGM22)|(1 << CS20)|(1 << CS21); TIMSK2 |= (1 << OCIE2A); // timer2
Wire.begin();lcd.begin(16, 2);irrecv.enableIRIn();Serial.begin(9600);
lcd.createChar(0,a1);lcd.createChar(1,a2);lcd.createChar(2,a3);
pinMode(DATA, OUTPUT); // D2 R2S15902FP
pinMode(CLK, OUTPUT); // D3 R2S15902FP
pinMode(13,INPUT); // encoder INPUT D13
pinMode(14,OUTPUT);// coax OUTPUT A0
pinMode(15,OUTPUT);// standby OUTPUT A1
if(eeprom.readWire(100)!=0){for(int i=0;i<101;i++){eeprom.writeWire(i,0);}}
lcd.setCursor(0,0);lcd.print(F(" dolby dts "));
lcd.setCursor(0,1);lcd.print(F(" digital audio "));
delay(1000);
lcd.clear();
vol = eeprom.readWire(0);in = eeprom.readWire(1);bas = eeprom.readWire(2);treb = eeprom.readWire(3);
f_lr = eeprom.readWire(4);r_lr = eeprom.readWire(5);cen = eeprom.readWire(6);sub = eeprom.readWire(7);
gain1 = eeprom.readWire(8);gain2 = eeprom.readWire(9);gain3 = eeprom.readWire(10);gain4 = eeprom.readWire(11);gain_6 = eeprom.readWire(12);
if(in<4){in6=0;}else{in6=1;}
audio();delay(100);
}
void loop() {
//////////////// INPUT MENU //////////////////////////////////////////////////////////
if(power==0){
if(digitalRead(13)==LOW && menu_in==0){x++;xd=1;delay(200);}
if(digitalRead(13)==HIGH && menu_in==0 && x>0){xd=1;x=0;times1=millis();}
if(x > 15){menu_in=1;lcd.clear();lcd.setCursor(0,0);lcd.print(F(" INPUT MENU "));delay(2000);lcd.clear(); times1 = millis();}
if(menu_in==1){menu=0;x=0;if(digitalRead(13)==LOW){times1 = millis();in++;if(in>4){in = 0;}
if(in<4){in6=0;}else{in6=1;} audio();delay(200); }
//gain
switch(in){
case 0: gain0 = gain1;break;
case 1: gain0 = gain2;break;
case 2: gain0 = gain3;break;
case 3: gain0 = gain4;break;
case 4: gain0 = gain_6;break;}
if (newPosition != oldPosition) {
oldPosition = newPosition;
gain0=gain0+newPosition;myEnc.write(0);newPosition=0;times=millis();times1=millis();w=1;w2=1;www=1;gain_func();audio();}
switch(in){
case 0: gain1 = gain0;break;
case 1: gain2 = gain0;break;
case 2: gain3 = gain0;break;
case 3: gain4 = gain0;break;
case 4: gain_6 = gain0;break;}
if(www==1){audio();www=0;}
lcd.setCursor(5,1);lcd.print(" ");lcd.print(gain0*2);lcd.print(" ");lcd.setCursor(8,1);lcd.print(F("dB"));
// end gain
lcd.setCursor(3,0);lcd.print(F("INPUT "));
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;
case 4: lcd.print(F(" 5.1"));break;}}
if(digitalRead(13)==HIGH && millis()-times1>5000 && menu_in==1){x=0;menu=-1;menu_in=0;times1=millis();lcd.clear();w2=1;}
if(digitalRead(13)==HIGH && xd == 1 && menu_in==0){menu++;times=millis();w=1;w2=1;xd=0;lcd.clear();if(menu>7){menu=0;}}
// Serial.println(menu);
}
///////////////// END INPUT MENU ///////////////////////////////////////////////////////
/////////////////////////////// IR ///////////////////////////////////////////////////////////////
if ( irrecv.decode( &ir )) {Serial.print(F("0x"));Serial.println( ir.value,HEX);irrecv.resume();times=millis();w=1;}// IR
if(ir.value==0){gr1=0;gr2=0;}
if(power==0){
// bass & treble
if((ir.value==0x2FDAA55 || ir.value==BASS_UP) && menu!=1){bas++;menu=1;cl();times=millis();w=1;w2=1;gr1=1;gr2=0;bass_func();audio();}
if((ir.value==0x2FDCA35 || ir.value==BASS_DOWN) && menu!=1){bas--;menu=1;cl();times=millis();w=1;w2=1;gr1=0;gr2=1;bass_func();audio();}
if((ir.value==0x2FDE817 || ir.value==TREBLE_UP) && menu!=2){treb++;menu=2;cl();times=millis();w=1;w2=1;gr1=1;gr2=0;treb_func();audio();}
if((ir.value==0x2FDA857 || ir.value==TREBLE_DOWN) && menu!=2){treb--;menu=2;cl();times=millis();w=1;w2=1;gr1=0;gr2=1;treb_func();audio();}
// mute
if((ir.value==0x2FD708F || ir.value==MUTE) && mute==0){mute=1;cl();vol_old=vol;vol=0;menu = 100;lcd.setCursor(6,0);lcd.print(F("MUTE"));audio();delay(300);}
if((ir.value==0x2FD708F || ir.value==MUTE) && mute==1){mute=0;cl();vol=vol_old;menu=0;w2=1;delay(300);}
// gain front output
if((ir.value==0x2FD807F || ir.value==FRONT_LR_UP) && menu!=3){f_lr++;menu=3;cl();times=millis();w=1;w2=1;gr1=1;gr2=0;front_func();audio();}
if((ir.value==0x2FDE21D || ir.value==FRONT_LR_DOWN) && menu!=3){f_lr--;menu=3;cl();times=millis();w=1;w2=1;gr1=0;gr2=1;front_func();audio();}
// gain rear output
if((ir.value==0x2FD02FD || ir.value==REAR_LR_UP) && menu!=4){r_lr++;menu=4;cl();times=millis();w=1;w2=1;gr1=1;gr2=0;rear_func();audio();}
if((ir.value==0x2FD827D || ir.value==REAR_LR_DOWN) && menu!=4){r_lr--;menu=4;cl();times=millis();w=1;w2=1;gr1=0;gr2=1;rear_func();audio();}
// gain center output
if((ir.value==0x2FD02 || ir.value==CEN_UP) && menu!=5){cen++;menu=5;cl();times=millis();w=1;w2=1;gr1=1;gr2=0;cen_func();audio();}
if((ir.value==0x2FD82 || ir.value==CEN_DOWN) && menu!=5){cen--;menu=5;cl();times=millis();w=1;w2=1;gr1=0;gr2=1;cen_func();audio();}
// gain sub output
if((ir.value==0x2FD0 || ir.value==SUB_UP) && menu!=6){sub++;menu=6;cl();times=millis();w=1;w2=1;gr1=1;gr2=0;sub_func();audio();}
if((ir.value==0x2FD8 || ir.value==SUB_DOWN) && menu!=6){sub--;menu=6;cl();times=millis();w=1;w2=1;gr1=0;gr2=1;sub_func();audio();}
// gain input
if((ir.value==0x2FD || ir.value==GAIN_UP) && menu!=7){gain0++;menu=7;cl();times=millis();w=1;w2=1;gr1=1;gr2=0;gain_func();audio();}
if((ir.value==0x2FD || ir.value==GAIN_DOWN) && menu!=7){gain0--;menu=7;cl();times=millis();w=1;w2=1;gr1=0;gr2=1;gain_func();audio();}
// aux1
if(ir.value==0x2FD629D || ir.value==AUX1){in=0;cl();times=millis();w=1;w2=1;in6=0;audio();}
if(ir.value==0x2FD22DD || ir.value==AUX2){in=1;cl();times=millis();w=1;w2=1;in6=0;audio();}
if(ir.value==0x2FD40BF || ir.value==AUX3){in=2;cl();times=millis();w=1;w2=1;in6=0;audio();}
if(ir.value==0x2FDA25D || ir.value==AUX4){in=3;cl();times=millis();w=1;w2=1;in6=0;audio();}
if(ir.value==0x2FDE01F || ir.value==INPUT_5){in=4;cl();times=millis();w=1;w2=1;in6=1;audio();}
// coax
if((ir.value==0x2FD2AD5 || ir.value==COAXIAL) && coax==0){coax=1;cl();times=millis();w=1;w2=1;digitalWrite(14,HIGH);lcd.setCursor(3,0);lcd.print(F("COAXIAL ON"));delay(2000);cl();}
if((ir.value==0x2FD2AD5 || ir.value==COAXIAL) && coax==1){coax=0;cl();times=millis();w=1;w2=1;digitalWrite(14,LOW);lcd.setCursor(3,0);lcd.print(F("COAXIAL OFF"));delay(2000);cl();}
}
// standby
if((ir.value==0x2FD00FF || ir.value==STANDBY) && power==0){power=1;cl();times=millis();w=1;w2=1;digitalWrite(15,HIGH);lcd.setCursor(3,0);lcd.print(F("STANDBY ON"));vol_old=vol;vol=0;menu = 0;audio();delay(500);}
if((ir.value==0x2FD00FF || ir.value==STANDBY) && power==1){power=0;cl();times=millis();w=1;w2=1;digitalWrite(15,LOW);lcd.setCursor(3,0);lcd.print(F("STANDBY OFF"));vol=vol_old;menu=0;audio();delay(2000);cl();}
/////////////////////////////// VOLUME -99...0 дБ ////////////////////////////////////////////////
if(menu==0 && menu_in==0 && power==0){
if(ir.value==0x2FD906F || ir.value==VOLUME_UP){vol++;gr1=1;gr2=0;clv();times=millis();w=1;w2=1;vol_func();audio();}// кнопка >
if(ir.value==0xFFFFFFFF and gr1==1){vol++;gr2=0;clv();times=millis();w=1;w2=1;vol_func();audio();}// кнопка >>>>>>
if(ir.value==0x2FDF20D || ir.value==VOLUME_DOWN){vol--;gr1=0;gr2=1;clv();times=millis();w=1;w2=1;vol_func();audio();}// кнопка <
if(ir.value==0xFFFFFFFF and gr2==1){vol--;gr1=0;clv();times=millis();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(F("VOLUME "));
if(vol<10){lcd.setCursor(8,0);}else{lcd.setCursor(7,0);}lcd.print(vol);
vol_d=map(vol, 0,99, 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;
case 4: lcd.print(F(" 5.1"));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==0x2FDAA55 || ir.value==BASS_UP){bas++;gr1=1;gr2=0;cl1();times=millis();w=1;w2=1;bass_func();audio();}// кнопка >
if(ir.value==0xFFFFFFFF and gr1==1){bas++;gr2=0;cl1();times=millis();w=1;w2=1;bass_func();audio();}// кнопка >>>>>>
if(ir.value==0x2FDCA35 || ir.value==BASS_DOWN){bas--;gr1=0;gr2=1;cl1();times=millis();w=1;w2=1;bass_func();audio();}// кнопка <
if(ir.value==0xFFFFFFFF and gr2==1){bas--;gr1=0;cl1();times=millis();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(F("BASS "));
if(bas*2-14>=0){lcd.print(F("+"));}lcd.print(bas*2-14);lcd.print(" ");lcd.setCursor(13,0);lcd.print(F("dB"));
if(w2==1){
for(z=0,z0=0,z1=0;z<=(bas+1)*2;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==0x2FDE817 || ir.value==TREBLE_UP){treb++;gr1=1;gr2=0;cl1();times=millis();w=1;w2=1;treb_func();audio();}// кнопка >
if(ir.value==0xFFFFFFFF and gr1==1){treb++;gr2=0;cl1();times=millis();w=1;w2=1;treb_func();audio();}// кнопка >>>>>>
if(ir.value==0x2FDA857 || ir.value==TREBLE_DOWN){treb--;gr1=0;gr2=1;cl1();times=millis();w=1;w2=1;treb_func();audio();}// кнопка <
if(ir.value==0xFFFFFFFF and gr2==1){treb--;gr1=0;cl1();times=millis();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(F("TREBLE "));
if(treb*2-14>=0){lcd.print(F("+"));}lcd.print(treb*2-14);lcd.print(" ");lcd.setCursor(13,0);lcd.print(F("dB"));
if(w2==1){
for(z=0,z0=0,z1=0;z<=(treb+1)*2;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 //////////////////////////////////
///////////////////////// GAIN FRONT LR 0...14 dB /////////////////////////////////////////////////////////
if(menu==3){
if(ir.value==0x2FD807F || ir.value==FRONT_LR_UP){f_lr++;gr1=1;gr2=0;cl1();times=millis();w=1;w2=1;front_func();audio();}// кнопка >
if(ir.value==0xFFFFFFFF and gr1==1){f_lr++;gr2=0;cl1();times=millis();w=1;w2=1;front_func();audio();}// кнопка >>>>>>
if(ir.value==0x2FDE21D || ir.value==FRONT_LR_DOWN){f_lr--;gr1=0;gr2=1;cl1();times=millis();w=1;w2=1;front_func();audio();}// кнопка <
if(ir.value==0xFFFFFFFF and gr2==1){f_lr--;gr1=0;cl1();times=millis();w=1;w2=1;front_func();audio();}// кнопка <<<<<<
if (newPosition != oldPosition) {
oldPosition = newPosition;
f_lr=f_lr+newPosition;myEnc.write(0);newPosition=0;times=millis();w=1;w2=1;front_func();audio();}
lcd.setCursor(0,0);lcd.print(F("FRONT "));
if(f_lr*2>=0){lcd.print(F("+"));}lcd.print(f_lr*2);lcd.print(" ");lcd.setCursor(13,0);lcd.print(F("dB"));
if(w2==1){
for(z=0,z0=0,z1=0;z<=(f_lr*2+1)*2;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 GAIN FRONT //////////////////////////////////
///////////////////////// GAIN REAR LR 0...14 dB /////////////////////////////////////////////////////////
if(menu==4){
if(ir.value==0x2FD02FD || ir.value==REAR_LR_UP){r_lr++;gr1=1;gr2=0;cl1();times=millis();w=1;w2=1;rear_func();audio();}// кнопка >
if(ir.value==0xFFFFFFFF and gr1==1){r_lr++;gr2=0;cl1();times=millis();w=1;w2=1;rear_func();audio();}// кнопка >>>>>>
if(ir.value==0x2FD827D || ir.value==REAR_LR_DOWN){r_lr--;gr1=0;gr2=1;cl1();times=millis();w=1;w2=1;rear_func();audio();}// кнопка <
if(ir.value==0xFFFFFFFF and gr2==1){r_lr--;gr1=0;cl1();times=millis();w=1;w2=1;rear_func();audio();}// кнопка <<<<<<
if (newPosition != oldPosition) {
oldPosition = newPosition;
r_lr=r_lr+newPosition;myEnc.write(0);newPosition=0;times=millis();w=1;w2=1;rear_func();audio();}
lcd.setCursor(0,0);lcd.print(F("REAR "));
if(r_lr*2>=0){lcd.print(F("+"));}lcd.print(r_lr*2);lcd.print(" ");lcd.setCursor(13,0);lcd.print(F("dB"));
if(w2==1){
for(z=0,z0=0,z1=0;z<=(r_lr*2+1)*2;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 GAIN REAR //////////////////////////////////
///////////////////////// GAIN CENTER LR 0...14 dB /////////////////////////////////////////////////////////
if(menu==5){
if(ir.value==0x2FD02F || ir.value==CEN_UP){cen++;gr1=1;gr2=0;cl1();times=millis();w=1;w2=1;cen_func();audio();}// кнопка >
if(ir.value==0xFFFFFFFF and gr1==1){cen++;gr2=0;cl1();times=millis();w=1;w2=1;cen_func();audio();}// кнопка >>>>>>
if(ir.value==0x2FD827 || ir.value==CEN_DOWN){cen--;gr1=0;gr2=1;cl1();times=millis();w=1;w2=1;cen_func();audio();}// кнопка <
if(ir.value==0xFFFFFFFF and gr2==1){cen--;gr1=0;cl1();times=millis();w=1;w2=1;cen_func();audio();}// кнопка <<<<<<
if (newPosition != oldPosition) {
oldPosition = newPosition;
cen=cen+newPosition;myEnc.write(0);newPosition=0;times=millis();w=1;w2=1;cen_func();audio();}
lcd.setCursor(0,0);lcd.print(F("CENTER "));
if(cen*2>=0){lcd.print(F("+"));}lcd.print(cen*2);lcd.print(" ");lcd.setCursor(13,0);lcd.print(F("dB"));
if(w2==1){
for(z=0,z0=0,z1=0;z<=(cen*2+1)*2;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 GAIN CENTER //////////////////////////////////
///////////////////////// GAIN SUB LR 0...14 dB /////////////////////////////////////////////////////////
if(menu==6){
if(ir.value==0x2FD02 || ir.value==SUB_UP){sub++;gr1=1;gr2=0;cl1();times=millis();w=1;w2=1;sub_func();audio();}// кнопка >
if(ir.value==0xFFFFFFFF and gr1==1){sub++;gr2=0;cl1();times=millis();w=1;w2=1;sub_func();audio();}// кнопка >>>>>>
if(ir.value==0x2FD82 || ir.value==SUB_DOWN){sub--;gr1=0;gr2=1;cl1();times=millis();w=1;w2=1;sub_func();audio();}// кнопка <
if(ir.value==0xFFFFFFFF and gr2==1){sub--;gr1=0;cl1();times=millis();w=1;w2=1;sub_func();audio();}// кнопка <<<<<<
if (newPosition != oldPosition) {
oldPosition = newPosition;
sub=sub+newPosition;myEnc.write(0);newPosition=0;times=millis();w=1;w2=1;sub_func();audio();}
lcd.setCursor(0,0);lcd.print(F("SUBWOOFER "));
if(sub*2>=0){lcd.print(F("+"));}lcd.print(sub*2);lcd.print(" ");lcd.setCursor(13,0);lcd.print(F("dB"));
if(w2==1){
for(z=0,z0=0,z1=0;z<=(sub*2+1)*2;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 GAIN SUB //////////////////////////////////
//////////////// INPUT GAIN /////////////////////////////////////////////////////////////
if(menu==7){
switch(in){
case 0: gain0 = gain1;break;
case 1: gain0 = gain2;break;
case 2: gain0 = gain3;break;
case 3: gain0 = gain4;break;
case 4: gain0 = gain_6;break;
}
if(ir.value==GAIN_UP){gain0++;gr1=1;gr2=0;cl1();times=millis();w=1;w2=1;www=1;gain_func();audio();}// кнопка >
if(ir.value==0xFFFFFFFF and gr1==1){gain0++;gr2=0;cl1();times=millis();w=1;w2=1;www=1;gain_func();audio();}// кнопка >>>>>>
if(ir.value==GAIN_DOWN){gain0--;gr1=0;gr2=1;cl1();times=millis();w=1;w2=1;www=1;gain_func();audio();}// кнопка <
if(ir.value==0xFFFFFFFF and gr2==1){gain0--;gr1=0;cl1();times=millis();w=1;w2=1;www=1;gain_func();audio();}// кнопка <<<<<<
if (newPosition != oldPosition) {
oldPosition = newPosition;
gain0=gain0+newPosition;myEnc.write(0);newPosition=0;times=millis();w=1;w2=1;www=1;gain_func();audio();}
switch(in){
case 0: gain1 = gain0;break;
case 1: gain2 = gain0;break;
case 2: gain3 = gain0;break;
case 3: gain4 = gain0;break;
case 4: gain_6 = gain0;break;
}
if(www==1){audio();www=0;}
lcd.setCursor(0,0); lcd.print(F("INPUT "));
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;
case 4: lcd.print(F(" 5.1"));break;}
lcd.setCursor(10,0);lcd.print(" ");lcd.print(gain0*2);lcd.print(" ");lcd.setCursor(13,0);lcd.print("dB");
if(w2==1){
for(z=0,z0=0,z1=0;z<=(gain0*2+1)*2;z++,z1++){if(z1>2){z1=0;z0++;}
if(z1==1){lcd.setCursor(z0+3,1);lcd.write((uint8_t)0);lcd.setCursor(z0+3+1,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 INPUT GAIN //////////////////////////////////////////////////////////////////////////
////////////// EEPROM ///////////////////////////////////////////////////
if(millis()-times>10000 && w==1 && power==0){
eeprom.writeWire(0,vol);eeprom.writeWire(1,in);eeprom.writeWire(2,bas);eeprom.writeWire(3,treb);
eeprom.writeWire(4,r_lr);eeprom.writeWire(5,r_lr);eeprom.writeWire(6,cen);eeprom.writeWire(7,sub);
eeprom.writeWire(8,gain1);eeprom.writeWire(9,gain2);eeprom.writeWire(10,gain3);eeprom.writeWire(11,gain4);eeprom.writeWire(12,gain_6);
menu=0;w=0;w2=1;cl();}
} // LOOP
void gain_func(){if(gain0>7){gain0=7;}if(gain0<0){gain0=0;}}
void sub_func(){if(sub>7){sub=7;}if(sub<0){sub=0;}}
void cen_func(){if(cen>7){cen=7;}if(cen<0){cen=0;}}
void rear_func(){if(r_lr>7){r_lr=7;}if(r_lr<0){r_lr=0;}}
void front_func(){if(f_lr>7){f_lr=7;}if(f_lr<0){f_lr=0;}}
void treb_func(){if(treb>14){treb=14;}if(treb<0){treb=0;}}
void bass_func(){if(bas>14){bas=14;}if(bas<0){bas=0;}}
void vol_func(){if(vol>99){vol=99;}if(vol<0){vol=0;}}
void cl(){ir.value=0;delay(300);lcd.clear();}
void cl1(){ir.value=0;delay(200);}
void clv(){ir.value=0;delay(100);}
void audio(){
Slot1(in,0,0,in6,bas,treb,gain0);
// input selector 1...4 === int 0...3, in4 === multi in
//REC-Output Gain Control int 0...6 dB === int 0...3
//ADC Input ATT 0...-6 dB === int 0...3
//L/R Input 0 === IN1...3, 1 === IN4 MULTI
//bass int 0 === +14dB int 8 === 0dB int 15 === -14dB
//treble int 0 === +14dB int 8 === 0dB int 15 === -14dB
//Input Gain 0...14 dB === int 0...7
Slot2(f_lr,99-vol,f_lr,99-vol); // gain0, volume0, gain1, volume1 // L/R
Slot3(cen,99-vol,sub,99-vol); // gain2, volume2, gain3, volume3 // C/SW
Slot4(r_lr,99-vol,r_lr,99-vol); // gain4, volume4, gain5, volume5 // SL/SR
// gain 0...14 dB === int 0...7
// volume 0...-99 dB === int 0...99
}
ISR (TIMER2_COMPA_vect){newPosition = myEnc.read()/4;}