1

Тема: TDA7419 + OLED1.3 + ENCODER + IR + Spectrum Analyzer (LGT8F328)

Основная статья - http://rcl-radio.ru/?p=131120

// TDA7419 + OLED1.3 + ENCODER + IR + Spectrum Analyzer
// rcl-radio.ru
// liman324@yandex.ru
// Alexander Liman

#define IR2       0x807FF00F // button encoder
#define MUTE_IR   0x807FF807 // mute
#define IR4       0x807F48B7 // >>>
#define IR5       0x807FC837 // <<<
#define IN1_IR    0x807F38C7 // IN1
#define IN2_IR    0x807FB847 // IN2
#define IN3_IR    0x807F7887 // IN3

#define GAIN_SPEC    2.0
#define SIG_0_SPEC   7
#define SPED_SPEC    25
#define TIME_SPEC    15

#define ENC_DT       9
#define ENC_CLK      8
#define ENC_SW       10
#define IR           12
#define IN1          2
#define IN2          3
#define IN3          4
#define SET          5
#define MUTE         6

#include <Wire.h> 
#include <U8glib.h>            // https://github.com/olikraus/u8glib/
#include <MsTimer2.h>          // http://rcl-radio.ru/wp-content/uploads/2018/11/MsTimer2.zip 
#include <TDA7419.h>           // https://github.com/liman324/TDA7419.git
#include <Encoder.h>           // http://rcl-radio.ru/wp-content/uploads/2019/05/Encoder.zip 
#include <EEPROM.h>
#include <boarddefs.h>         // входит в состав библиотеки IRremote
#include <IRremote.h>          // http://rcl-radio.ru/wp-content/uploads/2019/06/IRremote.zip
 
TDA7419 tda;
Encoder myEnc(ENC_DT, ENC_CLK);
U8GLIB_SH1106_128X64 u8g(U8G_I2C_OPT_DEV_0|U8G_I2C_OPT_FAST);
IRrecv irrecv(IR); 
decode_results ir; 

long times,oldPosition  = -999,newPosition, times1;
byte spektor[7];
int menu,vol_reg,in_reg,treb_reg,mid_reg,bass_reg,treb_f,gain0,gain1,gain2,gain3;
int lon,lon_f;
bool w=1,w1,gr1,gr2,www,set,mute=1;
byte ur[7],urr[7];
int fr,fl,rr,rl,sab,out_att,out,mid_f,mid_q,sab_f,bass_f,bass_q;

void setup(){
  Wire.begin();Serial.begin(9600);
  analogReadResolution(8);
  analogReference(INTERNAL1V024);
  irrecv.enableIRIn();
  pinMode(A0,INPUT);          // SAOUT TDA7419
  pinMode(A1,OUTPUT);         // SAIN  TDA7419
  pinMode(IN1,INPUT_PULLUP);  //  IN1  TDA7419
  pinMode(IN2,INPUT_PULLUP);  //  IN2  TDA7419
  pinMode(IN3,INPUT_PULLUP);  //  IN3  TDA7419
  pinMode(SET,INPUT_PULLUP);  //  SET  TDA7419
  pinMode(MUTE,INPUT_PULLUP); // MUTE  TDA7419
  MsTimer2::set(1, to_Timer);MsTimer2::start();
  vol_reg = EEPROM.read(0)-79;treb_reg = EEPROM.read(1)-15;mid_reg = EEPROM.read(2)-15;bass_reg = EEPROM.read(3)-15;
  in_reg = EEPROM.read(4);gain1 = EEPROM.read(5);gain2 = EEPROM.read(6);gain3 = EEPROM.read(7);
  lon = EEPROM.read(8);lon_f = EEPROM.read(9);
  fr = EEPROM.read(10);fl = EEPROM.read(11);rl = EEPROM.read(12);rr = EEPROM.read(13);sab = EEPROM.read(14);
  treb_f = EEPROM.read(15);mid_f = EEPROM.read(16);mid_q = EEPROM.read(17);
  bass_f = EEPROM.read(18);bass_q = EEPROM.read(19);sab_f = EEPROM.read(20);
  arr_7();
  delay(500);audio();
  }

void loop(){
/// IR ////////////////////////////////////////
 if ( irrecv.decode( &ir )) {Serial.print("0x");Serial.println( ir.value,HEX);irrecv.resume();}// IR приемник - чтение, в мониторе порта отображаются коды кнопок
 if(ir.value==0){gr1=0;gr2=0;}// запрет нажатий не активных кнопок пульта  
//////// BUTTON ////////////////////////////////////////////////
 if(digitalRead(ENC_SW)==LOW&&menu<5||ir.value==IR2){menu++;cl();if(menu>3){menu=0;}arr_1();delay(200);}
 if(digitalRead(IN1)==LOW&&menu<5||ir.value==IN1_IR){menu=4;cl();in_reg=1;arr_1();www=1;;delay(200);}
 if(digitalRead(IN2)==LOW&&menu<5||ir.value==IN2_IR){menu=4;cl();in_reg=2;arr_1();www=1;delay(200);}
 if(digitalRead(IN3)==LOW&&menu<5||ir.value==IN3_IR){menu=4;cl();in_reg=3;arr_1();www=1;delay(200);}
 if(digitalRead(SET)==LOW&&set==0){menu=5;set=1;times1=millis();w=1;delay(200);}
 if(digitalRead(SET)==LOW&&set==1){menu=0;set=0;;arr_1();www=1;delay(200);}
 if(digitalRead(ENC_SW)==LOW&&menu>4){menu++;if(menu>10){menu=0;}times1=millis();w=1;set=0;delay(200);}
 if((digitalRead(MUTE)==LOW||ir.value==MUTE_IR)&&mute==1){mute=0;menu=100;cl();
 u8g.firstPage();do {u8g.setFont(u8g_font_profont12r);u8g.drawStr(53,30,"MUTE");} while( u8g.nextPage() );audio();delay(200);}
 if((digitalRead(MUTE)==LOW||ir.value==MUTE_IR)&&mute==0){mute=1;menu=0;cl();arr_1();audio();delay(200);}
///////////////////////////////////////////////////////////////
  
//////// VOLUME //////////////////////////////////////////////////////////////////////////////////////////////////////////////  
  if(menu==0){
   if(newPosition != oldPosition){arr_2();vol_reg=vol_reg+newPosition;arr_3();arr_1();vol_func();audio();}
 
   if(ir.value==IR4){vol_reg++;arr_4();cl();arr_1();vol_func();audio();}// кнопка > 
   if(ir.value==0xFFFFFFFF and gr1==1){vol_reg++;gr2=0;cl();arr_1();vol_func();audio();}// кнопка >>>>>>
   if(ir.value==IR5){vol_reg--;gr1=0;gr2=1;cl();arr_1();vol_func();audio();}// кнопка <
   if(ir.value==0xFFFFFFFF and gr2==1){vol_reg--;gr1=0;cl();arr_1();vol_func();audio();}// кнопка <<<<<<
 
  if(w==1){w=0;
  u8g.firstPage();  
   do {
  u8g.setFont(u8g_font_profont12r);u8g.drawStr(0,8,"VOLUME");u8g.drawStr(0,18,"IN");
  u8g.setPrintPos(20, 18);u8g.print(in_reg);u8g.drawStr(0,28,"GAIN");u8g.setPrintPos(30, 28);u8g.print(gain0);
  arr_6();
  u8g.drawStr(0,44,"TREBLE");u8g.setPrintPos(80, 44);u8g.print(treb_reg);u8g.drawStr(95,44,"dB");
  u8g.drawStr(0,54,"MIDDLE");u8g.setPrintPos(80, 54);u8g.print(mid_reg);u8g.drawStr(95,54,"dB");
  u8g.drawStr(0,64,"BASS");u8g.setPrintPos(80, 64);u8g.print(bass_reg);u8g.drawStr(95,64,"dB");
  u8g.setFont(u8g_font_profont29r); u8g.setPrintPos(78, 22);u8g.print(vol_reg+79);
   } while( u8g.nextPage() );
  }}
/////////////////////////////////////////////////////////////////

//////// TREBLE //////////////////////////////////////////////////////////////////////////////////////////////////////////////  
  if(menu==1){
   if(newPosition != oldPosition){arr_2();treb_reg=treb_reg+newPosition;arr_3();arr_1();treb_func();audio();}

   if(ir.value==IR4){treb_reg++;arr_4();cl();arr_1();treb_func();audio();}// кнопка > 
   if(ir.value==0xFFFFFFFF and gr1==1){treb_reg++;gr2=0;cl();arr_1();treb_func();audio();}// кнопка >>>>>>
   if(ir.value==IR5){treb_reg--;gr1=0;gr2=1;cl();arr_1();treb_func();audio();}// кнопка <
   if(ir.value==0xFFFFFFFF and gr2==1){treb_reg--;gr1=0;cl();arr_1();treb_func();audio();}// кнопка <<<<<<
   
  if(w==1){w=0;
  u8g.firstPage();  
   do {
  u8g.setFont(u8g_font_profont29r); u8g.setPrintPos(78, 22);u8g.print(treb_reg);
  arr_6();
  u8g.setFont(u8g_font_profont12r);u8g.drawStr(0,8,"TREBLE");u8g.drawStr(0,44,"MIDDLE");u8g.setPrintPos(80, 44);u8g.print(mid_reg);u8g.drawStr(95,44,"dB");
  u8g.drawStr(0,54,"BASS");u8g.setPrintPos(80, 54);u8g.print(bass_reg);u8g.drawStr(95,54,"dB");
  u8g.drawStr(0,64,"VOLUME");u8g.setPrintPos(80, 64);u8g.print(vol_reg+79);u8g.drawStr(95,64,"dB");
   } while( u8g.nextPage() );
  }}
/////////////////////////////////////////////////////////////////

//////// MIDDLE //////////////////////////////////////////////////////////////////////////////////////////////////////////////  
  if(menu==2){
   if(newPosition != oldPosition){arr_2();mid_reg=mid_reg+newPosition;arr_3();arr_1();mid_func();audio();}

   if(ir.value==IR4){mid_reg++;arr_4();cl();arr_1();mid_func();audio();}// кнопка > 
   if(ir.value==0xFFFFFFFF and gr1==1){mid_reg++;gr2=0;cl();arr_1();mid_func();audio();}// кнопка >>>>>>
   if(ir.value==IR5){mid_reg--;gr1=0;gr2=1;cl();arr_1();mid_func();audio();}// кнопка <
   if(ir.value==0xFFFFFFFF and gr2==1){mid_reg--;gr1=0;cl();arr_1();mid_func();audio();}// кнопка <<<<<<
 
  if(w==1){w=0;
  u8g.firstPage();  
   do {
  u8g.setFont(u8g_font_profont29r); u8g.setPrintPos(78, 22);u8g.print(mid_reg);
  arr_6();
  u8g.setFont(u8g_font_profont12r);u8g.drawStr(0,8,"MIDDLE");u8g.drawStr(0,44,"BASS");u8g.setPrintPos(80, 44);u8g.print(bass_reg);u8g.drawStr(95,44,"dB");
  u8g.drawStr(0,54,"VOLUME");u8g.setPrintPos(80, 54);u8g.print(vol_reg+79);u8g.drawStr(95,54,"dB");
  u8g.drawStr(0,64,"TREBLE");u8g.setPrintPos(80, 64);u8g.print(treb_reg);u8g.drawStr(95,64,"dB");
   } while( u8g.nextPage() );
  }}
/////////////////////////////////////////////////////////////////

//////// BASS //////////////////////////////////////////////////////////////////////////////////////////////////////////////  
  if(menu==3){
   if(newPosition != oldPosition){arr_2();bass_reg=bass_reg+newPosition;arr_3();arr_1();bass_func();audio();}

   if(ir.value==IR4){bass_reg++;arr_4();cl();arr_1();bass_func();audio();}// кнопка > 
   if(ir.value==0xFFFFFFFF and gr1==1){bass_reg++;gr2=0;cl();arr_1();bass_func();audio();}// кнопка >>>>>>
   if(ir.value==IR5){bass_reg--;gr1=0;gr2=1;cl();arr_1();bass_func();audio();}// кнопка <
   if(ir.value==0xFFFFFFFF and gr2==1){bass_reg--;gr1=0;cl();arr_1();bass_func();audio();}// кнопка <<<<<<
 
  if(w==1){w=0;
  u8g.firstPage();  
   do {
  u8g.setFont(u8g_font_profont29r); u8g.setPrintPos(78, 22);u8g.print(bass_reg);
  arr_6();
  u8g.setFont(u8g_font_profont12r);u8g.drawStr(0,8,"BASS");u8g.drawStr(0,44,"VOLUME");u8g.setPrintPos(80, 44);u8g.print(vol_reg+79);u8g.drawStr(95,44,"dB");
  u8g.drawStr(0,54,"TREBLE");u8g.setPrintPos(80, 54);u8g.print(mid_reg);u8g.drawStr(95,54,"dB");
  u8g.drawStr(0,64,"MIDDLE");u8g.setPrintPos(80, 64);u8g.print(treb_reg);u8g.drawStr(95,64,"dB");
   } while( u8g.nextPage() );
  }}
/////////////////////////////////////////////////////////////////

////////////// INPUT GAIN ///////////////////////////////////////////////////////////////////
 if(menu==4){
  arr_7();
  if (newPosition != oldPosition){arr_5();gain0=gain0+newPosition;arr_3();arr_1();www=1;gain_func();}
  switch(in_reg){
    case 1: gain1=gain0;break;
    case 2: gain2=gain0;break;
    case 3: gain3=gain0;break;
    } 
  if(www==1){audio();www=0;}
  if(w==1){w=0;
  u8g.firstPage();  
   do {
  u8g.setFont(u8g_font_profont29r); u8g.setPrintPos(78, 22);u8g.print(in_reg);  
  arr_6();
  u8g.setFont(u8g_font_profont12r);u8g.drawStr(0,8,"INPUT");u8g.drawStr(0,44,"GAIN");
  u8g.setFont(u8g_font_profont29r); u8g.setPrintPos(78, 60);u8g.print(gain0);
    } while( u8g.nextPage() );
  }}

/////////// loudness att/freq /////////////////////
if(menu==5){
  if (newPosition != oldPosition){arr_5();lon=lon-newPosition;arr_3();w=1;lon_func();audio();}
  if(digitalRead(IN1)==LOW){lon_f++;if(lon_f>3){lon_f=0;}w=1;;audio();delay(200);}
  if(w==1){w=0;EEPROM.update(8,lon);EEPROM.update(9,lon_f);
  u8g.firstPage();  
   do {
  u8g.setFont(u8g_font_profont12r);u8g.drawStr(0,8,"LOUDNESS ATTENUATION");u8g.setPrintPos(50, 22);u8g.print(-lon);u8g.drawStr(80,22,"dB");
  arr_6();
  u8g.drawStr(0,44,"LOUDNESS FREQUENCY"); 
   switch(lon_f){
    case 0: u8g.drawStr(50, 60," FLAT");break;
    case 1: u8g.drawStr(50, 60," 400Hz");break;
    case 2: u8g.drawStr(50, 60," 800Hz");break;
    case 3: u8g.drawStr(50, 60,"2400Hz");break;} 
    } while( u8g.nextPage() );
  }}  

///////////// out att ///////////////////////////////
if(menu==6){
  if(digitalRead(IN1)==LOW){out++;if(out>4){out=0;}w=1;delay(200);}
  switch(out){
    case 0: out_att=fr;break;
    case 1: out_att=fl;break;
    case 2: out_att=rl;break;
    case 3: out_att=rr;break;
    case 4: out_att=sab;break;
    }
  if (newPosition != oldPosition){arr_5();out_att=out_att+newPosition;arr_3();w=1;att_func();www=1;}
  switch(out){
    case 0: fr=out_att;break;
    case 1: fl=out_att;break;
    case 2: rl=out_att;break;
    case 3: rr=out_att;break;
    case 4: sab=out_att;break;
    }
  if(www==1){audio();www=0; EEPROM.update(10,fr);EEPROM.update(11,fl);EEPROM.update(12,rl);EEPROM.update(13,rr);EEPROM.update(14,sab);}
  if(w==1){w=0;
  u8g.firstPage();  
   do {
  u8g.setFont(u8g_font_profont12r);u8g.drawStr(0,8,"OUTPUT"); 
  switch(out){
    case 0: u8g.drawStr(45,8,"FR");break;
    case 1: u8g.drawStr(45,8,"FL");break;
    case 2: u8g.drawStr(45,8,"RL");break;
    case 3: u8g.drawStr(45,8,"RR");break;
    case 4: u8g.drawStr(45,8,"SAB");break;
    }
  u8g.setPrintPos(50, 22);u8g.print(out_att);u8g.drawStr(80,22,"dB");
    } while( u8g.nextPage() );
  }} 
///////////////////////////////////////////////////////////////////
  
/////////// treb f /////////////////////
if(menu==7){
  if (newPosition != oldPosition){arr_5();treb_f=treb_f+newPosition;arr_3();w=1;treb_f_func();audio();}
  if(w==1){w=0;EEPROM.update(15,treb_f);
  u8g.firstPage();  
   do {
  u8g.setFont(u8g_font_profont12r);u8g.drawStr(0,8,"TREBLE CENTER FREQ");
   switch(treb_f){
    case 0: u8g.drawStr(40, 22,"10.0 kHz");break;
    case 1: u8g.drawStr(40, 22,"12.5 kHz");break;
    case 2: u8g.drawStr(40, 22,"15.0 kHz");break;
    case 3: u8g.drawStr(40, 22,"17.5 kHz");break;} 
    } while( u8g.nextPage() );
  }} 

/////////// middle f/q /////////////////////
if(menu==8){
  if (newPosition != oldPosition){arr_5();mid_f=mid_f+newPosition;arr_3();w=1;mid_f_func();audio();}
  if(digitalRead(IN1)==LOW){mid_q++;mid_q_func();w=1;audio();delay(200);}
  if(w==1){w=0;EEPROM.update(16,mid_f);EEPROM.update(17,mid_q);
  u8g.firstPage();  
   do {
  u8g.setFont(u8g_font_profont12r);u8g.drawStr(0,8,"MIDDLE CENTER FREQ");
   switch(mid_f){
    case 0: u8g.drawStr(40, 22,"0.5 kHz");break;
    case 1: u8g.drawStr(40, 22,"1.0 kHz");break;
    case 2: u8g.drawStr(40, 22,"1.5 kHz");break;
    case 3: u8g.drawStr(40, 22,"2.5 kHz");break;}
  arr_6();
  u8g.drawStr(0,44,"MIDDLE Q FACTOR"); 
   switch(mid_q){
    case 0: u8g.drawStr(50, 60,"0.50");break;
    case 1: u8g.drawStr(50, 60,"0.75");break;
    case 2: u8g.drawStr(50, 60,"1.00");break;
    case 3: u8g.drawStr(50, 60,"1.25");break;} 
    } while( u8g.nextPage() );
  }}   

/////////// bass f/q /////////////////////
if(menu==9){
  if (newPosition != oldPosition){arr_5();bass_f=bass_f+newPosition;arr_3();w=1;bass_f_func();audio();}
  if(digitalRead(IN1)==LOW){bass_q++;bass_q_func();w=1;audio();delay(200);}
  if(w==1){w=0;EEPROM.update(18,bass_f);EEPROM.update(19,bass_q);
  u8g.firstPage();  
   do {
  u8g.setFont(u8g_font_profont12r);u8g.drawStr(0,8,"BASS CENTER FREQ");
   switch(bass_f){
    case 0: u8g.drawStr(40, 22," 60 Hz");break;
    case 1: u8g.drawStr(40, 22," 80 Hz");break;
    case 2: u8g.drawStr(40, 22,"100 Hz");break;
    case 3: u8g.drawStr(40, 22,"200 Hz");break;}
  arr_6();
  u8g.drawStr(0,44,"BASS Q FACTOR"); 
   switch(bass_q){
    case 0: u8g.drawStr(50, 60,"1.00");break;
    case 1: u8g.drawStr(50, 60,"1.25");break;
    case 2: u8g.drawStr(50, 60,"1.50");break;
    case 3: u8g.drawStr(50, 60,"2.00");break;} 
    } while( u8g.nextPage() );
  }}   

/////////// sab f /////////////////////
if(menu==10){
  if (newPosition != oldPosition){arr_5();sab_f=sab_f+newPosition;arr_3();w=1;sab_f_func();audio();}
  if(w==1){w=0;EEPROM.update(20,sab_f);
  u8g.firstPage();  
   do {
  u8g.setFont(u8g_font_profont12r);u8g.drawStr(0,8,"SUBWOOFER CENTER FREQ");
   switch(sab_f){
    case 0: u8g.drawStr(40, 22," FLAT ");break;
    case 1: u8g.drawStr(40, 22," 80 Hz");break;
    case 2: u8g.drawStr(40, 22,"120 Hz");break;
    case 3: u8g.drawStr(40, 22,"160 Hz");break;}
    } while( u8g.nextPage() );
  }}    

  
if(millis()-times1>TIME_SPEC*1000&&mute==1&&(menu<5||menu>50)){menu=100;spec_func();
  if(newPosition != oldPosition){arr_5();myEnc.write(0);times1=millis();menu=0;w=1;}}
  
if(millis()-times>3000 && w1==1 && menu<5){
     EEPROM.update(0,vol_reg+79);EEPROM.update(1,treb_reg+15);EEPROM.update(2,mid_reg+15);EEPROM.update(3,bass_reg+15);
     EEPROM.update(4,in_reg);EEPROM.update(5,gain1);EEPROM.update(6,gain2);EEPROM.update(7,gain3);
      
     menu=0;w1=0;w=1;myEnc.write(0);}

} // end loop

void arr_7(){switch(in_reg){
    case 1: gain0=gain1;break;
    case 2: gain0=gain2;break;
    case 3: gain0=gain3;break;
    }}
void arr_6(){u8g.drawLine(0, 32, 128, 32);}
void arr_5(){oldPosition = newPosition;}
void arr_4(){gr1=1;gr2=0;}
void arr_3(){myEnc.write(0);newPosition=0;}
void arr_2(){arr_5();if(newPosition>1){newPosition=1;}if(newPosition<-1){newPosition=-1;}}
void arr_1(){times=millis();times1=millis();w=1;w1=1;}
void cl(){ir.value=0;delay(300);}
void sab_f_func(){if(sab_f>3){sab_f=0;}if(sab_f<0){sab_f=3;}}
void bass_q_func(){if(bass_q>3){bass_q=0;}if(bass_q<0){bass_q=3;}}
void bass_f_func(){if(bass_f>3){bass_f=0;}if(bass_f<0){bass_f=3;}}
void mid_q_func(){if(mid_q>3){mid_q=0;}if(mid_q<0){mid_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 att_func(){if(out_att>15){out_att=15;}if(out_att<0){out_att=0;}}
void lon_func(){if(lon<0){lon=0;}if(lon>15){lon=15;}}
void gain_func(){if(gain0>15){gain0=15;}if(gain0<0){gain0=0;}}
void bass_func(){if(bass_reg<-15){bass_reg=-15;}if(bass_reg>15){bass_reg=15;}}
void mid_func(){if(mid_reg<-15){mid_reg=-15;}if(mid_reg>15){mid_reg=15;}}  
void treb_func(){if(treb_reg<-15){treb_reg=-15;}if(treb_reg>15){treb_reg=15;}}  
void vol_func(){if(vol_reg<-79){vol_reg=-79;}if(vol_reg>15){vol_reg=15;}}
void to_Timer(){newPosition = myEnc.read()/4;} 
void audio(){
  tda.setInput(in_reg,gain0,0);    //вх1=1, вх2=2, вх3=3
  tda.setInput2(0,0,0);   // не используется
  tda.setAtt_loudness(lon,lon_f,0,0);
  tda.setSoft(mute,0,0,0,0);//mute  = 1 off 
  tda.setVolume(vol_reg,0);   // общая громкость int = -79...+15
  tda.setAtt_LF(64+fl,0);   // гром. лк фронт
  tda.setAtt_RF(64+fr,0);   // гром. пк фронт
  tda.setAtt_LT(64+rl,0);   // гром. лк тыл
  tda.setAtt_RT(64+rr,0);   // гром. пк тыл
  tda.setAtt_SUB(64+sab,0);  // гром. савбуфер
  tda.setAtt_Mix(79,0);   // не использует
  tda.setFilter_Treble(treb_reg,treb_f,0); 
  tda.setFilter_Middle(mid_reg,mid_q,0);
  tda.setFilter_Bass(bass_reg,bass_q,0);
  tda.setSub_M_B(sab_f,mid_f,bass_f,0,0);
  tda.setMix_Gain_Eff(1,0,0,0,0); // не используется
  tda.setSpektor(2,0,1,0,1,0,0);
}

void spec_func(){
  //// spectrum analyzer //////////////////////////////////////
  digitalWrite(A1,LOW);digitalWrite(A1,HIGH);delay(SPED_SPEC);
  for(int i=0;i<7;i++){
  digitalWrite(A1,LOW);digitalWrite(A1,HIGH);
  spektor[i]=analogRead(A0)*2;
  if(spektor[i]<SIG_0_SPEC){spektor[i]=0;}}
  u8g.firstPage(); do {
  for (int pos = 0; pos < 7; pos++) {
  for (int v_pos=0; v_pos<spektor[pos]+4;v_pos+=4){u8g.drawBox(pos*19, 61-v_pos, 13, 2);}}
  } while( u8g.nextPage() );
  }
 

2

Re: TDA7419 + OLED1.3 + ENCODER + IR + Spectrum Analyzer (LGT8F328)

Отключение дисплея при отсутствии сигнала на входе регулятора в течении 60 секунд.

Serial.port не работает, заранее внесите в скетч коды кнопок

// TDA7419 + OLED1.3 + ENCODER + IR + Spectrum Analyzer
// rcl-radio.ru
// liman324@yandex.ru
// Alexander Liman

#define IR2       0x807FF00F // button encoder
#define MUTE_IR   0x807FF807 // mute
#define IR4       0x807F48B7 // >>>
#define IR5       0x807FC837 // <<<
#define IN1_IR    0x807F38C7 // IN1
#define IN2_IR    0x807FB847 // IN2
#define IN3_IR    0x807F7887 // IN3

#define GAIN_SPEC    2.0
#define SIG_0_SPEC   7
#define SPED_SPEC    25 // mS
#define TIME_SPEC    15 // S
#define OLED_OFF     60 // S

#define ENC_DT       9
#define ENC_CLK      8
#define ENC_SW       10
#define IR           12
#define IN1          2
#define IN2          3
#define IN3          4
#define SET          5
#define MUTE         6

#include <Wire.h> 
#include <U8glib.h>            // https://github.com/olikraus/u8glib/
#include <MsTimer2.h>          // http://rcl-radio.ru/wp-content/uploads/2018/11/MsTimer2.zip 
#include <TDA7419.h>           // https://github.com/liman324/TDA7419.git
#include <Encoder.h>           // http://rcl-radio.ru/wp-content/uploads/2019/05/Encoder.zip 
#include <EEPROM.h>
#include <boarddefs.h>         // входит в состав библиотеки IRremote
#include <IRremote.h>          // http://rcl-radio.ru/wp-content/uploads/2019/06/IRremote.zip
 
TDA7419 tda;
Encoder myEnc(ENC_DT, ENC_CLK);
U8GLIB_SH1106_128X64 u8g(U8G_I2C_OPT_DEV_0|U8G_I2C_OPT_FAST);
IRrecv irrecv(IR); 
decode_results ir; 

long times,oldPosition  = -999,newPosition, times1;
byte spektor[7];
int menu,vol_reg,in_reg,treb_reg,mid_reg,bass_reg,treb_f,gain0,gain1,gain2,gain3;
int lon,lon_f;
bool w=1,w1,gr1,gr2,www,set,mute=1;
byte ur[7],urr[7];
int fr,fl,rr,rl,sab,out_att,out,mid_f,mid_q,sab_f,bass_f,bass_q;
long tim;
int tic;

void setup(){
  Wire.begin();//Serial.begin(9600);
  analogReadResolution(8);
  analogReference(INTERNAL1V024);
  irrecv.enableIRIn();
  pinMode(A0,INPUT);          // SAOUT TDA7419
  pinMode(A1,OUTPUT);         // SAIN  TDA7419
  pinMode(IN1,INPUT_PULLUP);  //  IN1  TDA7419
  pinMode(IN2,INPUT_PULLUP);  //  IN2  TDA7419
  pinMode(IN3,INPUT_PULLUP);  //  IN3  TDA7419
  pinMode(SET,INPUT_PULLUP);  //  SET  TDA7419
  pinMode(MUTE,INPUT_PULLUP); // MUTE  TDA7419
  MsTimer2::set(1, to_Timer);MsTimer2::start();
  vol_reg = EEPROM.read(0)-79;treb_reg = EEPROM.read(1)-15;mid_reg = EEPROM.read(2)-15;bass_reg = EEPROM.read(3)-15;
  in_reg = EEPROM.read(4);gain1 = EEPROM.read(5);gain2 = EEPROM.read(6);gain3 = EEPROM.read(7);
  lon = EEPROM.read(8);lon_f = EEPROM.read(9);
  fr = EEPROM.read(10);fl = EEPROM.read(11);rl = EEPROM.read(12);rr = EEPROM.read(13);sab = EEPROM.read(14);
  treb_f = EEPROM.read(15);mid_f = EEPROM.read(16);mid_q = EEPROM.read(17);
  bass_f = EEPROM.read(18);bass_q = EEPROM.read(19);sab_f = EEPROM.read(20);
  arr_7();
  delay(500);audio();
  }

void loop(){
/// IR ////////////////////////////////////////
 if ( irrecv.decode( &ir )) {irrecv.resume();}// IR приемник - чтение, в мониторе порта отображаются коды кнопок
 if(ir.value==0){gr1=0;gr2=0;}// запрет нажатий не активных кнопок пульта  
//////// BUTTON ////////////////////////////////////////////////
 if(digitalRead(ENC_SW)==LOW&&menu<5||ir.value==IR2){menu++;cl();if(menu>3){menu=0;}arr_1();delay(200);}
 if(digitalRead(IN1)==LOW&&menu<5||ir.value==IN1_IR){menu=4;cl();in_reg=1;arr_1();www=1;;delay(200);}
 if(digitalRead(IN2)==LOW&&menu<5||ir.value==IN2_IR){menu=4;cl();in_reg=2;arr_1();www=1;delay(200);}
 if(digitalRead(IN3)==LOW&&menu<5||ir.value==IN3_IR){menu=4;cl();in_reg=3;arr_1();www=1;delay(200);}
 if(digitalRead(SET)==LOW&&set==0){menu=5;set=1;times1=millis();w=1;delay(200);}
 if(digitalRead(SET)==LOW&&set==1){menu=0;set=0;;arr_1();www=1;delay(200);}
 if(digitalRead(ENC_SW)==LOW&&menu>4){menu++;if(menu>10){menu=0;}times1=millis();w=1;set=0;delay(200);}
 if((digitalRead(MUTE)==LOW||ir.value==MUTE_IR)&&mute==1){mute=0;menu=100;cl();
 u8g.firstPage();do {u8g.setFont(u8g_font_profont12r);u8g.drawStr(53,30,"MUTE");} while( u8g.nextPage() );audio();delay(200);}
 if((digitalRead(MUTE)==LOW||ir.value==MUTE_IR)&&mute==0){mute=1;menu=0;cl();arr_1();audio();delay(200);}
///////////////////////////////////////////////////////////////
  
//////// VOLUME //////////////////////////////////////////////////////////////////////////////////////////////////////////////  
  if(menu==0){
   if(newPosition != oldPosition){arr_2();vol_reg=vol_reg+newPosition;arr_3();arr_1();vol_func();audio();}
 
   if(ir.value==IR4){vol_reg++;arr_4();cl();arr_1();vol_func();audio();}// кнопка > 
   if(ir.value==0xFFFFFFFF and gr1==1){vol_reg++;gr2=0;cl();arr_1();vol_func();audio();}// кнопка >>>>>>
   if(ir.value==IR5){vol_reg--;gr1=0;gr2=1;cl();arr_1();vol_func();audio();}// кнопка <
   if(ir.value==0xFFFFFFFF and gr2==1){vol_reg--;gr1=0;cl();arr_1();vol_func();audio();}// кнопка <<<<<<
 
  if(w==1){w=0;
  u8g.firstPage();  
   do {
  u8g.setFont(u8g_font_profont12r);u8g.drawStr(0,8,"VOLUME");u8g.drawStr(0,18,"IN");
  u8g.setPrintPos(20, 18);u8g.print(in_reg);u8g.drawStr(0,28,"GAIN");u8g.setPrintPos(30, 28);u8g.print(gain0);
  arr_6();
  u8g.drawStr(0,44,"TREBLE");u8g.setPrintPos(80, 44);u8g.print(treb_reg);u8g.drawStr(95,44,"dB");
  u8g.drawStr(0,54,"MIDDLE");u8g.setPrintPos(80, 54);u8g.print(mid_reg);u8g.drawStr(95,54,"dB");
  u8g.drawStr(0,64,"BASS");u8g.setPrintPos(80, 64);u8g.print(bass_reg);u8g.drawStr(95,64,"dB");
  u8g.setFont(u8g_font_profont29r); u8g.setPrintPos(78, 22);u8g.print(vol_reg+79);
   } while( u8g.nextPage() );
  }}
/////////////////////////////////////////////////////////////////

//////// TREBLE //////////////////////////////////////////////////////////////////////////////////////////////////////////////  
  if(menu==1){
   if(newPosition != oldPosition){arr_2();treb_reg=treb_reg+newPosition;arr_3();arr_1();treb_func();audio();}

   if(ir.value==IR4){treb_reg++;arr_4();cl();arr_1();treb_func();audio();}// кнопка > 
   if(ir.value==0xFFFFFFFF and gr1==1){treb_reg++;gr2=0;cl();arr_1();treb_func();audio();}// кнопка >>>>>>
   if(ir.value==IR5){treb_reg--;gr1=0;gr2=1;cl();arr_1();treb_func();audio();}// кнопка <
   if(ir.value==0xFFFFFFFF and gr2==1){treb_reg--;gr1=0;cl();arr_1();treb_func();audio();}// кнопка <<<<<<
   
  if(w==1){w=0;
  u8g.firstPage();  
   do {
  u8g.setFont(u8g_font_profont29r); u8g.setPrintPos(78, 22);u8g.print(treb_reg);
  arr_6();
  u8g.setFont(u8g_font_profont12r);u8g.drawStr(0,8,"TREBLE");u8g.drawStr(0,44,"MIDDLE");u8g.setPrintPos(80, 44);u8g.print(mid_reg);u8g.drawStr(95,44,"dB");
  u8g.drawStr(0,54,"BASS");u8g.setPrintPos(80, 54);u8g.print(bass_reg);u8g.drawStr(95,54,"dB");
  u8g.drawStr(0,64,"VOLUME");u8g.setPrintPos(80, 64);u8g.print(vol_reg+79);u8g.drawStr(95,64,"dB");
   } while( u8g.nextPage() );
  }}
/////////////////////////////////////////////////////////////////

//////// MIDDLE //////////////////////////////////////////////////////////////////////////////////////////////////////////////  
  if(menu==2){
   if(newPosition != oldPosition){arr_2();mid_reg=mid_reg+newPosition;arr_3();arr_1();mid_func();audio();}

   if(ir.value==IR4){mid_reg++;arr_4();cl();arr_1();mid_func();audio();}// кнопка > 
   if(ir.value==0xFFFFFFFF and gr1==1){mid_reg++;gr2=0;cl();arr_1();mid_func();audio();}// кнопка >>>>>>
   if(ir.value==IR5){mid_reg--;gr1=0;gr2=1;cl();arr_1();mid_func();audio();}// кнопка <
   if(ir.value==0xFFFFFFFF and gr2==1){mid_reg--;gr1=0;cl();arr_1();mid_func();audio();}// кнопка <<<<<<
 
  if(w==1){w=0;
  u8g.firstPage();  
   do {
  u8g.setFont(u8g_font_profont29r); u8g.setPrintPos(78, 22);u8g.print(mid_reg);
  arr_6();
  u8g.setFont(u8g_font_profont12r);u8g.drawStr(0,8,"MIDDLE");u8g.drawStr(0,44,"BASS");u8g.setPrintPos(80, 44);u8g.print(bass_reg);u8g.drawStr(95,44,"dB");
  u8g.drawStr(0,54,"VOLUME");u8g.setPrintPos(80, 54);u8g.print(vol_reg+79);u8g.drawStr(95,54,"dB");
  u8g.drawStr(0,64,"TREBLE");u8g.setPrintPos(80, 64);u8g.print(treb_reg);u8g.drawStr(95,64,"dB");
   } while( u8g.nextPage() );
  }}
/////////////////////////////////////////////////////////////////

//////// BASS //////////////////////////////////////////////////////////////////////////////////////////////////////////////  
  if(menu==3){
   if(newPosition != oldPosition){arr_2();bass_reg=bass_reg+newPosition;arr_3();arr_1();bass_func();audio();}

   if(ir.value==IR4){bass_reg++;arr_4();cl();arr_1();bass_func();audio();}// кнопка > 
   if(ir.value==0xFFFFFFFF and gr1==1){bass_reg++;gr2=0;cl();arr_1();bass_func();audio();}// кнопка >>>>>>
   if(ir.value==IR5){bass_reg--;gr1=0;gr2=1;cl();arr_1();bass_func();audio();}// кнопка <
   if(ir.value==0xFFFFFFFF and gr2==1){bass_reg--;gr1=0;cl();arr_1();bass_func();audio();}// кнопка <<<<<<
 
  if(w==1){w=0;
  u8g.firstPage();  
   do {
  u8g.setFont(u8g_font_profont29r); u8g.setPrintPos(78, 22);u8g.print(bass_reg);
  arr_6();
  u8g.setFont(u8g_font_profont12r);u8g.drawStr(0,8,"BASS");u8g.drawStr(0,44,"VOLUME");u8g.setPrintPos(80, 44);u8g.print(vol_reg+79);u8g.drawStr(95,44,"dB");
  u8g.drawStr(0,54,"TREBLE");u8g.setPrintPos(80, 54);u8g.print(mid_reg);u8g.drawStr(95,54,"dB");
  u8g.drawStr(0,64,"MIDDLE");u8g.setPrintPos(80, 64);u8g.print(treb_reg);u8g.drawStr(95,64,"dB");
   } while( u8g.nextPage() );
  }}
/////////////////////////////////////////////////////////////////

////////////// INPUT GAIN ///////////////////////////////////////////////////////////////////
 if(menu==4){
  arr_7();
  if (newPosition != oldPosition){arr_5();gain0=gain0+newPosition;arr_3();arr_1();www=1;gain_func();}
  switch(in_reg){
    case 1: gain1=gain0;break;
    case 2: gain2=gain0;break;
    case 3: gain3=gain0;break;
    } 
  if(www==1){audio();www=0;}
  if(w==1){w=0;
  u8g.firstPage();  
   do {
  u8g.setFont(u8g_font_profont29r); u8g.setPrintPos(78, 22);u8g.print(in_reg);  
  arr_6();
  u8g.setFont(u8g_font_profont12r);u8g.drawStr(0,8,"INPUT");u8g.drawStr(0,44,"GAIN");
  u8g.setFont(u8g_font_profont29r); u8g.setPrintPos(78, 60);u8g.print(gain0);
    } while( u8g.nextPage() );
  }}

/////////// loudness att/freq /////////////////////
if(menu==5){
  if (newPosition != oldPosition){arr_5();lon=lon-newPosition;arr_3();w=1;lon_func();audio();}
  if(digitalRead(IN1)==LOW){lon_f++;if(lon_f>3){lon_f=0;}w=1;;audio();delay(200);}
  if(w==1){w=0;EEPROM.update(8,lon);EEPROM.update(9,lon_f);
  u8g.firstPage();  
   do {
  u8g.setFont(u8g_font_profont12r);u8g.drawStr(0,8,"LOUDNESS ATTENUATION");u8g.setPrintPos(50, 22);u8g.print(-lon);u8g.drawStr(80,22,"dB");
  arr_6();
  u8g.drawStr(0,44,"LOUDNESS FREQUENCY"); 
   switch(lon_f){
    case 0: u8g.drawStr(50, 60," FLAT");break;
    case 1: u8g.drawStr(50, 60," 400Hz");break;
    case 2: u8g.drawStr(50, 60," 800Hz");break;
    case 3: u8g.drawStr(50, 60,"2400Hz");break;} 
    } while( u8g.nextPage() );
  }}  

///////////// out att ///////////////////////////////
if(menu==6){
  if(digitalRead(IN1)==LOW){out++;if(out>4){out=0;}w=1;delay(200);}
  switch(out){
    case 0: out_att=fr;break;
    case 1: out_att=fl;break;
    case 2: out_att=rl;break;
    case 3: out_att=rr;break;
    case 4: out_att=sab;break;
    }
  if (newPosition != oldPosition){arr_5();out_att=out_att+newPosition;arr_3();w=1;att_func();www=1;}
  switch(out){
    case 0: fr=out_att;break;
    case 1: fl=out_att;break;
    case 2: rl=out_att;break;
    case 3: rr=out_att;break;
    case 4: sab=out_att;break;
    }
  if(www==1){audio();www=0; EEPROM.update(10,fr);EEPROM.update(11,fl);EEPROM.update(12,rl);EEPROM.update(13,rr);EEPROM.update(14,sab);}
  if(w==1){w=0;
  u8g.firstPage();  
   do {
  u8g.setFont(u8g_font_profont12r);u8g.drawStr(0,8,"OUTPUT"); 
  switch(out){
    case 0: u8g.drawStr(45,8,"FR");break;
    case 1: u8g.drawStr(45,8,"FL");break;
    case 2: u8g.drawStr(45,8,"RL");break;
    case 3: u8g.drawStr(45,8,"RR");break;
    case 4: u8g.drawStr(45,8,"SAB");break;
    }
  u8g.setPrintPos(50, 22);u8g.print(out_att);u8g.drawStr(80,22,"dB");
    } while( u8g.nextPage() );
  }} 
///////////////////////////////////////////////////////////////////
  
/////////// treb f /////////////////////
if(menu==7){
  if (newPosition != oldPosition){arr_5();treb_f=treb_f+newPosition;arr_3();w=1;treb_f_func();audio();}
  if(w==1){w=0;EEPROM.update(15,treb_f);
  u8g.firstPage();  
   do {
  u8g.setFont(u8g_font_profont12r);u8g.drawStr(0,8,"TREBLE CENTER FREQ");
   switch(treb_f){
    case 0: u8g.drawStr(40, 22,"10.0 kHz");break;
    case 1: u8g.drawStr(40, 22,"12.5 kHz");break;
    case 2: u8g.drawStr(40, 22,"15.0 kHz");break;
    case 3: u8g.drawStr(40, 22,"17.5 kHz");break;} 
    } while( u8g.nextPage() );
  }} 

/////////// middle f/q /////////////////////
if(menu==8){
  if (newPosition != oldPosition){arr_5();mid_f=mid_f+newPosition;arr_3();w=1;mid_f_func();audio();}
  if(digitalRead(IN1)==LOW){mid_q++;mid_q_func();w=1;audio();delay(200);}
  if(w==1){w=0;EEPROM.update(16,mid_f);EEPROM.update(17,mid_q);
  u8g.firstPage();  
   do {
  u8g.setFont(u8g_font_profont12r);u8g.drawStr(0,8,"MIDDLE CENTER FREQ");
   switch(mid_f){
    case 0: u8g.drawStr(40, 22,"0.5 kHz");break;
    case 1: u8g.drawStr(40, 22,"1.0 kHz");break;
    case 2: u8g.drawStr(40, 22,"1.5 kHz");break;
    case 3: u8g.drawStr(40, 22,"2.5 kHz");break;}
  arr_6();
  u8g.drawStr(0,44,"MIDDLE Q FACTOR"); 
   switch(mid_q){
    case 0: u8g.drawStr(50, 60,"0.50");break;
    case 1: u8g.drawStr(50, 60,"0.75");break;
    case 2: u8g.drawStr(50, 60,"1.00");break;
    case 3: u8g.drawStr(50, 60,"1.25");break;} 
    } while( u8g.nextPage() );
  }}   

/////////// bass f/q /////////////////////
if(menu==9){
  if (newPosition != oldPosition){arr_5();bass_f=bass_f+newPosition;arr_3();w=1;bass_f_func();audio();}
  if(digitalRead(IN1)==LOW){bass_q++;bass_q_func();w=1;audio();delay(200);}
  if(w==1){w=0;EEPROM.update(18,bass_f);EEPROM.update(19,bass_q);
  u8g.firstPage();  
   do {
  u8g.setFont(u8g_font_profont12r);u8g.drawStr(0,8,"BASS CENTER FREQ");
   switch(bass_f){
    case 0: u8g.drawStr(40, 22," 60 Hz");break;
    case 1: u8g.drawStr(40, 22," 80 Hz");break;
    case 2: u8g.drawStr(40, 22,"100 Hz");break;
    case 3: u8g.drawStr(40, 22,"200 Hz");break;}
  arr_6();
  u8g.drawStr(0,44,"BASS Q FACTOR"); 
   switch(bass_q){
    case 0: u8g.drawStr(50, 60,"1.00");break;
    case 1: u8g.drawStr(50, 60,"1.25");break;
    case 2: u8g.drawStr(50, 60,"1.50");break;
    case 3: u8g.drawStr(50, 60,"2.00");break;} 
    } while( u8g.nextPage() );
  }}   

/////////// sab f /////////////////////
if(menu==10){
  if (newPosition != oldPosition){arr_5();sab_f=sab_f+newPosition;arr_3();w=1;sab_f_func();audio();}
  if(w==1){w=0;EEPROM.update(20,sab_f);
  u8g.firstPage();  
   do {
  u8g.setFont(u8g_font_profont12r);u8g.drawStr(0,8,"SUBWOOFER CENTER FREQ");
   switch(sab_f){
    case 0: u8g.drawStr(40, 22," FLAT ");break;
    case 1: u8g.drawStr(40, 22," 80 Hz");break;
    case 2: u8g.drawStr(40, 22,"120 Hz");break;
    case 3: u8g.drawStr(40, 22,"160 Hz");break;}
    } while( u8g.nextPage() );
  }}    

  
if(millis()-times1>TIME_SPEC*1000&&mute==1&&(menu<5||menu>50)){menu=100;spec_func();
  if(newPosition != oldPosition){arr_5();myEnc.write(0);times1=millis();menu=0;w=1;}}
  
if(millis()-times>3000 && w1==1 && menu<5){
     EEPROM.update(0,vol_reg+79);EEPROM.update(1,treb_reg+15);EEPROM.update(2,mid_reg+15);EEPROM.update(3,bass_reg+15);
     EEPROM.update(4,in_reg);EEPROM.update(5,gain1);EEPROM.update(6,gain2);EEPROM.update(7,gain3);
      
     menu=0;w1=0;w=1;myEnc.write(0);}

} // end loop

void arr_7(){switch(in_reg){
    case 1: gain0=gain1;break;
    case 2: gain0=gain2;break;
    case 3: gain0=gain3;break;
    }}
void arr_6(){u8g.drawLine(0, 32, 128, 32);}
void arr_5(){oldPosition = newPosition;}
void arr_4(){gr1=1;gr2=0;}
void arr_3(){myEnc.write(0);newPosition=0;}
void arr_2(){arr_5();if(newPosition>1){newPosition=1;}if(newPosition<-1){newPosition=-1;}}
void arr_1(){times=millis();times1=millis();w=1;w1=1;}
void cl(){ir.value=0;delay(300);}
void sab_f_func(){if(sab_f>3){sab_f=0;}if(sab_f<0){sab_f=3;}}
void bass_q_func(){if(bass_q>3){bass_q=0;}if(bass_q<0){bass_q=3;}}
void bass_f_func(){if(bass_f>3){bass_f=0;}if(bass_f<0){bass_f=3;}}
void mid_q_func(){if(mid_q>3){mid_q=0;}if(mid_q<0){mid_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 att_func(){if(out_att>15){out_att=15;}if(out_att<0){out_att=0;}}
void lon_func(){if(lon<0){lon=0;}if(lon>15){lon=15;}}
void gain_func(){if(gain0>15){gain0=15;}if(gain0<0){gain0=0;}}
void bass_func(){if(bass_reg<-15){bass_reg=-15;}if(bass_reg>15){bass_reg=15;}}
void mid_func(){if(mid_reg<-15){mid_reg=-15;}if(mid_reg>15){mid_reg=15;}}  
void treb_func(){if(treb_reg<-15){treb_reg=-15;}if(treb_reg>15){treb_reg=15;}}  
void vol_func(){if(vol_reg<-79){vol_reg=-79;}if(vol_reg>15){vol_reg=15;}}
void to_Timer(){newPosition = myEnc.read()/4;} 
void audio(){
  tda.setInput(in_reg,gain0,0);    //вх1=1, вх2=2, вх3=3
  tda.setInput2(0,0,0);   // не используется
  tda.setAtt_loudness(lon,lon_f,0,0);
  tda.setSoft(mute,0,0,0,0);//mute  = 1 off 
  tda.setVolume(vol_reg,0);   // общая громкость int = -79...+15
  tda.setAtt_LF(64+fl,0);   // гром. лк фронт
  tda.setAtt_RF(64+fr,0);   // гром. пк фронт
  tda.setAtt_LT(64+rl,0);   // гром. лк тыл
  tda.setAtt_RT(64+rr,0);   // гром. пк тыл
  tda.setAtt_SUB(64+sab,0);  // гром. савбуфер
  tda.setAtt_Mix(79,0);   // не использует
  tda.setFilter_Treble(treb_reg,treb_f,0); 
  tda.setFilter_Middle(mid_reg,mid_q,0);
  tda.setFilter_Bass(bass_reg,bass_q,0);
  tda.setSub_M_B(sab_f,mid_f,bass_f,0,0);
  tda.setMix_Gain_Eff(1,0,0,0,0); // не используется
  tda.setSpektor(2,0,1,0,1,0,0);
}

void spec_func(){
  //// spectrum analyzer //////////////////////////////////////
  digitalWrite(A1,LOW);digitalWrite(A1,HIGH);delay(SPED_SPEC);
  for(int i=0;i<7;i++){
  digitalWrite(A1,LOW);digitalWrite(A1,HIGH);
  spektor[i]=analogRead(A0)*2;
  if(spektor[i]<SIG_0_SPEC){spektor[i]=0;}}
  if(millis()-tim>1000 && spektor[2]<SIG_0_SPEC){tic++;tim=millis();}
  if(spektor[2]>=SIG_0_SPEC){tic=0;}
  if(tic>OLED_OFF){u8g.firstPage(); do {} while( u8g.nextPage() );}
    else{
  u8g.firstPage(); do {
  for (int pos = 0; pos < 7; pos++) {
  for (int v_pos=0; v_pos<spektor[pos]+4;v_pos+=4){ u8g.drawBox(pos*19, 61-v_pos, 13, 2);}}
  } while( u8g.nextPage() );}
  }
 

3

Re: TDA7419 + OLED1.3 + ENCODER + IR + Spectrum Analyzer (LGT8F328)

Прикольный процессор. Одно плохо - куча выходов, хотя для музыки достаточно стерео.
Или можно режим стерео?

4 (2023-11-10 02:16:18 отредактировано www.aleksandrov74)

Re: TDA7419 + OLED1.3 + ENCODER + IR + Spectrum Analyzer (LGT8F328)

приветствую что то не компелируется останавливается на 
  void setup(){
  Wire.begin();Serial.begin(9600);
  analogReadResolution(8);

5

Re: TDA7419 + OLED1.3 + ENCODER + IR + Spectrum Analyzer (LGT8F328)

У Вас LGT8F328?

6 (2023-11-10 18:51:11 отредактировано www.aleksandrov74)

Re: TDA7419 + OLED1.3 + ENCODER + IR + Spectrum Analyzer (LGT8F328)

pro mini 328p . Не подходит?

7

Re: TDA7419 + OLED1.3 + ENCODER + IR + Spectrum Analyzer (LGT8F328)

analogReadResolution(8);
  analogReference(INTERNAL1V024);

заменить на

  analogReference(INTERNAL);

Потребуется корректировка усиления для анализатора

#define GAIN_SPEC    2.0

8 (2023-11-10 19:43:35 отредактировано www.aleksandrov74)

Re: TDA7419 + OLED1.3 + ENCODER + IR + Spectrum Analyzer (LGT8F328)

void setup(){
  Wire.begin();//Serial.begin(9600);
  analogReadResolution(8);
  analogReference(INTERNAL);
  irrecv.enableIRIn();
сделал так но все равно на том же месте
пока схема не собрана просто гружу скетчь в ардуинку подключен только дисплей

9

Re: TDA7419 + OLED1.3 + ENCODER + IR + Spectrum Analyzer (LGT8F328)

удалить analogReadResolution(8);

Re: TDA7419 + OLED1.3 + ENCODER + IR + Spectrum Analyzer (LGT8F328)

Все нормально загрузилось все работает! У меня лично после того, как анализатор начал свою работу,с пульта именно с пульта при увеличении или уменьшении громкости , ардуинка не подчиняется пока не покрутишь сам энкодер . Иногда при максимальной громкости виснет, пока не отключишь питание. Больше не заменил пока ничего. Да и еще немного не удобное меню выбора входа целых три кнопки. Физические куда не шло еще можно оставить, а вот на пульте путаешь постоянно .На пульте бы сделать перебором одной кнопкой .И самое главное как всегда не хватает стенбая и и вывода включения усилителя. Ну и на одном из выбора входа (например первом сделать включения блютуз и пин на ардуине).Было бы замечательно.

Re: TDA7419 + OLED1.3 + ENCODER + IR + Spectrum Analyzer (LGT8F328)

Можно попросить вас сделать это?

12

Re: TDA7419 + OLED1.3 + ENCODER + IR + Spectrum Analyzer (LGT8F328)

У меня лично после того, как анализатор начал свою работу,с пульта именно с пульта при увеличении или уменьшении громкости , ардуинка не подчиняется пока не покрутишь сам энкодер .

Я поправлю скетч, но Вам нужно будет его протестировать.

Иногда при максимальной громкости виснет, пока не отключишь питание. 

Возможно дело в питании, не вижу программных проблем которые могли бы привести к такому результату.

Да и еще немного не удобное меню выбора входа целых три кнопки. Физические куда не шло еще можно оставить, а вот на пульте путаешь постоянно .На пульте бы сделать перебором одной кнопкой .И самое главное как всегда не хватает стенбая и и вывода включения усилителя. Ну и на одном из выбора входа (например первом сделать включения блютуз и пин на ардуине).

Эти изменения я внесу после доработки первого пункта.

На днях займусь этим вопросом.

Re: TDA7419 + OLED1.3 + ENCODER + IR + Spectrum Analyzer (LGT8F328)

Спасибо !

14

Re: TDA7419 + OLED1.3 + ENCODER + IR + Spectrum Analyzer (LGT8F328)

Я про Вас не забыл, сейчас немного занят, но постараюсь сделать в течении недели.

Re: TDA7419 + OLED1.3 + ENCODER + IR + Spectrum Analyzer (LGT8F328)

Хорошо !

16

Re: TDA7419 + OLED1.3 + ENCODER + IR + Spectrum Analyzer (LGT8F328)

Тестирование - при нажатии любой кнопки пульта в режиме анализатора, происходит переход в меню регулировки громкости:

// TDA7419 + OLED1.3 + ENCODER + IR + Spectrum Analyzer
// rcl-radio.ru
// liman324@yandex.ru
// Alexander Liman

#define IR2       0x33B820DF // button encoder
#define MUTE_IR   0x33B8946B // mute
#define IR4       0x33B810EF // >>>
#define IR5       0x33B8E01F // <<<
#define IN1_IR    0x33B88877 // IN1
#define IN2_IR    0x33B848B7 // IN2
#define IN3_IR    0x33B8C837 // IN3

#define GAIN_SPEC    2.0
#define SIG_0_SPEC   7
#define SPED_SPEC    25
#define TIME_SPEC    15

#define ENC_DT       9
#define ENC_CLK      8
#define ENC_SW       10
#define IR           12
#define IN1          2
#define IN2          3
#define IN3          4
#define SET          5
#define MUTE         6

#include <Wire.h> 
#include <U8glib.h>            // https://github.com/olikraus/u8glib/
#include <MsTimer2.h>          // http://rcl-radio.ru/wp-content/uploads/2018/11/MsTimer2.zip 
#include <TDA7419.h>           // https://github.com/liman324/TDA7419.git
#include <Encoder.h>           // http://rcl-radio.ru/wp-content/uploads/2019/05/Encoder.zip 
#include <EEPROM.h>
#include <boarddefs.h>         // входит в состав библиотеки IRremote
#include <IRremote.h>          // http://rcl-radio.ru/wp-content/uploads/2019/06/IRremote.zip
 
TDA7419 tda;
Encoder myEnc(ENC_DT, ENC_CLK);
U8GLIB_SH1106_128X64 u8g(U8G_I2C_OPT_DEV_0|U8G_I2C_OPT_FAST);
IRrecv irrecv(IR); 
decode_results ir; 

long times,oldPosition  = -999,newPosition, times1;
byte spektor[7];
int menu,vol_reg,in_reg,treb_reg,mid_reg,bass_reg,treb_f,gain0,gain1,gain2,gain3;
int lon,lon_f;
bool w=1,w1,gr1,gr2,www,set,mute=1;
byte ur[7],urr[7];
int fr,fl,rr,rl,sab,out_att,out,mid_f,mid_q,sab_f,bass_f,bass_q;

void setup(){
  Wire.begin();Serial.begin(9600);
  analogReadResolution(8);
  analogReference(INTERNAL1V024);
  irrecv.enableIRIn();
  pinMode(A0,INPUT);          // SAOUT TDA7419
  pinMode(A1,OUTPUT);         // SAIN  TDA7419
  pinMode(IN1,INPUT_PULLUP);  //  IN1  TDA7419
  pinMode(IN2,INPUT_PULLUP);  //  IN2  TDA7419
  pinMode(IN3,INPUT_PULLUP);  //  IN3  TDA7419
  pinMode(SET,INPUT_PULLUP);  //  SET  TDA7419
  pinMode(MUTE,INPUT_PULLUP); // MUTE  TDA7419
  MsTimer2::set(1, to_Timer);MsTimer2::start();
  vol_reg = EEPROM.read(0)-79;treb_reg = EEPROM.read(1)-15;mid_reg = EEPROM.read(2)-15;bass_reg = EEPROM.read(3)-15;
  in_reg = EEPROM.read(4);gain1 = EEPROM.read(5);gain2 = EEPROM.read(6);gain3 = EEPROM.read(7);
  lon = EEPROM.read(8);lon_f = EEPROM.read(9);
  fr = EEPROM.read(10);fl = EEPROM.read(11);rl = EEPROM.read(12);rr = EEPROM.read(13);sab = EEPROM.read(14);
  treb_f = EEPROM.read(15);mid_f = EEPROM.read(16);mid_q = EEPROM.read(17);
  bass_f = EEPROM.read(18);bass_q = EEPROM.read(19);sab_f = EEPROM.read(20);
  arr_7();
  delay(500);audio();
  }

void loop(){
/// IR ////////////////////////////////////////
 if ( irrecv.decode( &ir )) {Serial.print("0x");Serial.println( ir.value,HEX);irrecv.resume();}// IR приемник - чтение, в мониторе порта отображаются коды кнопок
 if(ir.value==0){gr1=0;gr2=0;}// запрет нажатий не активных кнопок пульта  
//////// BUTTON ////////////////////////////////////////////////
 if(digitalRead(ENC_SW)==LOW&&menu<5||ir.value==IR2){menu++;cl();if(menu>3){menu=0;}arr_1();delay(200);}
 if(digitalRead(IN1)==LOW&&menu<5||ir.value==IN1_IR){menu=4;cl();in_reg=1;arr_1();www=1;;delay(200);}
 if(digitalRead(IN2)==LOW&&menu<5||ir.value==IN2_IR){menu=4;cl();in_reg=2;arr_1();www=1;delay(200);}
 if(digitalRead(IN3)==LOW&&menu<5||ir.value==IN3_IR){menu=4;cl();in_reg=3;arr_1();www=1;delay(200);}
 if(digitalRead(SET)==LOW&&set==0){menu=5;set=1;times1=millis();w=1;delay(200);}
 if(digitalRead(SET)==LOW&&set==1){menu=0;set=0;;arr_1();www=1;delay(200);}
 if(digitalRead(ENC_SW)==LOW&&menu>4){menu++;if(menu>10){menu=0;}times1=millis();w=1;set=0;delay(200);}
 if((digitalRead(MUTE)==LOW||ir.value==MUTE_IR)&&mute==1){mute=0;menu=100;cl();
 u8g.firstPage();do {u8g.setFont(u8g_font_profont12r);u8g.drawStr(53,30,"MUTE");} while( u8g.nextPage() );audio();delay(200);}
 if((digitalRead(MUTE)==LOW||ir.value==MUTE_IR)&&mute==0){mute=1;menu=0;cl();arr_1();audio();delay(200);}
///////////////////////////////////////////////////////////////
  
//////// VOLUME //////////////////////////////////////////////////////////////////////////////////////////////////////////////  
  if(menu==0){
   if(newPosition != oldPosition){arr_2();vol_reg=vol_reg+newPosition;arr_3();arr_1();vol_func();audio();}
 
   if(ir.value==IR4){vol_reg++;arr_4();cl();arr_1();vol_func();audio();}// кнопка > 
   if(ir.value==0xFFFFFFFF and gr1==1){vol_reg++;gr2=0;cl();arr_1();vol_func();audio();}// кнопка >>>>>>
   if(ir.value==IR5){vol_reg--;gr1=0;gr2=1;cl();arr_1();vol_func();audio();}// кнопка <
   if(ir.value==0xFFFFFFFF and gr2==1){vol_reg--;gr1=0;cl();arr_1();vol_func();audio();}// кнопка <<<<<<
 
  if(w==1){w=0;
  u8g.firstPage();  
   do {
  u8g.setFont(u8g_font_profont12r);u8g.drawStr(0,8,"VOLUME");u8g.drawStr(0,18,"IN");
  u8g.setPrintPos(20, 18);u8g.print(in_reg);u8g.drawStr(0,28,"GAIN");u8g.setPrintPos(30, 28);u8g.print(gain0);
  arr_6();
  u8g.drawStr(0,44,"TREBLE");u8g.setPrintPos(80, 44);u8g.print(treb_reg);u8g.drawStr(95,44,"dB");
  u8g.drawStr(0,54,"MIDDLE");u8g.setPrintPos(80, 54);u8g.print(mid_reg);u8g.drawStr(95,54,"dB");
  u8g.drawStr(0,64,"BASS");u8g.setPrintPos(80, 64);u8g.print(bass_reg);u8g.drawStr(95,64,"dB");
  u8g.setFont(u8g_font_profont29r); u8g.setPrintPos(78, 22);u8g.print(vol_reg+79);
   } while( u8g.nextPage() );
  }}
/////////////////////////////////////////////////////////////////

//////// TREBLE //////////////////////////////////////////////////////////////////////////////////////////////////////////////  
  if(menu==1){
   if(newPosition != oldPosition){arr_2();treb_reg=treb_reg+newPosition;arr_3();arr_1();treb_func();audio();}

   if(ir.value==IR4){treb_reg++;arr_4();cl();arr_1();treb_func();audio();}// кнопка > 
   if(ir.value==0xFFFFFFFF and gr1==1){treb_reg++;gr2=0;cl();arr_1();treb_func();audio();}// кнопка >>>>>>
   if(ir.value==IR5){treb_reg--;gr1=0;gr2=1;cl();arr_1();treb_func();audio();}// кнопка <
   if(ir.value==0xFFFFFFFF and gr2==1){treb_reg--;gr1=0;cl();arr_1();treb_func();audio();}// кнопка <<<<<<
   
  if(w==1){w=0;
  u8g.firstPage();  
   do {
  u8g.setFont(u8g_font_profont29r); u8g.setPrintPos(78, 22);u8g.print(treb_reg);
  arr_6();
  u8g.setFont(u8g_font_profont12r);u8g.drawStr(0,8,"TREBLE");u8g.drawStr(0,44,"MIDDLE");u8g.setPrintPos(80, 44);u8g.print(mid_reg);u8g.drawStr(95,44,"dB");
  u8g.drawStr(0,54,"BASS");u8g.setPrintPos(80, 54);u8g.print(bass_reg);u8g.drawStr(95,54,"dB");
  u8g.drawStr(0,64,"VOLUME");u8g.setPrintPos(80, 64);u8g.print(vol_reg+79);u8g.drawStr(95,64,"dB");
   } while( u8g.nextPage() );
  }}
/////////////////////////////////////////////////////////////////

//////// MIDDLE //////////////////////////////////////////////////////////////////////////////////////////////////////////////  
  if(menu==2){
   if(newPosition != oldPosition){arr_2();mid_reg=mid_reg+newPosition;arr_3();arr_1();mid_func();audio();}

   if(ir.value==IR4){mid_reg++;arr_4();cl();arr_1();mid_func();audio();}// кнопка > 
   if(ir.value==0xFFFFFFFF and gr1==1){mid_reg++;gr2=0;cl();arr_1();mid_func();audio();}// кнопка >>>>>>
   if(ir.value==IR5){mid_reg--;gr1=0;gr2=1;cl();arr_1();mid_func();audio();}// кнопка <
   if(ir.value==0xFFFFFFFF and gr2==1){mid_reg--;gr1=0;cl();arr_1();mid_func();audio();}// кнопка <<<<<<
 
  if(w==1){w=0;
  u8g.firstPage();  
   do {
  u8g.setFont(u8g_font_profont29r); u8g.setPrintPos(78, 22);u8g.print(mid_reg);
  arr_6();
  u8g.setFont(u8g_font_profont12r);u8g.drawStr(0,8,"MIDDLE");u8g.drawStr(0,44,"BASS");u8g.setPrintPos(80, 44);u8g.print(bass_reg);u8g.drawStr(95,44,"dB");
  u8g.drawStr(0,54,"VOLUME");u8g.setPrintPos(80, 54);u8g.print(vol_reg+79);u8g.drawStr(95,54,"dB");
  u8g.drawStr(0,64,"TREBLE");u8g.setPrintPos(80, 64);u8g.print(treb_reg);u8g.drawStr(95,64,"dB");
   } while( u8g.nextPage() );
  }}
/////////////////////////////////////////////////////////////////

//////// BASS //////////////////////////////////////////////////////////////////////////////////////////////////////////////  
  if(menu==3){
   if(newPosition != oldPosition){arr_2();bass_reg=bass_reg+newPosition;arr_3();arr_1();bass_func();audio();}

   if(ir.value==IR4){bass_reg++;arr_4();cl();arr_1();bass_func();audio();}// кнопка > 
   if(ir.value==0xFFFFFFFF and gr1==1){bass_reg++;gr2=0;cl();arr_1();bass_func();audio();}// кнопка >>>>>>
   if(ir.value==IR5){bass_reg--;gr1=0;gr2=1;cl();arr_1();bass_func();audio();}// кнопка <
   if(ir.value==0xFFFFFFFF and gr2==1){bass_reg--;gr1=0;cl();arr_1();bass_func();audio();}// кнопка <<<<<<
 
  if(w==1){w=0;
  u8g.firstPage();  
   do {
  u8g.setFont(u8g_font_profont29r); u8g.setPrintPos(78, 22);u8g.print(bass_reg);
  arr_6();
  u8g.setFont(u8g_font_profont12r);u8g.drawStr(0,8,"BASS");u8g.drawStr(0,44,"VOLUME");u8g.setPrintPos(80, 44);u8g.print(vol_reg+79);u8g.drawStr(95,44,"dB");
  u8g.drawStr(0,54,"TREBLE");u8g.setPrintPos(80, 54);u8g.print(mid_reg);u8g.drawStr(95,54,"dB");
  u8g.drawStr(0,64,"MIDDLE");u8g.setPrintPos(80, 64);u8g.print(treb_reg);u8g.drawStr(95,64,"dB");
   } while( u8g.nextPage() );
  }}
/////////////////////////////////////////////////////////////////

////////////// INPUT GAIN ///////////////////////////////////////////////////////////////////
 if(menu==4){
  arr_7();
  if (newPosition != oldPosition){arr_5();gain0=gain0+newPosition;arr_3();arr_1();www=1;gain_func();}
  switch(in_reg){
    case 1: gain1=gain0;break;
    case 2: gain2=gain0;break;
    case 3: gain3=gain0;break;
    } 
  if(www==1){audio();www=0;}
  if(w==1){w=0;
  u8g.firstPage();  
   do {
  u8g.setFont(u8g_font_profont29r); u8g.setPrintPos(78, 22);u8g.print(in_reg);  
  arr_6();
  u8g.setFont(u8g_font_profont12r);u8g.drawStr(0,8,"INPUT");u8g.drawStr(0,44,"GAIN");
  u8g.setFont(u8g_font_profont29r); u8g.setPrintPos(78, 60);u8g.print(gain0);
    } while( u8g.nextPage() );
  }}

/////////// loudness att/freq /////////////////////
if(menu==5){
  if (newPosition != oldPosition){arr_5();lon=lon-newPosition;arr_3();w=1;lon_func();audio();}
  if(digitalRead(IN1)==LOW){lon_f++;if(lon_f>3){lon_f=0;}w=1;;audio();delay(200);}
  if(w==1){w=0;EEPROM.update(8,lon);EEPROM.update(9,lon_f);
  u8g.firstPage();  
   do {
  u8g.setFont(u8g_font_profont12r);u8g.drawStr(0,8,"LOUDNESS ATTENUATION");u8g.setPrintPos(50, 22);u8g.print(-lon);u8g.drawStr(80,22,"dB");
  arr_6();
  u8g.drawStr(0,44,"LOUDNESS FREQUENCY"); 
   switch(lon_f){
    case 0: u8g.drawStr(50, 60," FLAT");break;
    case 1: u8g.drawStr(50, 60," 400Hz");break;
    case 2: u8g.drawStr(50, 60," 800Hz");break;
    case 3: u8g.drawStr(50, 60,"2400Hz");break;} 
    } while( u8g.nextPage() );
  }}  

///////////// out att ///////////////////////////////
if(menu==6){
  if(digitalRead(IN1)==LOW){out++;if(out>4){out=0;}w=1;delay(200);}
  switch(out){
    case 0: out_att=fr;break;
    case 1: out_att=fl;break;
    case 2: out_att=rl;break;
    case 3: out_att=rr;break;
    case 4: out_att=sab;break;
    }
  if (newPosition != oldPosition){arr_5();out_att=out_att+newPosition;arr_3();w=1;att_func();www=1;}
  switch(out){
    case 0: fr=out_att;break;
    case 1: fl=out_att;break;
    case 2: rl=out_att;break;
    case 3: rr=out_att;break;
    case 4: sab=out_att;break;
    }
  if(www==1){audio();www=0; EEPROM.update(10,fr);EEPROM.update(11,fl);EEPROM.update(12,rl);EEPROM.update(13,rr);EEPROM.update(14,sab);}
  if(w==1){w=0;
  u8g.firstPage();  
   do {
  u8g.setFont(u8g_font_profont12r);u8g.drawStr(0,8,"OUTPUT"); 
  switch(out){
    case 0: u8g.drawStr(45,8,"FR");break;
    case 1: u8g.drawStr(45,8,"FL");break;
    case 2: u8g.drawStr(45,8,"RL");break;
    case 3: u8g.drawStr(45,8,"RR");break;
    case 4: u8g.drawStr(45,8,"SAB");break;
    }
  u8g.setPrintPos(50, 22);u8g.print(out_att);u8g.drawStr(80,22,"dB");
    } while( u8g.nextPage() );
  }} 
///////////////////////////////////////////////////////////////////
  
/////////// treb f /////////////////////
if(menu==7){
  if (newPosition != oldPosition){arr_5();treb_f=treb_f+newPosition;arr_3();w=1;treb_f_func();audio();}
  if(w==1){w=0;EEPROM.update(15,treb_f);
  u8g.firstPage();  
   do {
  u8g.setFont(u8g_font_profont12r);u8g.drawStr(0,8,"TREBLE CENTER FREQ");
   switch(treb_f){
    case 0: u8g.drawStr(40, 22,"10.0 kHz");break;
    case 1: u8g.drawStr(40, 22,"12.5 kHz");break;
    case 2: u8g.drawStr(40, 22,"15.0 kHz");break;
    case 3: u8g.drawStr(40, 22,"17.5 kHz");break;} 
    } while( u8g.nextPage() );
  }} 

/////////// middle f/q /////////////////////
if(menu==8){
  if (newPosition != oldPosition){arr_5();mid_f=mid_f+newPosition;arr_3();w=1;mid_f_func();audio();}
  if(digitalRead(IN1)==LOW){mid_q++;mid_q_func();w=1;audio();delay(200);}
  if(w==1){w=0;EEPROM.update(16,mid_f);EEPROM.update(17,mid_q);
  u8g.firstPage();  
   do {
  u8g.setFont(u8g_font_profont12r);u8g.drawStr(0,8,"MIDDLE CENTER FREQ");
   switch(mid_f){
    case 0: u8g.drawStr(40, 22,"0.5 kHz");break;
    case 1: u8g.drawStr(40, 22,"1.0 kHz");break;
    case 2: u8g.drawStr(40, 22,"1.5 kHz");break;
    case 3: u8g.drawStr(40, 22,"2.5 kHz");break;}
  arr_6();
  u8g.drawStr(0,44,"MIDDLE Q FACTOR"); 
   switch(mid_q){
    case 0: u8g.drawStr(50, 60,"0.50");break;
    case 1: u8g.drawStr(50, 60,"0.75");break;
    case 2: u8g.drawStr(50, 60,"1.00");break;
    case 3: u8g.drawStr(50, 60,"1.25");break;} 
    } while( u8g.nextPage() );
  }}   

/////////// bass f/q /////////////////////
if(menu==9){
  if (newPosition != oldPosition){arr_5();bass_f=bass_f+newPosition;arr_3();w=1;bass_f_func();audio();}
  if(digitalRead(IN1)==LOW){bass_q++;bass_q_func();w=1;audio();delay(200);}
  if(w==1){w=0;EEPROM.update(18,bass_f);EEPROM.update(19,bass_q);
  u8g.firstPage();  
   do {
  u8g.setFont(u8g_font_profont12r);u8g.drawStr(0,8,"BASS CENTER FREQ");
   switch(bass_f){
    case 0: u8g.drawStr(40, 22," 60 Hz");break;
    case 1: u8g.drawStr(40, 22," 80 Hz");break;
    case 2: u8g.drawStr(40, 22,"100 Hz");break;
    case 3: u8g.drawStr(40, 22,"200 Hz");break;}
  arr_6();
  u8g.drawStr(0,44,"BASS Q FACTOR"); 
   switch(bass_q){
    case 0: u8g.drawStr(50, 60,"1.00");break;
    case 1: u8g.drawStr(50, 60,"1.25");break;
    case 2: u8g.drawStr(50, 60,"1.50");break;
    case 3: u8g.drawStr(50, 60,"2.00");break;} 
    } while( u8g.nextPage() );
  }}   

/////////// sab f /////////////////////
if(menu==10){
  if (newPosition != oldPosition){arr_5();sab_f=sab_f+newPosition;arr_3();w=1;sab_f_func();audio();}
  if(w==1){w=0;EEPROM.update(20,sab_f);
  u8g.firstPage();  
   do {
  u8g.setFont(u8g_font_profont12r);u8g.drawStr(0,8,"SUBWOOFER CENTER FREQ");
   switch(sab_f){
    case 0: u8g.drawStr(40, 22," FLAT ");break;
    case 1: u8g.drawStr(40, 22," 80 Hz");break;
    case 2: u8g.drawStr(40, 22,"120 Hz");break;
    case 3: u8g.drawStr(40, 22,"160 Hz");break;}
    } while( u8g.nextPage() );
  }}    

  
if(millis()-times1>TIME_SPEC*1000&&mute==1&&(menu<5||menu>50)){menu=100;spec_func();
  if(newPosition != oldPosition){arr_5();myEnc.write(0);times1=millis();menu=0;w=1;}
  if(ir.value!=0){cl();times1=millis();menu=0;w=1;}
  }
  
if(millis()-times>3000 && w1==1 && menu<5){
     EEPROM.update(0,vol_reg+79);EEPROM.update(1,treb_reg+15);EEPROM.update(2,mid_reg+15);EEPROM.update(3,bass_reg+15);
     EEPROM.update(4,in_reg);EEPROM.update(5,gain1);EEPROM.update(6,gain2);EEPROM.update(7,gain3);
      
     menu=0;w1=0;w=1;myEnc.write(0);}

} // end loop

void arr_7(){switch(in_reg){
    case 1: gain0=gain1;break;
    case 2: gain0=gain2;break;
    case 3: gain0=gain3;break;
    }}
void arr_6(){u8g.drawLine(0, 32, 128, 32);}
void arr_5(){oldPosition = newPosition;}
void arr_4(){gr1=1;gr2=0;}
void arr_3(){myEnc.write(0);newPosition=0;}
void arr_2(){arr_5();if(newPosition>1){newPosition=1;}if(newPosition<-1){newPosition=-1;}}
void arr_1(){times=millis();times1=millis();w=1;w1=1;}
void cl(){ir.value=0;delay(300);}
void sab_f_func(){if(sab_f>3){sab_f=0;}if(sab_f<0){sab_f=3;}}
void bass_q_func(){if(bass_q>3){bass_q=0;}if(bass_q<0){bass_q=3;}}
void bass_f_func(){if(bass_f>3){bass_f=0;}if(bass_f<0){bass_f=3;}}
void mid_q_func(){if(mid_q>3){mid_q=0;}if(mid_q<0){mid_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 att_func(){if(out_att>15){out_att=15;}if(out_att<0){out_att=0;}}
void lon_func(){if(lon<0){lon=0;}if(lon>15){lon=15;}}
void gain_func(){if(gain0>15){gain0=15;}if(gain0<0){gain0=0;}}
void bass_func(){if(bass_reg<-15){bass_reg=-15;}if(bass_reg>15){bass_reg=15;}}
void mid_func(){if(mid_reg<-15){mid_reg=-15;}if(mid_reg>15){mid_reg=15;}}  
void treb_func(){if(treb_reg<-15){treb_reg=-15;}if(treb_reg>15){treb_reg=15;}}  
void vol_func(){if(vol_reg<-79){vol_reg=-79;}if(vol_reg>15){vol_reg=15;}}
void to_Timer(){newPosition = myEnc.read()/4;} 
void audio(){
  tda.setInput(in_reg,gain0,0);    //вх1=1, вх2=2, вх3=3
  tda.setInput2(0,0,0);   // не используется
  tda.setAtt_loudness(lon,lon_f,0,0);
  tda.setSoft(mute,0,0,0,0);//mute  = 1 off 
  tda.setVolume(vol_reg,0);   // общая громкость int = -79...+15
  tda.setAtt_LF(64+fl,0);   // гром. лк фронт
  tda.setAtt_RF(64+fr,0);   // гром. пк фронт
  tda.setAtt_LT(64+rl,0);   // гром. лк тыл
  tda.setAtt_RT(64+rr,0);   // гром. пк тыл
  tda.setAtt_SUB(64+sab,0);  // гром. савбуфер
  tda.setAtt_Mix(79,0);   // не использует
  tda.setFilter_Treble(treb_reg,treb_f,0); 
  tda.setFilter_Middle(mid_reg,mid_q,0);
  tda.setFilter_Bass(bass_reg,bass_q,0);
  tda.setSub_M_B(sab_f,mid_f,bass_f,0,0);
  tda.setMix_Gain_Eff(1,0,0,0,0); // не используется
  tda.setSpektor(2,0,1,0,1,0,0);
}

void spec_func(){
  //// spectrum analyzer //////////////////////////////////////
  digitalWrite(A1,LOW);digitalWrite(A1,HIGH);delay(SPED_SPEC);
  for(int i=0;i<7;i++){
  digitalWrite(A1,LOW);digitalWrite(A1,HIGH);
  spektor[i]=analogRead(A0)*2;
  if(spektor[i]<SIG_0_SPEC){spektor[i]=0;}}
  u8g.firstPage(); do {
  for (int pos = 0; pos < 7; pos++) {
  for (int v_pos=0; v_pos<spektor[pos]+4;v_pos+=4){u8g.drawBox(pos*19, 61-v_pos, 13, 2);}}
  } while( u8g.nextPage() );
  }
 

17

Re: TDA7419 + OLED1.3 + ENCODER + IR + Spectrum Analyzer (LGT8F328)

Тестирование - одна кнопка INPUT, добавлена кнопка POWER, добавлен выход STANDBY = D13

// TDA7419 + OLED1.3 + ENCODER + IR + Spectrum Analyzer
// rcl-radio.ru
// liman324@yandex.ru
// Alexander Liman

#define IR2       0x33B820DF // button encoder
#define MUTE_IR   0x33B8946B // mute
#define IR4       0x33B810EF // >>>
#define IR5       0x33B8E01F // <<<
#define INPUT_IR  0x33B88877 // IN
#define POWER_IR  0x33B800FF // POWER

#define GAIN_SPEC    2.0
#define SIG_0_SPEC   7
#define SPED_SPEC    25
#define TIME_SPEC    15

#define ENC_DT       9
#define ENC_CLK      8
#define ENC_SW       10
#define IR           12
#define IN           2
#define POWER        3
#define SET          5
#define MUTE         6

#define POWER_OUT_PIN 13

#include <Wire.h> 
#include <U8glib.h>            // https://github.com/olikraus/u8glib/
#include <MsTimer2.h>          // http://rcl-radio.ru/wp-content/uploads/2018/11/MsTimer2.zip 
#include <TDA7419.h>           // https://github.com/liman324/TDA7419.git
#include <Encoder.h>           // http://rcl-radio.ru/wp-content/uploads/2019/05/Encoder.zip 
#include <EEPROM.h>
#include <boarddefs.h>         // входит в состав библиотеки IRremote
#include <IRremote.h>          // http://rcl-radio.ru/wp-content/uploads/2019/06/IRremote.zip
 
TDA7419 tda;
Encoder myEnc(ENC_DT, ENC_CLK);
U8GLIB_SH1106_128X64 u8g(U8G_I2C_OPT_DEV_0|U8G_I2C_OPT_FAST);
IRrecv irrecv(IR); 
decode_results ir; 

long times,oldPosition  = -999,newPosition, times1;
byte spektor[7];
int menu,vol_reg,in_reg,treb_reg,mid_reg,bass_reg,treb_f,gain0,gain1,gain2,gain3;
int lon,lon_f;
bool w=1,w1,gr1,gr2,www,set,mute=1,power;
byte ur[7],urr[7];
int fr,fl,rr,rl,sab,out_att,out,mid_f,mid_q,sab_f,bass_f,bass_q;

void setup(){
  Wire.begin();Serial.begin(9600);
  analogReadResolution(8);
  analogReference(INTERNAL1V024);
  irrecv.enableIRIn();
  pinMode(A0,INPUT);          // SAOUT TDA7419
  pinMode(A1,OUTPUT);         // SAIN  TDA7419
  pinMode(IN,INPUT_PULLUP);  //  IN1  TDA7419
  pinMode(POWER,INPUT_PULLUP);  //  POWER
  pinMode(SET,INPUT_PULLUP);  //  SET  TDA7419
  pinMode(MUTE,INPUT_PULLUP); // MUTE  TDA7419
  MsTimer2::set(1, to_Timer);MsTimer2::start();
  vol_reg = EEPROM.read(0)-79;treb_reg = EEPROM.read(1)-15;mid_reg = EEPROM.read(2)-15;bass_reg = EEPROM.read(3)-15;
  in_reg = EEPROM.read(4);gain1 = EEPROM.read(5);gain2 = EEPROM.read(6);gain3 = EEPROM.read(7);
  lon = EEPROM.read(8);lon_f = EEPROM.read(9);
  fr = EEPROM.read(10);fl = EEPROM.read(11);rl = EEPROM.read(12);rr = EEPROM.read(13);sab = EEPROM.read(14);
  treb_f = EEPROM.read(15);mid_f = EEPROM.read(16);mid_q = EEPROM.read(17);
  bass_f = EEPROM.read(18);bass_q = EEPROM.read(19);sab_f = EEPROM.read(20);
  arr_7();
  delay(500);audio();
  }

void loop(){
/// IR ////////////////////////////////////////
 if ( irrecv.decode( &ir )) {Serial.print("0x");Serial.println( ir.value,HEX);irrecv.resume();}// IR приемник - чтение, в мониторе порта отображаются коды кнопок
 if(ir.value==0){gr1=0;gr2=0;}// запрет нажатий не активных кнопок пульта  
//////// BUTTON ////////////////////////////////////////////////
///////// POWER ///////////////////
 if((digitalRead(POWER)==LOW||ir.value==POWER_IR)&&power==0){power=1;menu=100;cl();mute=0;audio();
  u8g.firstPage();do {u8g.setFont(u8g_font_profont12r);u8g.drawStr(40,30,"POWER OFF");} while( u8g.nextPage() );
  delay(1500); u8g.firstPage();do {} while( u8g.nextPage() );}
  
 if((digitalRead(POWER)==LOW||ir.value==POWER_IR)&&power==1){power=0;menu=0;times1=millis();mute=1;arr_1();
  u8g.firstPage();do {u8g.drawStr(42,30,"POWER ON");} while( u8g.nextPage() );delay(1500);audio();}

if(power==0){digitalWrite(POWER_OUT_PIN,HIGH);}else{digitalWrite(POWER_OUT_PIN,LOW);} 

if(power==0){
 if(digitalRead(ENC_SW)==LOW&&menu<5||ir.value==IR2){menu++;cl();if(menu>3){menu=0;}arr_1();delay(200);}
 if(digitalRead(IN)==LOW&&menu<5||ir.value==INPUT_IR){menu=4;cl();in_reg++;arr_1();www=1;if(in_reg>3){in_reg=1;};delay(200);}
 if(digitalRead(SET)==LOW&&set==0){menu=5;set=1;times1=millis();w=1;delay(200);}
 if(digitalRead(SET)==LOW&&set==1){menu=0;set=0;;arr_1();www=1;delay(200);}
 if(digitalRead(ENC_SW)==LOW&&menu>4){menu++;if(menu>10){menu=0;}times1=millis();w=1;set=0;delay(200);}
 if((digitalRead(MUTE)==LOW||ir.value==MUTE_IR)&&mute==1){mute=0;menu=100;cl();
 u8g.firstPage();do {u8g.setFont(u8g_font_profont12r);u8g.drawStr(53,30,"MUTE");} while( u8g.nextPage() );audio();delay(200);}
 if((digitalRead(MUTE)==LOW||ir.value==MUTE_IR)&&mute==0){mute=1;menu=0;cl();arr_1();audio();delay(200);}
}
///////////////////////////////////////////////////////////////
  
//////// VOLUME //////////////////////////////////////////////////////////////////////////////////////////////////////////////  
  if(menu==0){
   if(newPosition != oldPosition){arr_2();vol_reg=vol_reg+newPosition;arr_3();arr_1();vol_func();audio();}
 
   if(ir.value==IR4){vol_reg++;arr_4();cl();arr_1();vol_func();audio();}// кнопка > 
   if(ir.value==0xFFFFFFFF and gr1==1){vol_reg++;gr2=0;cl();arr_1();vol_func();audio();}// кнопка >>>>>>
   if(ir.value==IR5){vol_reg--;gr1=0;gr2=1;cl();arr_1();vol_func();audio();}// кнопка <
   if(ir.value==0xFFFFFFFF and gr2==1){vol_reg--;gr1=0;cl();arr_1();vol_func();audio();}// кнопка <<<<<<
 
  if(w==1){w=0;
  u8g.firstPage();  
   do {
  u8g.setFont(u8g_font_profont12r);u8g.drawStr(0,8,"VOLUME");u8g.drawStr(0,18,"IN");
  u8g.setPrintPos(20, 18);u8g.print(in_reg);u8g.drawStr(0,28,"GAIN");u8g.setPrintPos(30, 28);u8g.print(gain0);
  arr_6();
  u8g.drawStr(0,44,"TREBLE");u8g.setPrintPos(80, 44);u8g.print(treb_reg);u8g.drawStr(95,44,"dB");
  u8g.drawStr(0,54,"MIDDLE");u8g.setPrintPos(80, 54);u8g.print(mid_reg);u8g.drawStr(95,54,"dB");
  u8g.drawStr(0,64,"BASS");u8g.setPrintPos(80, 64);u8g.print(bass_reg);u8g.drawStr(95,64,"dB");
  u8g.setFont(u8g_font_profont29r); u8g.setPrintPos(78, 22);u8g.print(vol_reg+79);
   } while( u8g.nextPage() );
  }}
/////////////////////////////////////////////////////////////////

//////// TREBLE //////////////////////////////////////////////////////////////////////////////////////////////////////////////  
  if(menu==1){
   if(newPosition != oldPosition){arr_2();treb_reg=treb_reg+newPosition;arr_3();arr_1();treb_func();audio();}

   if(ir.value==IR4){treb_reg++;arr_4();cl();arr_1();treb_func();audio();}// кнопка > 
   if(ir.value==0xFFFFFFFF and gr1==1){treb_reg++;gr2=0;cl();arr_1();treb_func();audio();}// кнопка >>>>>>
   if(ir.value==IR5){treb_reg--;gr1=0;gr2=1;cl();arr_1();treb_func();audio();}// кнопка <
   if(ir.value==0xFFFFFFFF and gr2==1){treb_reg--;gr1=0;cl();arr_1();treb_func();audio();}// кнопка <<<<<<
   
  if(w==1){w=0;
  u8g.firstPage();  
   do {
  u8g.setFont(u8g_font_profont29r); u8g.setPrintPos(78, 22);u8g.print(treb_reg);
  arr_6();
  u8g.setFont(u8g_font_profont12r);u8g.drawStr(0,8,"TREBLE");u8g.drawStr(0,44,"MIDDLE");u8g.setPrintPos(80, 44);u8g.print(mid_reg);u8g.drawStr(95,44,"dB");
  u8g.drawStr(0,54,"BASS");u8g.setPrintPos(80, 54);u8g.print(bass_reg);u8g.drawStr(95,54,"dB");
  u8g.drawStr(0,64,"VOLUME");u8g.setPrintPos(80, 64);u8g.print(vol_reg+79);u8g.drawStr(95,64,"dB");
   } while( u8g.nextPage() );
  }}
/////////////////////////////////////////////////////////////////

//////// MIDDLE //////////////////////////////////////////////////////////////////////////////////////////////////////////////  
  if(menu==2){
   if(newPosition != oldPosition){arr_2();mid_reg=mid_reg+newPosition;arr_3();arr_1();mid_func();audio();}

   if(ir.value==IR4){mid_reg++;arr_4();cl();arr_1();mid_func();audio();}// кнопка > 
   if(ir.value==0xFFFFFFFF and gr1==1){mid_reg++;gr2=0;cl();arr_1();mid_func();audio();}// кнопка >>>>>>
   if(ir.value==IR5){mid_reg--;gr1=0;gr2=1;cl();arr_1();mid_func();audio();}// кнопка <
   if(ir.value==0xFFFFFFFF and gr2==1){mid_reg--;gr1=0;cl();arr_1();mid_func();audio();}// кнопка <<<<<<
 
  if(w==1){w=0;
  u8g.firstPage();  
   do {
  u8g.setFont(u8g_font_profont29r); u8g.setPrintPos(78, 22);u8g.print(mid_reg);
  arr_6();
  u8g.setFont(u8g_font_profont12r);u8g.drawStr(0,8,"MIDDLE");u8g.drawStr(0,44,"BASS");u8g.setPrintPos(80, 44);u8g.print(bass_reg);u8g.drawStr(95,44,"dB");
  u8g.drawStr(0,54,"VOLUME");u8g.setPrintPos(80, 54);u8g.print(vol_reg+79);u8g.drawStr(95,54,"dB");
  u8g.drawStr(0,64,"TREBLE");u8g.setPrintPos(80, 64);u8g.print(treb_reg);u8g.drawStr(95,64,"dB");
   } while( u8g.nextPage() );
  }}
/////////////////////////////////////////////////////////////////

//////// BASS //////////////////////////////////////////////////////////////////////////////////////////////////////////////  
  if(menu==3){
   if(newPosition != oldPosition){arr_2();bass_reg=bass_reg+newPosition;arr_3();arr_1();bass_func();audio();}

   if(ir.value==IR4){bass_reg++;arr_4();cl();arr_1();bass_func();audio();}// кнопка > 
   if(ir.value==0xFFFFFFFF and gr1==1){bass_reg++;gr2=0;cl();arr_1();bass_func();audio();}// кнопка >>>>>>
   if(ir.value==IR5){bass_reg--;gr1=0;gr2=1;cl();arr_1();bass_func();audio();}// кнопка <
   if(ir.value==0xFFFFFFFF and gr2==1){bass_reg--;gr1=0;cl();arr_1();bass_func();audio();}// кнопка <<<<<<
 
  if(w==1){w=0;
  u8g.firstPage();  
   do {
  u8g.setFont(u8g_font_profont29r); u8g.setPrintPos(78, 22);u8g.print(bass_reg);
  arr_6();
  u8g.setFont(u8g_font_profont12r);u8g.drawStr(0,8,"BASS");u8g.drawStr(0,44,"VOLUME");u8g.setPrintPos(80, 44);u8g.print(vol_reg+79);u8g.drawStr(95,44,"dB");
  u8g.drawStr(0,54,"TREBLE");u8g.setPrintPos(80, 54);u8g.print(mid_reg);u8g.drawStr(95,54,"dB");
  u8g.drawStr(0,64,"MIDDLE");u8g.setPrintPos(80, 64);u8g.print(treb_reg);u8g.drawStr(95,64,"dB");
   } while( u8g.nextPage() );
  }}
/////////////////////////////////////////////////////////////////

////////////// INPUT GAIN ///////////////////////////////////////////////////////////////////
 if(menu==4){
  arr_7();
  if (newPosition != oldPosition){arr_5();gain0=gain0+newPosition;arr_3();arr_1();www=1;gain_func();}
  switch(in_reg){
    case 1: gain1=gain0;break;
    case 2: gain2=gain0;break;
    case 3: gain3=gain0;break;
    } 
  if(www==1){audio();www=0;}
  if(w==1){w=0;
  u8g.firstPage();  
   do {
  u8g.setFont(u8g_font_profont29r); u8g.setPrintPos(78, 22);u8g.print(in_reg);  
  arr_6();
  u8g.setFont(u8g_font_profont12r);u8g.drawStr(0,8,"INPUT");u8g.drawStr(0,44,"GAIN");
  u8g.setFont(u8g_font_profont29r); u8g.setPrintPos(78, 60);u8g.print(gain0);
    } while( u8g.nextPage() );
  }}

/////////// loudness att/freq /////////////////////
if(menu==5){
  if (newPosition != oldPosition){arr_5();lon=lon-newPosition;arr_3();w=1;lon_func();audio();}
  if(digitalRead(IN)==LOW){lon_f++;if(lon_f>3){lon_f=0;}w=1;;audio();delay(200);}
  if(w==1){w=0;EEPROM.update(8,lon);EEPROM.update(9,lon_f);
  u8g.firstPage();  
   do {
  u8g.setFont(u8g_font_profont12r);u8g.drawStr(0,8,"LOUDNESS ATTENUATION");u8g.setPrintPos(50, 22);u8g.print(-lon);u8g.drawStr(80,22,"dB");
  arr_6();
  u8g.drawStr(0,44,"LOUDNESS FREQUENCY"); 
   switch(lon_f){
    case 0: u8g.drawStr(50, 60," FLAT");break;
    case 1: u8g.drawStr(50, 60," 400Hz");break;
    case 2: u8g.drawStr(50, 60," 800Hz");break;
    case 3: u8g.drawStr(50, 60,"2400Hz");break;} 
    } while( u8g.nextPage() );
  }}  

///////////// out att ///////////////////////////////
if(menu==6){
  if(digitalRead(IN)==LOW){out++;if(out>4){out=0;}w=1;delay(200);}
  switch(out){
    case 0: out_att=fr;break;
    case 1: out_att=fl;break;
    case 2: out_att=rl;break;
    case 3: out_att=rr;break;
    case 4: out_att=sab;break;
    }
  if (newPosition != oldPosition){arr_5();out_att=out_att+newPosition;arr_3();w=1;att_func();www=1;}
  switch(out){
    case 0: fr=out_att;break;
    case 1: fl=out_att;break;
    case 2: rl=out_att;break;
    case 3: rr=out_att;break;
    case 4: sab=out_att;break;
    }
  if(www==1){audio();www=0; EEPROM.update(10,fr);EEPROM.update(11,fl);EEPROM.update(12,rl);EEPROM.update(13,rr);EEPROM.update(14,sab);}
  if(w==1){w=0;
  u8g.firstPage();  
   do {
  u8g.setFont(u8g_font_profont12r);u8g.drawStr(0,8,"OUTPUT"); 
  switch(out){
    case 0: u8g.drawStr(45,8,"FR");break;
    case 1: u8g.drawStr(45,8,"FL");break;
    case 2: u8g.drawStr(45,8,"RL");break;
    case 3: u8g.drawStr(45,8,"RR");break;
    case 4: u8g.drawStr(45,8,"SAB");break;
    }
  u8g.setPrintPos(50, 22);u8g.print(out_att);u8g.drawStr(80,22,"dB");
    } while( u8g.nextPage() );
  }} 
///////////////////////////////////////////////////////////////////
  
/////////// treb f /////////////////////
if(menu==7){
  if (newPosition != oldPosition){arr_5();treb_f=treb_f+newPosition;arr_3();w=1;treb_f_func();audio();}
  if(w==1){w=0;EEPROM.update(15,treb_f);
  u8g.firstPage();  
   do {
  u8g.setFont(u8g_font_profont12r);u8g.drawStr(0,8,"TREBLE CENTER FREQ");
   switch(treb_f){
    case 0: u8g.drawStr(40, 22,"10.0 kHz");break;
    case 1: u8g.drawStr(40, 22,"12.5 kHz");break;
    case 2: u8g.drawStr(40, 22,"15.0 kHz");break;
    case 3: u8g.drawStr(40, 22,"17.5 kHz");break;} 
    } while( u8g.nextPage() );
  }} 

/////////// middle f/q /////////////////////
if(menu==8){
  if (newPosition != oldPosition){arr_5();mid_f=mid_f+newPosition;arr_3();w=1;mid_f_func();audio();}
  if(digitalRead(IN)==LOW){mid_q++;mid_q_func();w=1;audio();delay(200);}
  if(w==1){w=0;EEPROM.update(16,mid_f);EEPROM.update(17,mid_q);
  u8g.firstPage();  
   do {
  u8g.setFont(u8g_font_profont12r);u8g.drawStr(0,8,"MIDDLE CENTER FREQ");
   switch(mid_f){
    case 0: u8g.drawStr(40, 22,"0.5 kHz");break;
    case 1: u8g.drawStr(40, 22,"1.0 kHz");break;
    case 2: u8g.drawStr(40, 22,"1.5 kHz");break;
    case 3: u8g.drawStr(40, 22,"2.5 kHz");break;}
  arr_6();
  u8g.drawStr(0,44,"MIDDLE Q FACTOR"); 
   switch(mid_q){
    case 0: u8g.drawStr(50, 60,"0.50");break;
    case 1: u8g.drawStr(50, 60,"0.75");break;
    case 2: u8g.drawStr(50, 60,"1.00");break;
    case 3: u8g.drawStr(50, 60,"1.25");break;} 
    } while( u8g.nextPage() );
  }}   

/////////// bass f/q /////////////////////
if(menu==9){
  if (newPosition != oldPosition){arr_5();bass_f=bass_f+newPosition;arr_3();w=1;bass_f_func();audio();}
  if(digitalRead(IN)==LOW){bass_q++;bass_q_func();w=1;audio();delay(200);}
  if(w==1){w=0;EEPROM.update(18,bass_f);EEPROM.update(19,bass_q);
  u8g.firstPage();  
   do {
  u8g.setFont(u8g_font_profont12r);u8g.drawStr(0,8,"BASS CENTER FREQ");
   switch(bass_f){
    case 0: u8g.drawStr(40, 22," 60 Hz");break;
    case 1: u8g.drawStr(40, 22," 80 Hz");break;
    case 2: u8g.drawStr(40, 22,"100 Hz");break;
    case 3: u8g.drawStr(40, 22,"200 Hz");break;}
  arr_6();
  u8g.drawStr(0,44,"BASS Q FACTOR"); 
   switch(bass_q){
    case 0: u8g.drawStr(50, 60,"1.00");break;
    case 1: u8g.drawStr(50, 60,"1.25");break;
    case 2: u8g.drawStr(50, 60,"1.50");break;
    case 3: u8g.drawStr(50, 60,"2.00");break;} 
    } while( u8g.nextPage() );
  }}   

/////////// sab f /////////////////////
if(menu==10){
  if (newPosition != oldPosition){arr_5();sab_f=sab_f+newPosition;arr_3();w=1;sab_f_func();audio();}
  if(w==1){w=0;EEPROM.update(20,sab_f);
  u8g.firstPage();  
   do {
  u8g.setFont(u8g_font_profont12r);u8g.drawStr(0,8,"SUBWOOFER CENTER FREQ");
   switch(sab_f){
    case 0: u8g.drawStr(40, 22," FLAT ");break;
    case 1: u8g.drawStr(40, 22," 80 Hz");break;
    case 2: u8g.drawStr(40, 22,"120 Hz");break;
    case 3: u8g.drawStr(40, 22,"160 Hz");break;}
    } while( u8g.nextPage() );
  }}    

  
if(millis()-times1>TIME_SPEC*1000&&mute==1&&(menu<5||menu>50)){menu=100;spec_func();
  if(newPosition != oldPosition){arr_5();myEnc.write(0);times1=millis();menu=0;w=1;}
  if(ir.value!=0){cl();times1=millis();menu=0;w=1;}
  }
  
if(millis()-times>3000 && w1==1 && menu<5){
     EEPROM.update(0,vol_reg+79);EEPROM.update(1,treb_reg+15);EEPROM.update(2,mid_reg+15);EEPROM.update(3,bass_reg+15);
     EEPROM.update(4,in_reg);EEPROM.update(5,gain1);EEPROM.update(6,gain2);EEPROM.update(7,gain3);
      
     menu=0;w1=0;w=1;myEnc.write(0);}

} // end loop

void arr_7(){switch(in_reg){
    case 1: gain0=gain1;break;
    case 2: gain0=gain2;break;
    case 3: gain0=gain3;break;
    }}
void arr_6(){u8g.drawLine(0, 32, 128, 32);}
void arr_5(){oldPosition = newPosition;}
void arr_4(){gr1=1;gr2=0;}
void arr_3(){myEnc.write(0);newPosition=0;}
void arr_2(){arr_5();if(newPosition>1){newPosition=1;}if(newPosition<-1){newPosition=-1;}}
void arr_1(){times=millis();times1=millis();w=1;w1=1;}
void cl(){ir.value=0;delay(300);}
void sab_f_func(){if(sab_f>3){sab_f=0;}if(sab_f<0){sab_f=3;}}
void bass_q_func(){if(bass_q>3){bass_q=0;}if(bass_q<0){bass_q=3;}}
void bass_f_func(){if(bass_f>3){bass_f=0;}if(bass_f<0){bass_f=3;}}
void mid_q_func(){if(mid_q>3){mid_q=0;}if(mid_q<0){mid_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 att_func(){if(out_att>15){out_att=15;}if(out_att<0){out_att=0;}}
void lon_func(){if(lon<0){lon=0;}if(lon>15){lon=15;}}
void gain_func(){if(gain0>15){gain0=15;}if(gain0<0){gain0=0;}}
void bass_func(){if(bass_reg<-15){bass_reg=-15;}if(bass_reg>15){bass_reg=15;}}
void mid_func(){if(mid_reg<-15){mid_reg=-15;}if(mid_reg>15){mid_reg=15;}}  
void treb_func(){if(treb_reg<-15){treb_reg=-15;}if(treb_reg>15){treb_reg=15;}}  
void vol_func(){if(vol_reg<-79){vol_reg=-79;}if(vol_reg>15){vol_reg=15;}}
void to_Timer(){newPosition = myEnc.read()/4;} 
void audio(){
  tda.setInput(in_reg,gain0,0);    //вх1=1, вх2=2, вх3=3
  tda.setInput2(0,0,0);   // не используется
  tda.setAtt_loudness(lon,lon_f,0,0);
  tda.setSoft(mute,0,0,0,0);//mute  = 1 off 
  tda.setVolume(vol_reg,0);   // общая громкость int = -79...+15
  tda.setAtt_LF(64+fl,0);   // гром. лк фронт
  tda.setAtt_RF(64+fr,0);   // гром. пк фронт
  tda.setAtt_LT(64+rl,0);   // гром. лк тыл
  tda.setAtt_RT(64+rr,0);   // гром. пк тыл
  tda.setAtt_SUB(64+sab,0);  // гром. савбуфер
  tda.setAtt_Mix(79,0);   // не использует
  tda.setFilter_Treble(treb_reg,treb_f,0); 
  tda.setFilter_Middle(mid_reg,mid_q,0);
  tda.setFilter_Bass(bass_reg,bass_q,0);
  tda.setSub_M_B(sab_f,mid_f,bass_f,0,0);
  tda.setMix_Gain_Eff(1,0,0,0,0); // не используется
  tda.setSpektor(2,0,1,0,1,0,0);
}

void spec_func(){
  //// spectrum analyzer //////////////////////////////////////
  digitalWrite(A1,LOW);digitalWrite(A1,HIGH);delay(SPED_SPEC);
  for(int i=0;i<7;i++){
  digitalWrite(A1,LOW);digitalWrite(A1,HIGH);
  spektor[i]=analogRead(A0)*GAIN_SPEC;
  if(spektor[i]<SIG_0_SPEC){spektor[i]=0;}}
  u8g.firstPage(); do {
  for (int pos = 0; pos < 7; pos++) {
  for (int v_pos=0; v_pos<spektor[pos]+4;v_pos+=4){u8g.drawBox(pos*19, 61-v_pos, 13, 2);}}
  } while( u8g.nextPage() );
  }
 

Re: TDA7419 + OLED1.3 + ENCODER + IR + Spectrum Analyzer (LGT8F328)

Спасибо ! Все четко работает!А еще вопрос.А можно допустим  IN 1 или IN3 переименовать BT ON . и сделать  какой нить пин , чтобы включал блютуз и при переходе на другие входа соответственно отключал ? Много делов для правки скетча ?

19

Re: TDA7419 + OLED1.3 + ENCODER + IR + Spectrum Analyzer (LGT8F328)

Serial port отключен из-за нехватки памяти, коды кнопок отображаться не будут

// TDA7419 + OLED1.3 + ENCODER + IR + Spectrum Analyzer
// rcl-radio.ru
// liman324@yandex.ru
// Alexander Liman

#define IR2       0x33B820DF // button encoder
#define MUTE_IR   0x33B8946B // mute
#define IR4       0x33B810EF // >>>
#define IR5       0x33B8E01F // <<<
#define INPUT_IR  0x33B88877 // IN
#define POWER_IR  0x33B800FF // POWER

#define GAIN_SPEC    2.0
#define SIG_0_SPEC   7
#define SPED_SPEC    25
#define TIME_SPEC    15

#define ENC_DT       9
#define ENC_CLK      8
#define ENC_SW       10
#define IR           12
#define IN           2
#define POWER        3
#define SET          5
#define MUTE         6

#define POWER_OUT_PIN 13
#define PBT_OUT_PIN   A3


#include <Wire.h> 
#include <U8glib.h>            // https://github.com/olikraus/u8glib/
#include <MsTimer2.h>          // http://rcl-radio.ru/wp-content/uploads/2018/11/MsTimer2.zip 
#include <TDA7419.h>           // https://github.com/liman324/TDA7419.git
#include <Encoder.h>           // http://rcl-radio.ru/wp-content/uploads/2019/05/Encoder.zip 
#include <EEPROM.h>
#include <boarddefs.h>         // входит в состав библиотеки IRremote
#include <IRremote.h>          // http://rcl-radio.ru/wp-content/uploads/2019/06/IRremote.zip
 
TDA7419 tda;
Encoder myEnc(ENC_DT, ENC_CLK);
U8GLIB_SH1106_128X64 u8g(U8G_I2C_OPT_DEV_0|U8G_I2C_OPT_FAST);
IRrecv irrecv(IR); 
decode_results ir; 

long times,oldPosition  = -999,newPosition, times1;
byte spektor[7];
int menu,vol_reg,in_reg,treb_reg,mid_reg,bass_reg,treb_f,gain0,gain1,gain2,gain3;
int lon,lon_f;
bool w=1,w1,gr1,gr2,www,set,mute=1,power;
byte ur[7],urr[7];
int fr,fl,rr,rl,sab,out_att,out,mid_f,mid_q,sab_f,bass_f,bass_q;

void setup(){
  Wire.begin();
  analogReadResolution(8);
  analogReference(INTERNAL1V024);
  irrecv.enableIRIn();
  pinMode(A0,INPUT);          // SAOUT TDA7419
  pinMode(A1,OUTPUT);         // SAIN  TDA7419
  pinMode(IN,INPUT_PULLUP);  //  IN1  TDA7419
  pinMode(POWER,INPUT_PULLUP);  //  POWER
  pinMode(SET,INPUT_PULLUP);  //  SET  TDA7419
  pinMode(MUTE,INPUT_PULLUP); // MUTE  TDA7419
  pinMode(A3,OUTPUT);         // BT OUT
  MsTimer2::set(1, to_Timer);MsTimer2::start();
  vol_reg = EEPROM.read(0)-79;treb_reg = EEPROM.read(1)-15;mid_reg = EEPROM.read(2)-15;bass_reg = EEPROM.read(3)-15;
  in_reg = EEPROM.read(4);gain1 = EEPROM.read(5);gain2 = EEPROM.read(6);gain3 = EEPROM.read(7);
  lon = EEPROM.read(8);lon_f = EEPROM.read(9);
  fr = EEPROM.read(10);fl = EEPROM.read(11);rl = EEPROM.read(12);rr = EEPROM.read(13);sab = EEPROM.read(14);
  treb_f = EEPROM.read(15);mid_f = EEPROM.read(16);mid_q = EEPROM.read(17);
  bass_f = EEPROM.read(18);bass_q = EEPROM.read(19);sab_f = EEPROM.read(20);
  arr_7();
  delay(500);audio();
  }

void loop(){
/// IR ////////////////////////////////////////
 if ( irrecv.decode( &ir )) {Serial.print("0x");irrecv.resume();}// IR приемник - чтение, в мониторе порта отображаются коды кнопок
 if(ir.value==0){gr1=0;gr2=0;}// запрет нажатий не активных кнопок пульта  
//////// BUTTON ////////////////////////////////////////////////
///////// POWER ///////////////////
 if((digitalRead(POWER)==LOW||ir.value==POWER_IR)&&power==0){power=1;menu=100;cl();mute=0;audio();
  u8g.firstPage();do {u8g.setFont(u8g_font_profont12r);u8g.drawStr(40,30,"POWER OFF");} while( u8g.nextPage() );
  delay(1500); u8g.firstPage();do {} while( u8g.nextPage() );}
  
 if((digitalRead(POWER)==LOW||ir.value==POWER_IR)&&power==1){power=0;menu=0;times1=millis();mute=1;arr_1();
  u8g.firstPage();do {u8g.drawStr(42,30,"POWER ON");} while( u8g.nextPage() );delay(1500);audio();}

if(power==0){digitalWrite(POWER_OUT_PIN,HIGH);}else{digitalWrite(POWER_OUT_PIN,LOW);} 
if(in_reg==1 && power==0){digitalWrite(PBT_OUT_PIN,HIGH);}else{digitalWrite(PBT_OUT_PIN,LOW);} 

if(power==0){
 if(digitalRead(ENC_SW)==LOW&&menu<5||ir.value==IR2){menu++;cl();if(menu>3){menu=0;}arr_1();delay(200);}
 if(digitalRead(IN)==LOW&&menu<5||ir.value==INPUT_IR){menu=4;cl();in_reg++;arr_1();www=1;if(in_reg>3){in_reg=1;};delay(200);}
 if(digitalRead(SET)==LOW&&set==0){menu=5;set=1;times1=millis();w=1;delay(200);}
 if(digitalRead(SET)==LOW&&set==1){menu=0;set=0;;arr_1();www=1;delay(200);}
 if(digitalRead(ENC_SW)==LOW&&menu>4){menu++;if(menu>10){menu=0;}times1=millis();w=1;set=0;delay(200);}
 if((digitalRead(MUTE)==LOW||ir.value==MUTE_IR)&&mute==1){mute=0;menu=100;cl();
 u8g.firstPage();do {u8g.setFont(u8g_font_profont12r);u8g.drawStr(53,30,"MUTE");} while( u8g.nextPage() );audio();delay(200);}
 if((digitalRead(MUTE)==LOW||ir.value==MUTE_IR)&&mute==0){mute=1;menu=0;cl();arr_1();audio();delay(200);}
}
///////////////////////////////////////////////////////////////
  
//////// VOLUME //////////////////////////////////////////////////////////////////////////////////////////////////////////////  
  if(menu==0){
   if(newPosition != oldPosition){arr_2();vol_reg=vol_reg+newPosition;arr_3();arr_1();vol_func();audio();}
 
   if(ir.value==IR4){vol_reg++;arr_4();cl();arr_1();vol_func();audio();}// кнопка > 
   if(ir.value==0xFFFFFFFF and gr1==1){vol_reg++;gr2=0;cl();arr_1();vol_func();audio();}// кнопка >>>>>>
   if(ir.value==IR5){vol_reg--;gr1=0;gr2=1;cl();arr_1();vol_func();audio();}// кнопка <
   if(ir.value==0xFFFFFFFF and gr2==1){vol_reg--;gr1=0;cl();arr_1();vol_func();audio();}// кнопка <<<<<<
 
  if(w==1){w=0;
  u8g.firstPage();  
   do {
  u8g.setFont(u8g_font_profont12r);u8g.drawStr(0,8,"VOLUME");u8g.drawStr(0,18,"IN");
  u8g.setPrintPos(20, 18);if(in_reg==1){u8g.drawStr(20,18,"BT ON");}u8g.print(in_reg);u8g.drawStr(0,28,"GAIN");u8g.setPrintPos(30, 28);u8g.print(gain0);
  arr_6();
  u8g.drawStr(0,44,"TREBLE");u8g.setPrintPos(80, 44);u8g.print(treb_reg);u8g.drawStr(95,44,"dB");
  u8g.drawStr(0,54,"MIDDLE");u8g.setPrintPos(80, 54);u8g.print(mid_reg);u8g.drawStr(95,54,"dB");
  u8g.drawStr(0,64,"BASS");u8g.setPrintPos(80, 64);u8g.print(bass_reg);u8g.drawStr(95,64,"dB");
  u8g.setFont(u8g_font_profont29r); u8g.setPrintPos(78, 22);u8g.print(vol_reg+79);
   } while( u8g.nextPage() );
  }}
/////////////////////////////////////////////////////////////////

//////// TREBLE //////////////////////////////////////////////////////////////////////////////////////////////////////////////  
  if(menu==1){
   if(newPosition != oldPosition){arr_2();treb_reg=treb_reg+newPosition;arr_3();arr_1();treb_func();audio();}

   if(ir.value==IR4){treb_reg++;arr_4();cl();arr_1();treb_func();audio();}// кнопка > 
   if(ir.value==0xFFFFFFFF and gr1==1){treb_reg++;gr2=0;cl();arr_1();treb_func();audio();}// кнопка >>>>>>
   if(ir.value==IR5){treb_reg--;gr1=0;gr2=1;cl();arr_1();treb_func();audio();}// кнопка <
   if(ir.value==0xFFFFFFFF and gr2==1){treb_reg--;gr1=0;cl();arr_1();treb_func();audio();}// кнопка <<<<<<
   
  if(w==1){w=0;
  u8g.firstPage();  
   do {
  u8g.setFont(u8g_font_profont29r); u8g.setPrintPos(78, 22);u8g.print(treb_reg);
  arr_6();
  u8g.setFont(u8g_font_profont12r);u8g.drawStr(0,8,"TREBLE");u8g.drawStr(0,44,"MIDDLE");u8g.setPrintPos(80, 44);u8g.print(mid_reg);u8g.drawStr(95,44,"dB");
  u8g.drawStr(0,54,"BASS");u8g.setPrintPos(80, 54);u8g.print(bass_reg);u8g.drawStr(95,54,"dB");
  u8g.drawStr(0,64,"VOLUME");u8g.setPrintPos(80, 64);u8g.print(vol_reg+79);u8g.drawStr(95,64,"dB");
   } while( u8g.nextPage() );
  }}
/////////////////////////////////////////////////////////////////

//////// MIDDLE //////////////////////////////////////////////////////////////////////////////////////////////////////////////  
  if(menu==2){
   if(newPosition != oldPosition){arr_2();mid_reg=mid_reg+newPosition;arr_3();arr_1();mid_func();audio();}

   if(ir.value==IR4){mid_reg++;arr_4();cl();arr_1();mid_func();audio();}// кнопка > 
   if(ir.value==0xFFFFFFFF and gr1==1){mid_reg++;gr2=0;cl();arr_1();mid_func();audio();}// кнопка >>>>>>
   if(ir.value==IR5){mid_reg--;gr1=0;gr2=1;cl();arr_1();mid_func();audio();}// кнопка <
   if(ir.value==0xFFFFFFFF and gr2==1){mid_reg--;gr1=0;cl();arr_1();mid_func();audio();}// кнопка <<<<<<
 
  if(w==1){w=0;
  u8g.firstPage();  
   do {
  u8g.setFont(u8g_font_profont29r); u8g.setPrintPos(78, 22);u8g.print(mid_reg);
  arr_6();
  u8g.setFont(u8g_font_profont12r);u8g.drawStr(0,8,"MIDDLE");u8g.drawStr(0,44,"BASS");u8g.setPrintPos(80, 44);u8g.print(bass_reg);u8g.drawStr(95,44,"dB");
  u8g.drawStr(0,54,"VOLUME");u8g.setPrintPos(80, 54);u8g.print(vol_reg+79);u8g.drawStr(95,54,"dB");
  u8g.drawStr(0,64,"TREBLE");u8g.setPrintPos(80, 64);u8g.print(treb_reg);u8g.drawStr(95,64,"dB");
   } while( u8g.nextPage() );
  }}
/////////////////////////////////////////////////////////////////

//////// BASS //////////////////////////////////////////////////////////////////////////////////////////////////////////////  
  if(menu==3){
   if(newPosition != oldPosition){arr_2();bass_reg=bass_reg+newPosition;arr_3();arr_1();bass_func();audio();}

   if(ir.value==IR4){bass_reg++;arr_4();cl();arr_1();bass_func();audio();}// кнопка > 
   if(ir.value==0xFFFFFFFF and gr1==1){bass_reg++;gr2=0;cl();arr_1();bass_func();audio();}// кнопка >>>>>>
   if(ir.value==IR5){bass_reg--;gr1=0;gr2=1;cl();arr_1();bass_func();audio();}// кнопка <
   if(ir.value==0xFFFFFFFF and gr2==1){bass_reg--;gr1=0;cl();arr_1();bass_func();audio();}// кнопка <<<<<<
 
  if(w==1){w=0;
  u8g.firstPage();  
   do {
  u8g.setFont(u8g_font_profont29r); u8g.setPrintPos(78, 22);u8g.print(bass_reg);
  arr_6();
  u8g.setFont(u8g_font_profont12r);u8g.drawStr(0,8,"BASS");u8g.drawStr(0,44,"VOLUME");u8g.setPrintPos(80, 44);u8g.print(vol_reg+79);u8g.drawStr(95,44,"dB");
  u8g.drawStr(0,54,"TREBLE");u8g.setPrintPos(80, 54);u8g.print(mid_reg);u8g.drawStr(95,54,"dB");
  u8g.drawStr(0,64,"MIDDLE");u8g.setPrintPos(80, 64);u8g.print(treb_reg);u8g.drawStr(95,64,"dB");
   } while( u8g.nextPage() );
  }}
/////////////////////////////////////////////////////////////////

////////////// INPUT GAIN ///////////////////////////////////////////////////////////////////
 if(menu==4){
  arr_7();
  if (newPosition != oldPosition){arr_5();gain0=gain0+newPosition;arr_3();arr_1();www=1;gain_func();}
  switch(in_reg){
    case 1: gain1=gain0;break;
    case 2: gain2=gain0;break;
    case 3: gain3=gain0;break;
    } 
  if(www==1){audio();www=0;}
  if(w==1){w=0;
  u8g.firstPage();  
   do {
  u8g.setFont(u8g_font_profont29r);u8g.setPrintPos(78, 60);u8g.print(gain0);
  u8g.setPrintPos(78, 22);if(in_reg==1){u8g.drawStr(40,22,"BT ON");}else{u8g.print(in_reg);}  
  arr_6();
  u8g.setFont(u8g_font_profont12r);u8g.drawStr(0,8,"INPUT");u8g.drawStr(0,44,"GAIN");
    } while( u8g.nextPage() );  
  }}

/////////// loudness att/freq /////////////////////
if(menu==5){
  if (newPosition != oldPosition){arr_5();lon=lon-newPosition;arr_3();w=1;lon_func();audio();}
  if(digitalRead(IN)==LOW){lon_f++;if(lon_f>3){lon_f=0;}w=1;;audio();delay(200);}
  if(w==1){w=0;EEPROM.update(8,lon);EEPROM.update(9,lon_f);
  u8g.firstPage();  
   do {
  u8g.setFont(u8g_font_profont12r);u8g.drawStr(0,8,"LOUDNESS ATTENUATION");u8g.setPrintPos(50, 22);u8g.print(-lon);u8g.drawStr(80,22,"dB");
  arr_6();
  u8g.drawStr(0,44,"LOUDNESS FREQUENCY"); 
   switch(lon_f){
    case 0: u8g.drawStr(50, 60," FLAT");break;
    case 1: u8g.drawStr(50, 60," 400Hz");break;
    case 2: u8g.drawStr(50, 60," 800Hz");break;
    case 3: u8g.drawStr(50, 60,"2400Hz");break;} 
    } while( u8g.nextPage() );
  }}  

///////////// out att ///////////////////////////////
if(menu==6){
  if(digitalRead(IN)==LOW){out++;if(out>4){out=0;}w=1;delay(200);}
  switch(out){
    case 0: out_att=fr;break;
    case 1: out_att=fl;break;
    case 2: out_att=rl;break;
    case 3: out_att=rr;break;
    case 4: out_att=sab;break;
    }
  if (newPosition != oldPosition){arr_5();out_att=out_att+newPosition;arr_3();w=1;att_func();www=1;}
  switch(out){
    case 0: fr=out_att;break;
    case 1: fl=out_att;break;
    case 2: rl=out_att;break;
    case 3: rr=out_att;break;
    case 4: sab=out_att;break;
    }
  if(www==1){audio();www=0; EEPROM.update(10,fr);EEPROM.update(11,fl);EEPROM.update(12,rl);EEPROM.update(13,rr);EEPROM.update(14,sab);}
  if(w==1){w=0;
  u8g.firstPage();  
   do {
  u8g.setFont(u8g_font_profont12r);u8g.drawStr(0,8,"OUTPUT"); 
  switch(out){
    case 0: u8g.drawStr(45,8,"FR");break;
    case 1: u8g.drawStr(45,8,"FL");break;
    case 2: u8g.drawStr(45,8,"RL");break;
    case 3: u8g.drawStr(45,8,"RR");break;
    case 4: u8g.drawStr(45,8,"SAB");break;
    }
  u8g.setPrintPos(50, 22);u8g.print(out_att);u8g.drawStr(80,22,"dB");
    } while( u8g.nextPage() );
  }} 
///////////////////////////////////////////////////////////////////
  
/////////// treb f /////////////////////
if(menu==7){
  if (newPosition != oldPosition){arr_5();treb_f=treb_f+newPosition;arr_3();w=1;treb_f_func();audio();}
  if(w==1){w=0;EEPROM.update(15,treb_f);
  u8g.firstPage();  
   do {
  u8g.setFont(u8g_font_profont12r);u8g.drawStr(0,8,"TREBLE CENTER FREQ");
   switch(treb_f){
    case 0: u8g.drawStr(40, 22,"10.0 kHz");break;
    case 1: u8g.drawStr(40, 22,"12.5 kHz");break;
    case 2: u8g.drawStr(40, 22,"15.0 kHz");break;
    case 3: u8g.drawStr(40, 22,"17.5 kHz");break;} 
    } while( u8g.nextPage() );
  }} 

/////////// middle f/q /////////////////////
if(menu==8){
  if (newPosition != oldPosition){arr_5();mid_f=mid_f+newPosition;arr_3();w=1;mid_f_func();audio();}
  if(digitalRead(IN)==LOW){mid_q++;mid_q_func();w=1;audio();delay(200);}
  if(w==1){w=0;EEPROM.update(16,mid_f);EEPROM.update(17,mid_q);
  u8g.firstPage();  
   do {
  u8g.setFont(u8g_font_profont12r);u8g.drawStr(0,8,"MIDDLE CENTER FREQ");
   switch(mid_f){
    case 0: u8g.drawStr(40, 22,"0.5 kHz");break;
    case 1: u8g.drawStr(40, 22,"1.0 kHz");break;
    case 2: u8g.drawStr(40, 22,"1.5 kHz");break;
    case 3: u8g.drawStr(40, 22,"2.5 kHz");break;}
  arr_6();
  u8g.drawStr(0,44,"MIDDLE Q FACTOR"); 
   switch(mid_q){
    case 0: u8g.drawStr(50, 60,"0.50");break;
    case 1: u8g.drawStr(50, 60,"0.75");break;
    case 2: u8g.drawStr(50, 60,"1.00");break;
    case 3: u8g.drawStr(50, 60,"1.25");break;} 
    } while( u8g.nextPage() );
  }}   

/////////// bass f/q /////////////////////
if(menu==9){
  if (newPosition != oldPosition){arr_5();bass_f=bass_f+newPosition;arr_3();w=1;bass_f_func();audio();}
  if(digitalRead(IN)==LOW){bass_q++;bass_q_func();w=1;audio();delay(200);}
  if(w==1){w=0;EEPROM.update(18,bass_f);EEPROM.update(19,bass_q);
  u8g.firstPage();  
   do {
  u8g.setFont(u8g_font_profont12r);u8g.drawStr(0,8,"BASS CENTER FREQ");
   switch(bass_f){
    case 0: u8g.drawStr(40, 22," 60 Hz");break;
    case 1: u8g.drawStr(40, 22," 80 Hz");break;
    case 2: u8g.drawStr(40, 22,"100 Hz");break;
    case 3: u8g.drawStr(40, 22,"200 Hz");break;}
  arr_6();
  u8g.drawStr(0,44,"BASS Q FACTOR"); 
   switch(bass_q){
    case 0: u8g.drawStr(50, 60,"1.00");break;
    case 1: u8g.drawStr(50, 60,"1.25");break;
    case 2: u8g.drawStr(50, 60,"1.50");break;
    case 3: u8g.drawStr(50, 60,"2.00");break;} 
    } while( u8g.nextPage() );
  }}   

/////////// sab f /////////////////////
if(menu==10){
  if (newPosition != oldPosition){arr_5();sab_f=sab_f+newPosition;arr_3();w=1;sab_f_func();audio();}
  if(w==1){w=0;EEPROM.update(20,sab_f);
  u8g.firstPage();  
   do {
  u8g.setFont(u8g_font_profont12r);u8g.drawStr(0,8,"SUBWOOFER CENTER FREQ");
   switch(sab_f){
    case 0: u8g.drawStr(40, 22," FLAT ");break;
    case 1: u8g.drawStr(40, 22," 80 Hz");break;
    case 2: u8g.drawStr(40, 22,"120 Hz");break;
    case 3: u8g.drawStr(40, 22,"160 Hz");break;}
    } while( u8g.nextPage() );
  }}    

  
if(millis()-times1>TIME_SPEC*1000&&mute==1&&(menu<5||menu>50)){menu=100;spec_func();
  if(newPosition != oldPosition){arr_5();myEnc.write(0);times1=millis();menu=0;w=1;}
  if(ir.value!=0){cl();times1=millis();menu=0;w=1;}
  }
  
if(millis()-times>3000 && w1==1 && menu<5){
     EEPROM.update(0,vol_reg+79);EEPROM.update(1,treb_reg+15);EEPROM.update(2,mid_reg+15);EEPROM.update(3,bass_reg+15);
     EEPROM.update(4,in_reg);EEPROM.update(5,gain1);EEPROM.update(6,gain2);EEPROM.update(7,gain3);
      
     menu=0;w1=0;w=1;myEnc.write(0);}

} // end loop

void arr_7(){switch(in_reg){
    case 1: gain0=gain1;break;
    case 2: gain0=gain2;break;
    case 3: gain0=gain3;break;
    }}
void arr_6(){u8g.drawLine(0, 32, 128, 32);}
void arr_5(){oldPosition = newPosition;}
void arr_4(){gr1=1;gr2=0;}
void arr_3(){myEnc.write(0);newPosition=0;}
void arr_2(){arr_5();if(newPosition>1){newPosition=1;}if(newPosition<-1){newPosition=-1;}}
void arr_1(){times=millis();times1=millis();w=1;w1=1;}
void cl(){ir.value=0;delay(300);}
void sab_f_func(){if(sab_f>3){sab_f=0;}if(sab_f<0){sab_f=3;}}
void bass_q_func(){if(bass_q>3){bass_q=0;}if(bass_q<0){bass_q=3;}}
void bass_f_func(){if(bass_f>3){bass_f=0;}if(bass_f<0){bass_f=3;}}
void mid_q_func(){if(mid_q>3){mid_q=0;}if(mid_q<0){mid_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 att_func(){if(out_att>15){out_att=15;}if(out_att<0){out_att=0;}}
void lon_func(){if(lon<0){lon=0;}if(lon>15){lon=15;}}
void gain_func(){if(gain0>15){gain0=15;}if(gain0<0){gain0=0;}}
void bass_func(){if(bass_reg<-15){bass_reg=-15;}if(bass_reg>15){bass_reg=15;}}
void mid_func(){if(mid_reg<-15){mid_reg=-15;}if(mid_reg>15){mid_reg=15;}}  
void treb_func(){if(treb_reg<-15){treb_reg=-15;}if(treb_reg>15){treb_reg=15;}}  
void vol_func(){if(vol_reg<-79){vol_reg=-79;}if(vol_reg>15){vol_reg=15;}}
void to_Timer(){newPosition = myEnc.read()/4;} 
void audio(){
  tda.setInput(in_reg,gain0,0);    //вх1=1, вх2=2, вх3=3
  tda.setInput2(0,0,0);   // не используется
  tda.setAtt_loudness(lon,lon_f,0,0);
  tda.setSoft(mute,0,0,0,0);//mute  = 1 off 
  tda.setVolume(vol_reg,0);   // общая громкость int = -79...+15
  tda.setAtt_LF(64+fl,0);   // гром. лк фронт
  tda.setAtt_RF(64+fr,0);   // гром. пк фронт
  tda.setAtt_LT(64+rl,0);   // гром. лк тыл
  tda.setAtt_RT(64+rr,0);   // гром. пк тыл
  tda.setAtt_SUB(64+sab,0);  // гром. савбуфер
  tda.setAtt_Mix(79,0);   // не использует
  tda.setFilter_Treble(treb_reg,treb_f,0); 
  tda.setFilter_Middle(mid_reg,mid_q,0);
  tda.setFilter_Bass(bass_reg,bass_q,0);
  tda.setSub_M_B(sab_f,mid_f,bass_f,0,0);
  tda.setMix_Gain_Eff(1,0,0,0,0); // не используется
  tda.setSpektor(2,0,1,0,1,0,0);
}

void spec_func(){
  //// spectrum analyzer //////////////////////////////////////
  digitalWrite(A1,LOW);digitalWrite(A1,HIGH);delay(SPED_SPEC);
  for(int i=0;i<7;i++){
  digitalWrite(A1,LOW);digitalWrite(A1,HIGH);
  spektor[i]=analogRead(A0)*GAIN_SPEC;
  if(spektor[i]<SIG_0_SPEC){spektor[i]=0;}}
  u8g.firstPage(); do {
  for (int pos = 0; pos < 7; pos++) {
  for (int v_pos=0; v_pos<spektor[pos]+4;v_pos+=4){u8g.drawBox(pos*19, 61-v_pos, 13, 2);}}
  } while( u8g.nextPage() );
  }
 

Re: TDA7419 + OLED1.3 + ENCODER + IR + Spectrum Analyzer (LGT8F328)

Спасибо все четко ! Вы как всегда на высоте ! Все работает как надо!

21

Re: TDA7419 + OLED1.3 + ENCODER + IR + Spectrum Analyzer (LGT8F328)

Всех с новым годом... Извините, сэр, как мне отключить последовательный порт?

22

Re: TDA7419 + OLED1.3 + ENCODER + IR + Spectrum Analyzer (LGT8F328)

Я загрузил скетч, но все равно не получается, так как память переполнена. Как мне загрузить скетч? пожалуйста, помогите мне, сэр

23

Re: TDA7419 + OLED1.3 + ENCODER + IR + Spectrum Analyzer (LGT8F328)

Я загружал в Arduino IDE версии 1.8.15

24

Re: TDA7419 + OLED1.3 + ENCODER + IR + Spectrum Analyzer (LGT8F328)

Все еще не могу загрузить, сэр. Хотя я использую Arduino Ide версии 1.8.15. в описании переменная память заполнена или превышает емкость

25

Re: TDA7419 + OLED1.3 + ENCODER + IR + Spectrum Analyzer (LGT8F328)

http://forum.rcl-radio.ru/uploads/images/2024/02/78b935995de0abfb1fb6e2b38ecf725a.png