#define UP 0x33B810EF
#define DOWN 0x33B8E01F
#define MENU 0x33B820DF
#define MUTE 0x33B8946B
#define IN 0x33B8C03F
#define POWER 0x33B800FF
#define BRIG_L 50
#define BRIG_H 250
#include <TDA7433.h> // http://rcl-radio.ru/wp-content/uploads/2021/08/TDA7433.zip
#include <Wire.h> // Входит в состав Arduino IDE
#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 <EEPROM.h> // Входит в состав Arduino IDE
#include <LiquidCrystal_I2C.h> // http://forum.rcl-radio.ru/misc.php?action=pan_download&item=45&download=1
#include <boarddefs.h> // Входит в состав библиотеки IRremote
#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
LiquidCrystal_I2C lcd(0x27,16,2); // Устанавливаем дисплей
TDA7433 tda;
Encoder myEnc(9, 8);//CLK, DT подключение энкодера
decode_results ir;
IRrecv irrecv(12); // указываем вывод модуля IR приемника
DS3231 clock;
RTCDateTime DateTime;
byte v1[8] = {0x07,0x07,0x07,0x07,0x07,0x07,0x07,0x07};
byte v2[8] = {0x07,0x07,0x00,0x00,0x00,0x00,0x00,0x00};
byte v3[8] = {0x00,0x00,0x00,0x00,0x00,0x00,0x1F,0x1F};
byte v4[8] = {0x1F,0x1F,0x00,0x00,0x00,0x00,0x1F,0x1F};
byte v5[8] = {0x1C,0x1C,0x00,0x00,0x00,0x00,0x1C,0x1C};
byte v6[8] = {0x1C,0x1C,0x1C,0x1C,0x1C,0x1C,0x1C,0x1C};
byte v7[8] = {0x00,0x00,0x00,0x00,0x00,0x00,0x07,0x07};
byte v8[8] = {0x1F,0x1F,0x00,0x00,0x00,0x00,0x00,0x00};
unsigned long time,oldPosition = -999,newPosition;
byte i,d1,d2,d3,d4,d5,d6,e1,e2,e3,w,w1,gr1,gr2,power=0;
int a[6],menu,fun_d,vol,in,bass,treb,menu_set=100,mute;
int lf,rf,lr,rr,lf_old,rf_old,lr_old,rr_old;
int hour,secon,minut,x;
void setup(){
Wire.begin();Serial.begin(9600);irrecv.enableIRIn();
MsTimer2::set(3, to_Timer);MsTimer2::start();
lcd.init();lcd.backlight();clock.begin();
// clock.setDateTime(__DATE__, __TIME__); // Устанавливаем время на часах, основываясь на времени компиляции скетча
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);
pinMode(6,OUTPUT); // PWM output
analogWrite(6,BRIG_H);
lcd.setCursor(4,0);lcd.print("TDA7433");delay(1000);lcd.clear();// ЗАСТАВКА
pinMode(10,INPUT); // КНОПКА ЭНКОДЕРA
pinMode(2,INPUT_PULLUP); // INPUT
pinMode(3,INPUT_PULLUP); // SET
pinMode(4,INPUT_PULLUP); // MUTE
pinMode(5,INPUT_PULLUP); // POWER
pinMode(13,OUTPUT); // OUTPUT STANDBY
vol = EEPROM.read(0)-79;bass = EEPROM.read(1)-9;treb = EEPROM.read(2)-7;in = EEPROM.read(3);
lr = EEPROM.read(4);rr = EEPROM.read(5);lf = EEPROM.read(6);rf = EEPROM.read(7);
audio();
}
void loop(){
//////// IR ////////////////////////////////////////////////////////////////////
if ( irrecv.decode( &ir )) {Serial.print("0x");Serial.println( ir.value,HEX);irrecv.resume();delay(50);}// IR приемник - чтение, в мониторе порта отображаются коды кнопок
if(ir.value==0){gr1=0;gr2=0;}// запрет нажатий не активных кнопок пульта
//////// BUTTON ////////////////////////////////////////////////////////////////
if(power==0){
if(mute==0){
if(((digitalRead(10)==LOW||ir.value==MENU)&&menu_set==100)){menu++;cl();myEnc.write(0);time=millis();w=1;w1=1;if(menu>2){menu=0;}}// menu
if((digitalRead(10)==LOW&&menu==100)){menu_set++;cl();myEnc.write(0);time=millis();w=1;w1=1;if(menu_set>3){menu_set=0;}}// menu
if(digitalRead(2)==LOW||ir.value==IN){in++;cl();myEnc.write(0);time=millis();w=1;w1=1;if(in>2){in=0;}lcd.setCursor(4,0);lcd.print("INPUT ");lcd.print(in+1);audio();delay(1500);cl();}// input
if(digitalRead(3)==LOW&&menu_set==100){menu_set=0;menu=100;cl();myEnc.write(0);time=millis();w=1;w1=1;lcd.setCursor(4,0);lcd.print("SET MENU");delay(1500);cl();}// menu
if(digitalRead(3)==LOW&&menu_set<100){menu_set=100;menu=0;cl();myEnc.write(0);time=millis();w=1;w1=1;lcd.setCursor(3,0);lcd.print("MAIN MENU");delay(1500);cl();}// menu
}
if((digitalRead(4)==LOW||ir.value==MUTE)&&mute==0){mute=1;cl();lf_old=lf,rf_old=rf,lr_old=lr,rr_old=rr; lf=32,rf=32,lr=32,rr=32;menu=100;menu_set=100;myEnc.write(0);audio();lcd.setCursor(6,0);lcd.print("MUTE");}
if((digitalRead(4)==LOW||ir.value==MUTE)&&mute==1){mute=0;cl();lf=lf_old,rf=rf_old,lr=lr_old,rr=rr_old;menu=0;w=1;myEnc.write(0);time=millis();audio();cl();}
}else{menu=100;menu_set=100;}
// standby output
if(power==0){digitalWrite(13,HIGH);}else{digitalWrite(13,LOW);}
/// power ///
if((digitalRead(5)==LOW||ir.value==POWER)&&power==0){power=1;menu=100;menu_set=100;analogWrite(6,BRIG_L);cl();myEnc.write(0);
lf_old=lf,rf_old=rf,lr_old=lr,rr_old=rr; lf=32,rf=32,lr=32,rr=32;
lcd.setCursor(4,0);lcd.print("POWER OFF");audio();delay(2000);cl();}
if((digitalRead(5)==LOW||ir.value==POWER)&&power==1){power=0;menu=0;menu_set=100;analogWrite(6,BRIG_H);cl();myEnc.write(0);
lf=lf_old,rf=rf_old,lr=lr_old,rr=rr_old; w=1;
lcd.setCursor(4,0);lcd.print("POWER ON");audio();delay(2000);cl();}
//////// VOLUME ////////////////////////////////////////////////////////////////
if(menu==0){
if(ir.value==UP){vol++;gr1=1;gr2=0;cl1();time=millis();w=1;w1=1;vol_fun();audio();}// кнопка >
if(ir.value==0xFFFFFFFF and gr1==1){vol++;gr2=0;cl1();time=millis();w=1;w1=1;vol_fun();audio();}// кнопка >>>>>>
if(ir.value==DOWN){vol--;gr1=0;gr2=1;cl1();time=millis();w=1;w1=1;vol_fun();audio();}// кнопка <
if(ir.value==0xFFFFFFFF and gr2==1){vol--;gr1=0;cl1();time=millis();w=1;w1=1;vol_fun();audio();}// кнопка <<<<<<
if (newPosition != oldPosition){oldPosition = newPosition;
vol=vol-newPosition;myEnc.write(0);newPosition=0;time=millis();w=1;w1=1;vol_fun();audio();}
lcd.setCursor(0,0);lcd.print(F("VOLUME "));
lcd.setCursor(0,1);lcd.print(F("INPUT "));lcd.print(in+1);
fun_d = vol+79;
if(w==1){w=0;
a[0]=(fun_d)/10;a[1]=(fun_d)%10;
for(i=0;i<2;i++){
switch(i){
case 0: e1=10,e2=11,e3=12;break;
case 1: e1=13,e2=14,e3=15;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);
}}}
/////// BASS ///////////////////////////////////////////////////////////////////
if(menu==1){
if(ir.value==UP){bass++;gr1=1;gr2=0;cl1();time=millis();w=1;w1=1;bass_fun();audio();}// кнопка >
if(ir.value==0xFFFFFFFF and gr1==1){bass++;gr2=0;cl1();time=millis();w=1;w1=1;bass_fun();audio();}// кнопка >>>>>>
if(ir.value==DOWN){bass--;gr1=0;gr2=1;cl1();time=millis();w=1;w1=1;bass_fun();audio();}// кнопка <
if(ir.value==0xFFFFFFFF and gr2==1){bass--;gr1=0;cl1();time=millis();w=1;w1=1;bass_fun();audio();}// кнопка <<<<<<
if (newPosition != oldPosition){oldPosition = newPosition;
bass=bass-newPosition;myEnc.write(0);newPosition=0;time=millis();w=1;w1=1;bass_fun();audio();}
lcd.setCursor(0,0);lcd.print(F("BASS"));
lcd.setCursor(14,1);lcd.print(F("dB"));
fun_d=bass*2;
if(fun_d<0){fun_d=abs(fun_d);lcd.setCursor(6,0);lcd.write((uint8_t)3);}else{lcd.setCursor(6,0);lcd.print(" ");}
if(w==1){w=0;
a[0]=(fun_d)/10;a[1]=(fun_d)%10;
cif();}}
/////// TREBLE ///////////////////////////////////////////////////////////////////
if(menu==2){
if(ir.value==UP){treb++;gr1=1;gr2=0;cl1();time=millis();w=1;w1=1;treb_fun();audio();}// кнопка >
if(ir.value==0xFFFFFFFF and gr1==1){treb++;gr2=0;cl1();time=millis();w=1;w1=1;treb_fun();audio();}// кнопка >>>>>>
if(ir.value==DOWN){treb--;gr1=0;gr2=1;cl1();time=millis();w=1;w1=1;treb_fun();audio();}// кнопка <
if(ir.value==0xFFFFFFFF and gr2==1){treb--;gr1=0;cl1();time=millis();w=1;w1=1;treb_fun();audio();}// кнопка <<<<<<
if (newPosition != oldPosition){oldPosition = newPosition;
treb=treb-newPosition;myEnc.write(0);newPosition=0;time=millis();w=1;w1=1;treb_fun();audio();}
lcd.setCursor(0,0);lcd.print(F("TREB"));
lcd.setCursor(14,1);lcd.print(F("dB"));
fun_d=treb*2;
if(fun_d<0){fun_d=abs(fun_d);lcd.setCursor(6,0);lcd.write((uint8_t)3);}else{lcd.setCursor(6,0);lcd.print(" ");}
if(w==1){w=0;
a[0]=(fun_d)/10;a[1]=(fun_d)%10;
cif();}}
///// MENU_SET ///////////////////////////////////////////////////////////////////////
//////// LF ////////////////////////////////////////////////////////////////
if(menu_set==0){
if (newPosition != oldPosition){oldPosition = newPosition;
lf=lf+newPosition;myEnc.write(0);newPosition=0;time=millis();w=1;w1=1;if(lf>31){lf=31;}if(lf<0){lf=0;}audio();}
lcd.setCursor(0,0);lcd.print(F("ATT_LF"));
lcd.setCursor(14,1);lcd.print(F("dB"));
fun_d=lf;
if(fun_d>0){fun_d=abs(fun_d);lcd.setCursor(6,0);lcd.write((uint8_t)3);}else{lcd.setCursor(6,0);lcd.print(" ");}
if(w==1){w=0;
a[0]=(fun_d)/10;a[1]=(fun_d)%10;
cif();}}
//////// RF ////////////////////////////////////////////////////////////////
if(menu_set==1){
if (newPosition != oldPosition){oldPosition = newPosition;
rf=rf+newPosition;myEnc.write(0);newPosition=0;time=millis();w=1;w1=1;if(rf>31){rf=31;}if(rf<0){rf=0;}audio();}
lcd.setCursor(0,0);lcd.print(F("ATT_RF"));
lcd.setCursor(14,1);lcd.print(F("dB"));
fun_d=rf;
if(fun_d>0){fun_d=abs(fun_d);lcd.setCursor(6,0);lcd.write((uint8_t)3);}else{lcd.setCursor(6,0);lcd.print(" ");}
if(w==1){w=0;
a[0]=(fun_d)/10;a[1]=(fun_d)%10;
cif();}}
//////// LR ////////////////////////////////////////////////////////////////
if(menu_set==2){
if (newPosition != oldPosition){oldPosition = newPosition;
lr=lr+newPosition;myEnc.write(0);newPosition=0;time=millis();w=1;w1=1;if(lr>31){lr=31;}if(lr<0){lr=0;}audio();}
lcd.setCursor(0,0);lcd.print(F("ATT_LR"));
lcd.setCursor(14,1);lcd.print(F("dB"));
fun_d=lr;
if(fun_d>0){fun_d=abs(fun_d);lcd.setCursor(6,0);lcd.write((uint8_t)3);}else{lcd.setCursor(6,0);lcd.print(" ");}
if(w==1){w=0;
a[0]=(fun_d)/10;a[1]=(fun_d)%10;
cif();}}
//////// RR ////////////////////////////////////////////////////////////////
if(menu_set==3){
if (newPosition != oldPosition){oldPosition = newPosition;
rr=rr+newPosition;myEnc.write(0);newPosition=0;time=millis();w=1;w1=1;if(rr>31){rr=31;}if(rr<0){rr=0;}audio();}
lcd.setCursor(0,0);lcd.print(F("ATT_RR"));
lcd.setCursor(14,1);lcd.print(F("dB"));
fun_d=rr;
if(fun_d>0){fun_d=abs(fun_d);lcd.setCursor(6,0);lcd.write((uint8_t)3);}else{lcd.setCursor(6,0);lcd.print(" ");}
if(w==1){w=0;
a[0]=(fun_d)/10;a[1]=(fun_d)%10;
cif();}}
/////////////////// ЧАСЫ ///////////////////////////////////////////////////////////////////
DateTime = clock.getDateTime();hour = DateTime.hour;minut = DateTime.minute;secon = DateTime.second;
if(power==1){
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(x=0;x<4;x++){
switch(x){
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;
}digit();}
lcd.setCursor(6,0);lcd.print(".");lcd.setCursor(6,1);lcd.print(".");
lcd.setCursor(14,1);lcd.print(a[4]);lcd.setCursor(15,1);lcd.print(a[5]);
//// set time ////
if(digitalRead(10)==LOW&&digitalRead(2)==LOW){hour++;if(hour>23){hour=0;} clock.setDateTime(2021, 8, 28, hour, minut, secon);delay(100);}// input button HH++
if(digitalRead(10)==LOW&&digitalRead(3)==LOW){minut++;if(minut>59){minut=0;} clock.setDateTime(2021, 8, 28, hour, minut, secon);delay(100); }// menu set/main button MM++
if(digitalRead(10)==LOW&&digitalRead(4)==LOW){secon=0; clock.setDateTime(2021, 8, 28, hour, minut, secon);delay(100); }// mute button SS=0
}
//////// EEPROM //////////////////////////////////////////////////
if(millis()-time>10000 && w1==1&&mute==0&&power==0){
EEPROM.update(0,vol+79);EEPROM.update(1,bass+9);EEPROM.update(2,treb+7);EEPROM.update(3,in);
EEPROM.update(4,lr);EEPROM.update(5,rr);EEPROM.update(6,lf);EEPROM.update(7,rf);
menu_set=100;if(menu!=0){lcd.clear();}menu=0;w=1;w1=0;}
}// LOOP END
void cl(){ir.value=0;delay(300);lcd.clear();}
void cl1(){ir.value=0;delay(300);}
void bass_fun(){if(bass<-9){bass=-9;}if(bass>9){bass=9;}}
void treb_fun(){if(treb<-7){treb=-7;}if(treb>7){treb=7;}}
void vol_fun(){if(vol<-79){vol=-79;}if(vol>20){vol=20;}}
void to_Timer(){newPosition = myEnc.read()/4;}
void digit(){switch(a[x]){
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);}
void cif(){
for(i=0;i<2;i++){
switch(i){
case 0: e1=7,e2=8,e3=9;break;
case 1: e1=10,e2=11,e3=12;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);
}}
void audio(){
tda.setInput(in, 0, 0, bass*2); // не менять
// in >>> 0=in2, 1=in1, 2=mono, 3=mute
// bass_cut >>> 0=non-symmetrical bass cut, 1=symmetrical bass cut
// bass_range >>> 0=extended bass range, 1=standard bass range ±14dB
// bass >>> -18...+18 (-18...+18 dB) step 2
tda.setVolume(vol);
// vol >>> -79...+32 (-79...+32 dB) // более +20дБ не рекомендуется повышать
tda.setBass_Treb(bass*2, treb*2);
// bass >>> -18...+18 (-18...+18 dB) step 2
// treb >>> -14...+14 (-14...+14 dB) step 2
tda.setAtt_LF(lf);
// lf >>> 0...31 (0...-31 dB), 32=mute
tda.setAtt_LR(lr);
// lr >>> 0...31 (0...-31 dB), 32=mute
tda.setAtt_RF(rf);
// rf >>> 0...31 (0...-31 dB), 32=mute
tda.setAtt_RR(rr);
// rr >>> 0...31 (0...-31 dB), 32=mute
}