#include <Wire.h>
#include <TDA7419.h>
#include <EEPROM.h>
#include <LiquidCrystal_I2C.h>
TDA7419 tda;
LiquidCrystal_I2C lcd(0x27,16,2);
int menu,vol,vol2,bas,w,w1,vol_d,bass_d,treb,treble_d,middle,middle_d,z,in,gain0,gain1,gain2,gain3,gain_d,set;
int lon, lon_f, lon_d,out,vol_out,rf,lf,rt,lt,sab,treb_c,mid_c,bas_c,sab_f,power,a,b,vol_10,vol_1,sab_10,sab_1,mute=1;
unsigned long time;
byte a1[8]={0b00000,0b11011,0b11011,0b11011,0b11011,0b11011,0b11011,0b00000};
byte a2[8]={0b00000,0b11000,0b11000,0b11000,0b11000,0b11000,0b11000,0b00000};
byte custom_num[8][8] = {
{ B00111,B01111,B11111,B11111,B11111,B11111,B11111,B11111 },
{ B11111,B11111,B11111,B00000,B00000,B00000,B00000,B00000 },
{ B11100,B11110,B11111,B11111,B11111,B11111,B11111,B11111 },
{ B11111,B11111,B11111,B11111,B11111,B11111,B01111,B00111 },
{ B00000,B00000,B00000,B00000,B00000,B11111,B11111,B11111 },
{ B11111,B11111,B11111,B11111,B11111,B11111,B11110,B11100 },
{ B11111,B11111,B11111,B00000,B00000,B00000,B11111,B11111 },
{ B11111,B11111,B11111,B11111,B11111,B11111,B11111,B11111 }};
const int digit_width = 3;
// 0 1 2 3 4 5 6 7 8 9
const char custom_num_top[10][digit_width]={ 0,1,2, 1,2,32, 6,6,2, 6,6,2, 3,4,7, 7,6,6, 0,6,6, 1,1,2, 0,6,2, 0,6,2};
const char custom_num_bot[10][digit_width]={ 3,4,5, 4,7,4, 7,4,4, 4,4,5, 32,32,7, 4,4,5, 3,4,5, 32,32,7, 3,4,5, 4,4,5};
#define sw01 9 // menu
#define sw02 8 // +
#define sw03 11 // -
#define sw04 10 // <
#define sw05 7 // >
#define sw06 6 // Power
#define sw07 13 // remot
#define sw08 2 // iluminação interna 1
#define sw09 4 // controle A
#define sw10 3 // controle B
#define sw11 5 // remot subwoofer
#define sw12 12 // iluminação interna 2
void setup(){
Wire.begin();
Serial.begin(9600);
lcd.begin(16, 2);
pinMode(sw01, INPUT); // menu
pinMode(sw02, INPUT); // +
pinMode(sw03, INPUT); // -
pinMode(sw04, INPUT); // Input
pinMode(sw05, INPUT); // Mute
pinMode(sw06, INPUT); // Power
pinMode(sw07, OUTPUT); // remot
pinMode(sw08, OUTPUT); // iluminação interna 1
pinMode(sw09, OUTPUT); // controle A
pinMode(sw10, OUTPUT); // controle B
pinMode(sw11, OUTPUT); // remot subwoofer
pinMode(sw12, OUTPUT); // iluminação interna 2
vol = EEPROM.read(0);
treb = EEPROM.read(1)-15;
middle = EEPROM.read(3)-15;
bas = EEPROM.read(3)-15;
in = EEPROM.read(4);
gain1 = EEPROM.read(5);
gain2 = EEPROM.read(6);
gain3 = EEPROM.read(7);
lon = EEPROM.read(8);
lon_f = EEPROM.read(9);
rf = EEPROM.read(10);
lf = EEPROM.read(11);
rt = EEPROM.read(12);
lt = EEPROM.read(13);
sab = EEPROM.read(14);
treb_c = EEPROM.read(15);
mid_c = EEPROM.read(16);
bas_c = EEPROM.read(17);
sab_f = EEPROM.read(18);
audio();
vol = 0;
treb = 0;
middle = 0;
bas = 0;
treb_c = 0;
mid_c = 0;
bas_c = 0;
in = 1;
gain1 = 15;
gain2 = 15;
gain3 = 15;
lon_f = 0;
lon = 0;
sab = 0;
sab_f = 0;
menu=100;
}
void loop(){
lcd_update();
if(digitalRead(sw01)==HIGH&&menu<20){
menu++;
cl();
time=millis();
w1=1;
if(menu>9){menu=0;
}
}
//////////////////////////////////////// POWER ON //////////////////////////////////////
if(digitalRead(sw06)==HIGH&&menu<20){
menu=90;
cl();
time=millis();
w1=1;
}
if(digitalRead(sw06)==HIGH&&menu>20){
lcd.setBacklight(HIGH);
lcd.setCursor(0,0);
lcd.print("================");
lcd.setCursor(0,1);
lcd.print("================");
delay(150);
lcd.setCursor(0,0);
lcd.print("======= =======");
lcd.setCursor(0,1);
lcd.print("======= =======");
delay(150);
lcd.setCursor(0,0);
lcd.print("====== BA ======");
lcd.setCursor(0,1);
lcd.print("====== ======");
delay(150);
lcd.setCursor(0,0);
lcd.print("===== UBAR =====");
lcd.setCursor(0,1);
lcd.print("===== K S =====");
delay(150);
lcd.setCursor(0,0);
lcd.print("==== SUBARU ====");
lcd.setCursor(0,1);
lcd.print("==== CK SH ====");
delay(150);
lcd.setCursor(0,0);
lcd.print("=== SUBARU ===");
lcd.setCursor(0,1);
lcd.print("=== ACK SHA ===");
delay(150);
lcd.setCursor(0,0);
lcd.print("== SUBARU ==");
lcd.setCursor(0,1);
lcd.print("== LACK SHAR ==");
delay(150);
lcd.setCursor(0,0);
lcd.print("= SUBARU =");
lcd.setCursor(0,1);
lcd.print("= BLACK SHARK =");
delay(150);
lcd.setCursor(0,0);
lcd.print(" SUBARU ");
lcd.setCursor(0,1);
lcd.print(" BLACK SHARK ");
delay(2000);
lcd.clear();
menu=0;
digitalWrite(sw07, HIGH);
cl();
time=millis();
w1=1;
}
//////////////////////////////////////// //////////////////////////////////////
if(menu==90){
lcd.setCursor(0,0);
lcd.print(" bye ");
lcd.setCursor(0,1);
lcd.print(" bye ");
delay(2000);
lcd.setBacklight(LOW);
digitalWrite(sw07, LOW);
digitalWrite(sw08, LOW);
digitalWrite(sw11, LOW);
lcd.clear();
menu=100;
}//////////////////////////////////////// POWER OFF //////////////////////////////////////
if(menu==100){
}
//////////////////////////////////////// Volume -80 ... 0 //////////////////////////////////////
if(menu==0){
custom_num_shape();
if(digitalRead(sw02)==HIGH){vol++;w=1;
if(vol>80){vol=80;}}
// 80 maximum volume
if(digitalRead(sw03)==HIGH){vol--;w=1;
if(vol<0){vol=0;}}
// 0 volume minimum
if(vol>0){mute=1;}
if(vol==0){mute=0;}
//////////////////////////////////////COMANDOS////////////////////////////////////////////////
if(digitalRead(sw04)==HIGH){digitalWrite(sw10, HIGH);}
if(digitalRead(sw05)==HIGH){digitalWrite(sw09, HIGH);}
if(digitalRead(sw04)==LOW){digitalWrite(sw10, LOW);}
if(digitalRead(sw05)==LOW){digitalWrite(sw09, LOW);}
vol_10 = vol / 10;
vol_1 = vol - vol_10 * 10;
a = vol_10;
b = vol_1;
if(w==1){audio();cl2();time=millis();w=0;w1=1;}}
//////////////////////////////////////subw////////////////////////////////////////////////
if(menu==1){
if(digitalRead(sw02)==HIGH){sab++;w=1;
if(sab>15){sab=15;}}
if(digitalRead(sw03)==HIGH){sab--;w=1;
if(sab<0){sab=0;}}
if(sab>0){digitalWrite(sw11, HIGH);}
if(sab==0){digitalWrite(sw11, LOW);}
if(digitalRead(sw05)==HIGH){sab_f++;w=1;
if(sab_f>3){sab_f=3;}}
if(digitalRead(sw04)==HIGH){sab_f--;w=1;
if(sab_f<0){sab_f=0;}}
sab_10 = sab / 10;
sab_1 = sab - sab_10 * 10;
a = sab_10;
b = sab_1;
if(w==1){audio();cl();time=millis();w1=1;w=0;}
}
/////////////////////// indication HF tone + button control -15...15 dB ///////////////////
if(menu==2){
if(digitalRead(sw02)==HIGH){treb++;w=1;
if(treb>15){treb=15;}}
if(digitalRead(sw03)==HIGH){treb--;w=1;
if(treb<-15){treb=-15;}}
if(digitalRead(sw05)==HIGH){treb_c++;w=1;
if(treb_c>3){treb_c=3;}}
if(digitalRead(sw04)==HIGH){treb_c--;w=1;
if(treb_c<0){treb_c=0;}}
if(w==1){audio();cl();time=millis();w1=1;w=0;}}
/////////////////////////////////////////////////////////////////////////////////////
/////////////////////// indication timbre midrange + button control -15...15 dB ///////////////////
if(menu==3){
if(digitalRead(sw02)==HIGH){middle++;w=1;
if(middle>15){middle=15;}}
if(digitalRead(sw03)==HIGH){middle--;w=1;
if(middle<-15){middle=-15;}}
if(digitalRead(sw05)==HIGH){mid_c++;w=1;
if(mid_c>3){mid_c=3;}}
if(digitalRead(sw04)==HIGH){mid_c--;w=1;
if(mid_c<0){mid_c=0;}}
if(w==1){audio();cl();time=millis();w1=1;w=0;}}
/////////////////////////////////////////////////////////////////////////////////////
/////////////////////// indication bass tone + button control -15...15 dB ///////////////////
if(menu==4){
if(digitalRead(sw02)==HIGH){bas++;w=1;
if(bas>15){bas=15;}}
if(digitalRead(sw03)==HIGH){bas--;w=1;
if(bas<-15){bas=-15;}}
if(digitalRead(sw05)==HIGH){bas_c++;w=1;
if(bas_c>3){bas_c=3;}}
if(digitalRead(sw04)==HIGH){bas_c--;w=1;
if(bas_c<0){bas_c=0;}}
if(w==1){audio();cl();time=millis();w1=1;w=0;}}
////////////////////////////////////////////////////////////////////////////////////
///////////////////////////// input 1...3 + preamplifier 0...15 dB //////////////////////////////
if(menu==5){ //registro. pré-amplificador - pressione e segure o botão set, reg. botões mais e menos
if(digitalRead(sw05)==HIGH){
in++;w=1;if(in>3){in=3;
}
}
if(digitalRead(sw04)==HIGH){
in--;
w=1;
if(in<1){
in=1;
}
}
if(in==1){
gain0=gain1;
}
if(in==2){
gain0=gain2;
}
if(in==3){
gain0=gain3;
}
if(digitalRead(sw02)==HIGH){
gain0++;
w=1;
if(gain0>15){
gain0=15;
}
}
if(digitalRead(sw03)==HIGH){
gain0--;
w=1;
if(gain0<0){
gain0=0;
}
}
if(w==1){audio();cl();time=millis();w1=1;w=0;}
gain_d=gain0;
if(gain_d>=0){
for(z=0;
z<=gain_d;
z++){
lcd.setCursor(z/2,1);
lcd.write((uint8_t)7);
}
}
if((gain_d)%2==0){
lcd.setCursor(z/2,1);
lcd.write((uint8_t)4);
}
if(in==1){
gain1=gain0;
}
if(in==2){
gain2=gain0;
}
if(in==3){
gain3=gain0;
}
}
/////////////////////////////////////////////////////////////////////////////////////////////
////////////////////////////// loudness ////////////////////////////////////////////////////
if(menu==6){
if(digitalRead(sw05)==HIGH){lon_f++;w=1;
if(lon_f>3){lon_f=3;}}
if(digitalRead(sw04)==HIGH){lon_f--;w=1;
if(lon_f<0){lon_f=0;}}
if(digitalRead(sw02)==HIGH){lon++;w=1;
if(lon>15){lon=15;}}
if(digitalRead(sw03)==HIGH){lon--;w=1;
if(lon<0){lon=0;}}
if(w==1){audio();cl();time=millis();w1=1;w=0;}
}
////////////////////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////// out /////////////////////////////////////////////////
if(menu==7){
if(digitalRead(sw05)==HIGH){out++;w=1;
if(out>3){out=3;}}
if(digitalRead(sw04)==HIGH){out--;w=1;
if(out<0){out=0;}}
if(w==1){audio();cl();time=millis();w1=1;w=0;}
}
/////////////////////////////////treble center//////////////////////////////////////////////////
if(menu==8){
if(digitalRead(sw02)==HIGH){
digitalWrite(sw08, HIGH);
}
if(digitalRead(sw03)==HIGH){
digitalWrite(sw08, LOW);
}
}
/////////////////////////////////middle center//////////////////////////////////////////////////
if(menu==9){
if(digitalRead(sw02)==HIGH){
digitalWrite(sw12, HIGH);
}
if(digitalRead(sw03)==HIGH){
digitalWrite(sw12, LOW);
}
}
////////////////////////////////////bass center///////////////////////////////////////////
if(menu==10){
}
//////////////////////////////////////////////////////////////////////////////////////
Serial.println(time);
if(menu<20&&millis()-time>10000 && w1==1){
EEPROM.update(0,vol);
EEPROM.update(1,treb+15);
EEPROM.update(2,middle+15);
EEPROM.update(3,bas+15);
EEPROM.update(4,in);
EEPROM.update(5,gain1);
EEPROM.update(6,gain2);
EEPROM.update(7,gain3);
EEPROM.update(8,lon);
EEPROM.update(9,lon_f);
EEPROM.update(10,rf);
EEPROM.update(11,lf);
EEPROM.update(12,rt);
EEPROM.update(13,lt);
EEPROM.update(14,sab);
EEPROM.update(15,treb_c);
EEPROM.update(16,mid_c);
EEPROM.update(17,bas_c);
EEPROM.update(18,sab_f);
menu=0;w1=0; cl();}
}//loop
void cl(){
delay(300);
lcd.clear();
}
void cl2(){
delay(20);
lcd.clear();
}
void custom_num_shape(){
for(int i=0; i < 8; i++)
lcd.createChar(i, custom_num[i]);
}
void audio(){
tda.setInput(in,gain0,0); //entrada 1=1, entrada 2=2, entrada 3=3
tda.setInput2(0,0,0); // não usado
tda.setAtt_loudness(lon,lon_f,0,0);
tda.setSoft(mute,0,0,0,0); //mute off (não mude)
tda.setVolume(vol-79,0); // volume geral de 0 a 79 no máximo
tda.setAtt_LF(64+lf,0); // falante dianteiro esquerdo
tda.setAtt_RF(64+rf,0); // falante dianteiro direito
tda.setAtt_LT(64+lt,0); // falante traseiro esquerdo
tda.setAtt_RT(64+rt,0); // falante traseiro direito
tda.setAtt_SUB(64+sab,0); // subwoofer
tda.setAtt_Mix(79,0); // não usado
tda.setFilter_Treble(treb,treb_c,0);
tda.setFilter_Middle(middle,0,0);
tda.setFilter_Bass(bas,0,0);
tda.setSub_M_B(sab_f,mid_c,bas_c,0,0);
tda.setMix_Gain_Eff(1,0,0,0,0); // não usado
tda.setSpektor(0,0,1,0,1,0,0);
}
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
void lcd_update(){
lcd.setCursor(0, 0);
switch(menu){
case 0:
lcd.setCursor(0,0);
if(mute==1){
lcd.print(" SUBARU ");
}
else{
lcd.print(" MUDO ");
}
lcd.setCursor(9, 0);
for(int i=0; i < digit_width; i++)
lcd.print(custom_num_top[a][i]);
lcd.setCursor(9, 1);
for(int i=0; i < digit_width; i++)
lcd.print(custom_num_bot[a][i]);
lcd.setCursor(13, 0);
for(int i=0; i < digit_width; i++)
lcd.print(custom_num_top[b][i]);
lcd.setCursor(13, 1);
for(int i=0; i < digit_width; i++)
lcd.print(custom_num_bot[b][i]);
break;
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
case 1:
lcd.setCursor(0,0);
lcd.print("Subwoofer");
a = sab_10;
b = sab_1;
lcd.setCursor(9, 0);
for(int i=0; i < digit_width; i++)
lcd.print(custom_num_top[a][i]);
lcd.setCursor(9, 1);
for(int i=0; i < digit_width; i++)
lcd.print(custom_num_bot[a][i]);
lcd.setCursor(13, 0);
for(int i=0; i < digit_width; i++)
lcd.print(custom_num_top[b][i]);
lcd.setCursor(13, 1);
for(int i=0; i < digit_width; i++)
lcd.print(custom_num_bot[b][i]);
lcd.setCursor(0,1);
lcd.print("F.");
lcd.setCursor(2,1);
if(sab_f==0){lcd.print(" FLAT ");}
if(sab_f==1){lcd.print(" 80 Hz");}
if(sab_f==2){lcd.print("120 Hz");}
if(sab_f==3){lcd.print("160 Hz");}
break;
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
case 2:
lcd.setCursor(0,0);
lcd.print("AGUDO ");
lcd.print(treb);
lcd.setCursor(13,0);
lcd.print("dB");
treble_d=treb+15;
lcd.setCursor(4,1);
if(treb_c==0){lcd.print("10.0 kHz");}
if(treb_c==1){lcd.print("12.5 kHz");}
if(treb_c==2){lcd.print("15.0 kHz");}
if(treb_c==3){lcd.print("17.5 kHz");}
break;
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
case 3:
lcd.setCursor(0,0);
lcd.print("MEDIO ");
lcd.print(middle);
lcd.setCursor(13,0);
lcd.print("dB");
middle_d=middle+15;
lcd.setCursor(4,1);
if(mid_c==0){lcd.print("0.5 kHz");}
if(mid_c==1){lcd.print("1.0 kHz");}
if(mid_c==2){lcd.print("1.5 kHz");}
if(mid_c==3){lcd.print("2.5 kHz");}
break;
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
case 4:
lcd.setCursor(0,0);
lcd.print("GRAVE ");
lcd.print(bas);
lcd.setCursor(13,0);
lcd.print("dB");
bass_d=bas+15;
lcd.setCursor(5,1);
if(bas_c==0){lcd.print(" 60 Hz");}
if(bas_c==1){lcd.print(" 80 Hz");}
if(bas_c==2){lcd.print("100 Hz");}
if(bas_c==3){lcd.print("200 Hz");}
break;
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
case 5:
lcd.setCursor(0,0);
lcd.print("Entrada: ");
lcd.print(in);
lcd.setCursor(11,1);
lcd.print(gain0);
lcd.print(" dB ");
break;
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
case 6:
lcd.setCursor(0,0);
lcd.print("Loudness: ");
if(lon_f==0){lcd.print(" FLAT");}
if(lon_f==1){lcd.print(" 400Hz");}
if(lon_f==2){lcd.print(" 800Hz");}
if(lon_f==3){lcd.print("2400Hz");}
lcd.setCursor(9,1);
lcd.print(lon);
lcd.print(" dB ");
break;
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
case 7:
lcd.setCursor(0,0);
lcd.print("Volume OUT");
lcd.setCursor(0,1);
if(out==0){
lcd.print("RF: +");
lcd.print(rf);
if(digitalRead(sw02)==HIGH){
rf++;
w=1;
if(rf>15){
rf=15;
}
}
if(digitalRead(sw03)==HIGH){
rf--;
w=1;
if(rf<0){
rf=0;
}
}
}
if(out==1){
lcd.print("LF: +");
lcd.print(lf);
if(digitalRead(sw02)==HIGH){
lf++;
w=1;
if(lf>15){
lf=15;
}
}
if(digitalRead(sw03)==HIGH){
lf--;
w=1;
if(lf<0){
lf=0;
}
}
}
if(out==2){
lcd.print("RT: +");
lcd.print(rt);
if(digitalRead(sw02)==HIGH){
rt++;
w=1;
if(rt>15){
rt=15;
}
}
if(digitalRead(sw03)==HIGH){
rt--;
w=1;
if(rt<0){
rt=0;
}
}
}
if(out==3){
lcd.print("LT: +");
lcd.print(lt);
if(digitalRead(sw02)==HIGH){
lt++;
w=1;
if(lt>15){
lt=15;
}
}
if(digitalRead(sw03)==HIGH){
lt--;
w=1;
if(lt<0){
lt=0;
}
}
}
break;
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
case 8:
lcd.setCursor(0,0);
lcd.print("Luzes Internas 1");
if(digitalRead(sw08)==LOW){
lcd.setCursor(0,1);
lcd.print(" DESLIGADAS ");
}
if(digitalRead(sw08)==HIGH){
lcd.setCursor(0,1);
lcd.print(" LIGADAS ");
}
break;
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
case 9:
lcd.setCursor(0,0);
lcd.print("Luzes Internas 2");
if(digitalRead(sw12)==LOW){
lcd.setCursor(0,1);
lcd.print(" DESLIGADAS ");
}
if(digitalRead(sw12)==HIGH){
lcd.setCursor(0,1);
lcd.print(" LIGADAS ");
}
break;
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
case 10:
break;
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
}
}