1

Тема: STA333BW

Доработка №1

Вывод в меню громкости состояние фильтра de-emphasis control

http://forum.rcl-radio.ru/uploads/images/2023/02/691ffc765de4940d41f242def26689a2.png


#define I2C_STA333 0x1C // Address chip | PIN_SA = GND 

#define IR_1 0x2FDD02F // Кнопка menu up
#define IR_2 0x2FD32CD // Кнопка menu dw
#define IR_3 0x2FD906F // Кнопка >
#define IR_4 0x2FDF20D // Кнопка <
#define IR_5 0x2FDF00F // Кнопка MUTE
#define IR_6 0x2FD00FF // Кнопка STANDBY (POWER)
#define IR_7 0x2FD6A95 // DEMP

#include <Wire.h>
#include <OLED_I2C.h>           // http://rcl-radio.ru/wp-content/uploads/2022/01/OLED_I2C.zip
#include <Encoder.h>            // http://rcl-radio.ru/wp-content/uploads/2019/05/Encoder.zip    
#include <EEPROM.h>
#include <MsTimer2.h>           // http://rcl-radio.ru/wp-content/uploads/2018/11/MsTimer2.zip       
#include <boarddefs.h>          // входит в состав библиотеки IRremote
#include <IRremote.h>           // http://rcl-radio.ru/wp-content/uploads/2019/06/IRremote.zip

 OLED  myOLED(SDA, SCL, 8);
 IRrecv irrecv(12); // указываем вывод модуля IR приемника
 Encoder myEnc(9, 8);// DT, CLK
 decode_results ir; 
 
 int bass_q=3,bass,treb,vol,menu,ball;
 extern uint8_t SmallFont[],BigNumbers[];
 unsigned long times,oldPosition  = -999,newPosition;
 bool www,w,w2,gr1,gr2,mute,power,demp;


void setup() {
  Wire.begin();Serial.begin(9600);irrecv.enableIRIn();
  myOLED.begin();
  myOLED.setBrightness(100);
  pinMode(4,OUTPUT);               // RESET
  pinMode(5,OUTPUT);               // PWRDN
  digitalWrite(4,LOW);delay(10);   // RESET 
  digitalWrite(4,HIGH);delay(10);  // RESET 
  digitalWrite(5,HIGH);delay(10);  // PWRDN
  pinMode(10,INPUT);               // КНОПКА SW энкодера
  pinMode(A0,INPUT_PULLUP);        // КНОПКА MUTE
  pinMode(A1,INPUT_PULLUP);        // КНОПКА POWER
  pinMode(13,OUTPUT);              // ВЫХОД УПРАВЛЕНИЯ STANDBY
  MsTimer2::set(3, to_Timer);MsTimer2::start();
  if(EEPROM.read(100)!=0){for(int i=0;i<101;i++){EEPROM.update(i,0);}}// очистка памяти при первом включении  
  wireWrite(I2C_STA333,0x05,0b01011100);delay(10);
  myOLED.clrScr();
  myOLED.setFont(SmallFont);
  myOLED.print(F("Digital audio system"), CENTER, 10);
  myOLED.print(F("STA333BW"), CENTER, 30);
  myOLED.print(F("2.0 channel 40W"), CENTER, 50);
  myOLED.update();
  delay(2000);
  vol = EEPROM.read(0);treb = EEPROM.read(1);bass = EEPROM.read(2);
  bass_q = EEPROM.read(3)-100;ball = EEPROM.read(4)-100;demp = EEPROM.read(5);
  init_sta();
  Serial.println(wireRead(I2C_STA333,0x2D),BIN); 
}

void loop() {
/// IR ////////////////////////////////////////
  if ( irrecv.decode( &ir )) {Serial.print("0x");Serial.println( ir.value,HEX);irrecv.resume();times=millis();w=1;w2=1;}// IR приемник - чтение, в мониторе порта отображаются коды кнопок
  if(ir.value==0){gr1=0;gr2=0;}// запрет нажатий не активных кнопок пульта  

/////// BUTTON ////////////////////////////////////////////////////////////////////////////////////////////////////////
if(power==0){
/// menu
   if(digitalRead(10)==LOW||ir.value==IR_1){menu++;gr1=0;gr2=0;cl();delay(200);times=millis();w=1;w2=1;if(menu>4){menu=0;}}
   if(ir.value==IR_2){menu--;gr1=0;gr2=0;cl();delay(200);times=millis();w=1;w2=1;if(menu<0){menu=4;}}
/// mute
   if((digitalRead(A0)==LOW||ir.value==IR_5)&&mute==0){mute=1;w=1;menu=100;cl();wireWrite(I2C_STA333,0x06,0b00010110);
       myOLED.clrScr();myOLED.setFont(SmallFont);myOLED.print(F("MUTE"), CENTER, 25);myOLED.update();}
   if((digitalRead(A0)==LOW||ir.value==IR_5)&&mute==1){mute=0;w=1;menu=0;cl();wireWrite(I2C_STA333,0x06,0b00010000);} 
//// DEMP
   if(ir.value==IR_7&&demp==0){demp=1;w=1;cl();wireWrite(I2C_STA333,0x03,0b01000000|demp<<1);
       myOLED.clrScr();myOLED.setFont(SmallFont);myOLED.print(F("De-emphasis ON"), CENTER, 25);myOLED.update();delay(2000);menu=0;}
   if(ir.value==IR_7&&demp==1){demp=0;w=1;cl();wireWrite(I2C_STA333,0x03,0b01000000|demp<<1);
       myOLED.clrScr();myOLED.setFont(SmallFont);myOLED.print(F("De-emphasis OFF"), CENTER, 25);myOLED.update();delay(2000);menu=0;}       
   
   
}
 /// POWER ////////////////////////////////////
   if((digitalRead(A1)==LOW||ir.value==IR_6)&&power==0){power=1;menu=100;myOLED.setBrightness(1);cl();myEnc.write(0);
    myOLED.clrScr();myOLED.setFont(SmallFont);myOLED.print(F("POWER OFF"), CENTER, 10);myOLED.update();
    wireWrite(I2C_STA333,0x05,0b01011100);delay(2000);cl();}
    
   if((digitalRead(A1)==LOW||ir.value==IR_6)&&power==1&&digitalRead(10)==HIGH){power=0;menu=0;myOLED.setBrightness(100);cl();myEnc.write(0);w=1;
    myOLED.clrScr();myOLED.setFont(SmallFont);myOLED.print(F("POWER ON"), CENTER, 10);myOLED.update();
    wireWrite(I2C_STA333,0x05,0b11011100);delay(2000);cl();}  
    /// standby output 
   if(power==1){digitalWrite(13,LOW);}else{digitalWrite(13,HIGH);}  
 
     
//////// VOLUME //////////////////////////////////////////////////////////////////////////////////////////////////////////////  
  if(menu==0){
   if(newPosition != oldPosition){oldPosition = newPosition;vol=vol-newPosition;myEnc.write(0);newPosition=0;times=millis();w=1;w2=1;vol_func();www=1;}
 
   if(ir.value==IR_4){vol++;gr1=1;gr2=0;cl_vol();times=millis();w=1;w2=1;vol_func();www=1;}// кнопка > 
   if(ir.value==0xFFFFFFFF and gr1==1){vol++;gr2=0;cl_vol();times=millis();w=1;w2=1;vol_func();www=1;}// кнопка >>>>>>
   if(ir.value==IR_3){vol--;gr1=0;gr2=1;cl_vol();times=millis();w=1;w2=1;vol_func();www=1;}// кнопка <
   if(ir.value==0xFFFFFFFF and gr2==1){vol--;gr1=0;cl_vol();times=millis();w=1;w2=1;vol_func();www=1;}// кнопка <<<<<<

  if(www==1){www=0;  
    wireWrite(I2C_STA333,0x08,vol+ball*2);
    wireWrite(I2C_STA333,0x09,vol-ball*2);}
  
  if(w==1){w=0;
  myOLED.clrScr();
  myOLED.setFont(SmallFont);myOLED.print(F("VOLUME"), LEFT, 0);myOLED.setFont(BigNumbers);myOLED.printNumI(255-vol, 75, 0);
  myOLED.setFont(SmallFont);if(demp==0){myOLED.print(F("DEMP_OFF"), LEFT, 20);}
                              else{myOLED.print(F("DEMP_ON"), LEFT, 20);}
  myOLED.drawLine(0, 30, 128, 30);
  myOLED.setFont(SmallFont);myOLED.print(F("TREBLE"), LEFT, 35);myOLED.printNumI((treb-7)*2, 75, 35);myOLED.print(F("dB"), RIGHT, 35);
  myOLED.setFont(SmallFont);myOLED.print(F("BASS"), LEFT, 45);myOLED.printNumI((bass-7)*2, 75, 45);myOLED.print(F("dB"), RIGHT, 45);
  myOLED.setFont(SmallFont);myOLED.print(F("F_BASS"), LEFT, 55);bass_q_f(55);
  myOLED.update();
  }}
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////  

//////// TREBLE //////////////////////////////////////////////////////////////////////////////////////////////////////////////  
  if(menu==1){
   if(newPosition != oldPosition){oldPosition = newPosition;treb=treb+newPosition;myEnc.write(0);newPosition=0;times=millis();w=1;w2=1;treb_func();www=1;}
 
   if(ir.value==IR_3){treb++;gr1=1;gr2=0;cl();times=millis();w=1;w2=1;treb_func();www=1;}// кнопка > 
   if(ir.value==0xFFFFFFFF and gr1==1){treb++;gr2=0;cl();times=millis();w=1;w2=1;treb_func();www=1;}// кнопка >>>>>>
   if(ir.value==IR_4){treb--;gr1=0;gr2=1;cl();times=millis();w=1;w2=1;treb_func();www=1;}// кнопка <
   if(ir.value==0xFFFFFFFF and gr2==1){treb--;gr1=0;cl();times=millis();w=1;w2=1;treb_func();www=1;}// кнопка <<<<<<

  if(www==1){www=0;wireWrite(I2C_STA333,0x11,0|bass|treb<<4);}
  
  if(w==1){w=0;
  myOLED.clrScr();
  myOLED.setFont(SmallFont);myOLED.print(F("TREBLE"), LEFT, 0);myOLED.setFont(BigNumbers);myOLED.printNumI((treb-7)*2, 75, 0);
  myOLED.setFont(SmallFont);myOLED.print(F("dB"), RIGHT, 20);
  myOLED.drawLine(0, 30, 128, 30);
  myOLED.setFont(SmallFont);myOLED.print(F("BASS"), LEFT, 35);myOLED.printNumI((bass-7)*2, 75, 35);myOLED.print(F("dB"), RIGHT, 35);
  myOLED.setFont(SmallFont);myOLED.print(F("F_BASS"), LEFT, 45);myOLED.printNumI(bass_q, 75, 45);bass_q_f(45);
  myOLED.setFont(SmallFont);myOLED.print(F("BALANCE"), LEFT, 55);myOLED.printNumI(ball, 75, 55);myOLED.print(F("dB"), RIGHT, 55);
  myOLED.update();
  }}
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////  

//////// BASS //////////////////////////////////////////////////////////////////////////////////////////////////////////////  
  if(menu==2){
   if(newPosition != oldPosition){oldPosition = newPosition;bass=bass+newPosition;myEnc.write(0);newPosition=0;times=millis();w=1;w2=1;bass_func();www=1;}
 
   if(ir.value==IR_3){bass++;gr1=1;gr2=0;cl();times=millis();w=1;w2=1;bass_func();www=1;}// кнопка > 
   if(ir.value==0xFFFFFFFF and gr1==1){bass++;gr2=0;cl();times=millis();w=1;w2=1;bass_func();www=1;}// кнопка >>>>>>
   if(ir.value==IR_4){bass--;gr1=0;gr2=1;cl();times=millis();w=1;w2=1;bass_func();www=1;}// кнопка <
   if(ir.value==0xFFFFFFFF and gr2==1){bass--;gr1=0;cl();times=millis();w=1;w2=1;bass_func();www=1;}// кнопка <<<<<<

  if(www==1){www=0;wireWrite(I2C_STA333,0x11,0|bass|treb<<4);}
  
  if(w==1){w=0;
  myOLED.clrScr();
  myOLED.setFont(SmallFont);myOLED.print(F("BASS"), LEFT, 0);myOLED.setFont(BigNumbers);myOLED.printNumI((bass-7)*2, 75, 0);
  myOLED.setFont(SmallFont);myOLED.print(F("dB"), RIGHT, 20);
  myOLED.drawLine(0, 30, 128, 30);
  myOLED.setFont(SmallFont);myOLED.print(F("F_BASS"), LEFT, 35);myOLED.printNumI(bass_q, 75, 35);bass_q_f(35);
  myOLED.setFont(SmallFont);myOLED.print(F("BALANCE"), LEFT, 45);myOLED.printNumI(ball, 75, 45);myOLED.print(F("dB"), RIGHT, 45);
  myOLED.setFont(SmallFont);myOLED.print(F("VOLUME"), LEFT, 55);myOLED.printNumI(255-vol, 75, 55);
  myOLED.update();
  }}
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////  

//////// BASS_F //////////////////////////////////////////////////////////////////////////////////////////////////////////////  
  if(menu==3){
   if(newPosition != oldPosition){oldPosition = newPosition;bass_q=bass_q+newPosition;myEnc.write(0);newPosition=0;times=millis();w=1;w2=1;bass_q_func();www=1;}
 
   if(ir.value==IR_3){bass_q++;gr1=1;gr2=0;cl();times=millis();w=1;w2=1;bass_q_func();www=1;}// кнопка > 
   if(ir.value==0xFFFFFFFF and gr1==1){bass_q++;gr2=0;cl();times=millis();w=1;w2=1;bass_q_func();www=1;}// кнопка >>>>>>
   if(ir.value==IR_4){bass_q--;gr1=0;gr2=1;cl();times=millis();w=1;w2=1;bass_q_func();www=1;}// кнопка <
   if(ir.value==0xFFFFFFFF and gr2==1){bass_q--;gr1=0;cl();times=millis();w=1;w2=1;bass_q_func();www=1;}// кнопка <<<<<<

  if(www==1){www=0;wireWrite(I2C_STA333,0x0C,0b00001000|bass_q<<4);}
  
  if(w==1){w=0;
  myOLED.clrScr();
  myOLED.setFont(SmallFont);myOLED.print(F("F_BASS"), LEFT, 0);myOLED.setFont(BigNumbers);myOLED.printNumI(60+bass_q*20, 65, 0);
  myOLED.setFont(SmallFont);myOLED.print(F("Hz"), RIGHT, 20);
  myOLED.drawLine(0, 30, 128, 30);
  myOLED.setFont(SmallFont);myOLED.print(F("BALANCE"), LEFT, 35);myOLED.printNumI(ball, 75, 35);myOLED.print(F("dB"), RIGHT, 35);
  myOLED.setFont(SmallFont);myOLED.print(F("VOLUME"), LEFT, 45);myOLED.printNumI(255-vol, 75, 45);
  myOLED.setFont(SmallFont);myOLED.print(F("TREBLE"), LEFT, 55);myOLED.printNumI((treb-7)*2, 75, 55);myOLED.print(F("dB"), RIGHT, 55);
  myOLED.update();
  }}
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////  

//////// BALANCE //////////////////////////////////////////////////////////////////////////////////////////////////////////////  
  if(menu==4){
  if (newPosition != oldPosition){oldPosition = newPosition;ball=ball+newPosition;myEnc.write(0);newPosition=0;times=millis();w=1;w2=1;ball_fun();www=1;}
 
  if(ir.value==IR_3){ball++;gr1=1;gr2=0;cl();times=millis();w=1;w2=1;ball_fun();www=1;}// кнопка > 
  if(ir.value==IR_4){ball--;gr1=0;gr2=1;cl();times=millis();w=1;w2=1;ball_fun();www=1;}// кнопка <

  if(www==1){www=0;  
    wireWrite(I2C_STA333,0x08,vol+ball*2);
    wireWrite(I2C_STA333,0x09,vol-ball*2);}
    
  if(w==1){w=0;
  myOLED.clrScr();
  myOLED.setFont(SmallFont);myOLED.print(F("BALANCE"), LEFT, 0);myOLED.setFont(BigNumbers);myOLED.printNumI(abs(ball), 75, 0);
  myOLED.setFont(SmallFont);myOLED.print(F("dB"), RIGHT, 0);
  if(ball<=0){myOLED.print(F("LCH"), 35, 20);}
  if(ball>=0){myOLED.print(F("RCH"), RIGHT, 20);}
  myOLED.drawLine(0, 30, 128, 30);
  myOLED.setFont(SmallFont);myOLED.print(F("VOLUME"), LEFT, 35);myOLED.printNumI(255-vol, 75, 35);
  myOLED.setFont(SmallFont);myOLED.print(F("TREBLE"), LEFT, 45);myOLED.printNumI((treb-7)*2, 75, 45);myOLED.print(F("dB"), RIGHT, 45);
  myOLED.setFont(SmallFont);myOLED.print(F("BASS"), LEFT, 55);myOLED.printNumI((bass-7)*2, 75, 55);myOLED.print(F("dB"), RIGHT, 55);
  myOLED.update();
  }}
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
   
////////////////// EEPROM //////////////////////////////////////////////////////////////
 if(millis()-times>10000 && w2==1 && mute==0){
     EEPROM.update(0,vol);EEPROM.update(1,treb);EEPROM.update(2,bass);
     EEPROM.update(3,bass_q+100);EEPROM.update(4,ball+100);
     EEPROM.update(5,demp);
     cl();menu=0;w2=0;w=1;} 
  
  }

void ball_fun(){if(ball>4){ball=4;}if(ball<-4){ball=-4;}}
void bass_q_func(){if(bass_q>15){bass_q=15;}if(bass_q<1){bass_q=1;}}
void bass_func(){if(bass<1){bass=1;}if(bass>13){bass=13;}}  
void treb_func(){if(treb<1){treb=1;}if(treb>13){treb=13;}}
void vol_func(){if(vol<8){vol=8;}if(vol>246){vol=246;}}
void to_Timer(){newPosition = myEnc.read()/4;} 
void cl(){myOLED.clrScr();ir.value=0;delay(300);}
void cl_vol(){myOLED.clrScr();ir.value=0;delay(100);}

void bass_q_f(byte pp){
   switch(bass_q){
    case 1:myOLED.print(F("80     Hz"), RIGHT, pp);break;
    case 2:myOLED.print(F("100    Hz"), RIGHT, pp);break;
    case 3:myOLED.print(F("120    Hz"), RIGHT, pp);break;
    case 4:myOLED.print(F("140    Hz"), RIGHT, pp);break;
    case 5:myOLED.print(F("160    Hz"), RIGHT, pp);break;
    case 6:myOLED.print(F("180    Hz"), RIGHT, pp);break;
    case 7:myOLED.print(F("200    Hz"), RIGHT, pp);break;
    case 8:myOLED.print(F("220    Hz"), RIGHT, pp);break;
    case 9:myOLED.print(F("240    Hz"), RIGHT, pp);break;
    case 10:myOLED.print(F("260    Hz"), RIGHT, pp);break;
    case 11:myOLED.print(F("280    Hz"), RIGHT, pp);break;
    case 12:myOLED.print(F("300    Hz"), RIGHT, pp);break;
    case 13:myOLED.print(F("320    Hz"), RIGHT, pp);break;
    case 14:myOLED.print(F("340    Hz"), RIGHT, pp);break;
    case 15:myOLED.print(F("360    Hz"), RIGHT, pp);break;
    }
  }

void init_sta(){
  wireWrite(I2C_STA333,0x00,0b01101011);
  //[2:0][MCS2 MCS1 MCS0]=011
  //[4:3][IR1 IR0]=01(96K)
  //[5][TWRB]=1(TEMP_ERR АВТОВКЛЮЧ.ПОСЛЕ ПЕРЕГРЕВА-АКТИВНА)
  //[6][TWAB]=0(ОГРАНИЧ ВЫХ МОЩНОСТИ ПРИ ПЕРЕГРЕВЕ-АКТИВНА)0X37 - УКАЗАТЬ УРОВ. ОГР. МОЩН.
  //[7][FDRB]=0(ЗАЩИТА.ОТКЛ.ПИТАНИЯ ПРИ НЕИСПРАВНОСТИ-АКТИВНА)
  wireWrite(I2C_STA333,0x01,0b10100000); 
  //[3:0][SAI]=0000(I2S 64*fs 16 to 24 bit) 
  //[4][SAIFB]=0(MSB) MSB/LSB-first
  //[5][DSCKE]=1(АКТИВНА ТАКТОВАЯ ЗАДЕРЖКА)
  //[7:6][C1IM C2IM]=10(СОПАСТОНОВЛЕНИЕ КАНАЛОВ)DEF
  wireWrite(I2C_STA333,0x02,0b10011110);
  //[1:0][OM0 OM1]=10( FFX power output mode)DEF
  //[5:2][CSZ]=0111(FFX compensating pulse size register)DEF
  //[6][RESERVED]
  //[7][OCRB]=1(ЗАЩИТА ПО ТОКУ-АКТИВНА)
  wireWrite(I2C_STA333,0x03,0b01000000|demp<<1);
  //[0][HPB]=0(ФИЛЬТР HPB АКТИВЕН)DEF ОПАСНО ВЫКЛЮЧАТЬ!!! 
  //[1][DEMP]=0(De-emphasis)OFF
  //[2][DSPB]=0(DSP bypass)АКТИВНА-РЕГ.ТЕМБРА АКТИВНЫ
  //[3][PSL]=0(Postscale link)DEF
  //[4][BQL]=0(Biquad coefficient link)DEF
  //[5][DCR]=0(Dynamic range compression)DEF
  //[6][ZDE]=1(Zero-detect mute enable)DEF
  //[7][SME]=0(Submix mode enable)DEF  
  wireWrite(I2C_STA333,0x04,0b11000010);//def
  //[0][MPCV]=0(Max power correction variable)DEF
  //[1][MPC]=1(Max power correction)DEF
  //[2][NSBW]=0(Noise-shaper bandwidth selection)DEF
  //[3][AME]=0(AM mode enable)DEF
  //[4][PWMS]=1(PWM speed mode)DEF
  //[5][DCCV]=0(Distortion compensation variable enable)DEF
  //[6][ZCE]=1(Zero-crossing volume enable)DEF
  //[7][SVE]=1(Soft volume update enable)DEF
  wireWrite(I2C_STA333,0x05,0b11011100);
  //[1:0]RESERVED
  //[2][IDE]=1(Invalid input detect mute enable)DEF
  //[3][BCLE]=1(Binary output mode clock loss detection)DEF
  //[4][LDTE]=1(LRCK double trigger protection)DEF
  //[5][ECLE]=0(Auto EAPD on clock loss)DEF
  //[6][PWDN]=1(IC power down)DEF
  //[7][EAPD]=1(ВНЕШНЕЕ ПИТАНИЕ УСИЛИТЕЛЯ)АКТИВНО
  wireWrite(I2C_STA333,0x06,0b00010000);// DEF
  //Mute/line output configuration register
  wireWrite(I2C_STA333,0x07,0);// 0 dB
  //Master volume register BYTE 0...0xFE = 0 dB...-127,5 | 0xFF = MUTE
   wireWrite(I2C_STA333,0x08,vol+ball*2);
  //Channel 1 volume BYTE 0...0xEC = +48...-80 dB 0xFF = MUTE
  wireWrite(I2C_STA333,0x09,vol-ball*2);
  //Channel 2 volume BYTE 0...0xEC = +48...-80 dB 0xFF = MUTE 
  wireWrite(I2C_STA333,0x0A,255);
  wireWrite(I2C_STA333,0x0B,0b10000000);//DEF
  //[4:5][AMGC](Audio preset register 1)
  //Audio preset gain compression/limiters selection
  wireWrite(I2C_STA333,0x0C,0b00001000|bass_q<<4);
  //[0][amame]
  //[3:1][AMAM]=000(AM interference frequency switching)DEF
  //[7:4][XO]=0000(Кроссовер для управления басами)byte 0000...0001...1111 = DEF...80Hz...360Hz
  
  wireWrite(I2C_STA333,0x0E,0b00000000);
  //[0][TCB]=0(Tone control bypass)DEF
  //[1][EQBP]=0(EQ bypass)DEF
  //[2][VBP]=0(Volume bypass)DEF
  //[3][BO]=0(Binary output enable)DEF
  //[5:4][LS]=00(Channel limiter mapping as a function of CxLS bits)DEF
  //[7:6][OM]=00(Channel output mapping as a function of CxOM bits)DEF
  wireWrite(I2C_STA333,0x0F,0b01000000);
  //[0][TCB]=0(Tone control bypass)DEF
  //[1][EQBP]=0(EQ bypass)DEF
  //[2][VBP]=0(Volume bypass)DEF
  //[3][BO]=0(Binary output enable)DEF
  //[5:4][LS]=00(Channel limiter mapping as a function of CxLS bits)DEF
  //[7:6][OM]=00(Channel output mapping as a function of CxOM bits)DEF
  wireWrite(I2C_STA333,0x10,0b10000000);
  //[1:0]RESERVED
  //[2][VBP]=0(Volume bypass)DEF
  //[3][BO]=0(Binary output enable)DEF
  //[5:4][LS]=00(Channel limiter mapping as a function of CxLS bits)DEF
  //[7:6][OM]=00(Channel output mapping as a function of CxOM bits)DEF
  wireWrite(I2C_STA333,0x11,0|bass|treb<<4);// тембр ВЧ НЧ 
  
  wireWrite(I2C_STA333,0x12,0b01101010);
  //(Limiter 1 attack/release rate)DEF
  wireWrite(I2C_STA333,0x13,0b01101001);
  //(Limiter 1 attack/release threshold )DEF
  wireWrite(I2C_STA333,0x14,0b01101010);
  //(Limiter 2 attack/release rate)DEF
  wireWrite(I2C_STA333,0x15,0b01101001);
  //(Limiter 2 attack/release threshold)DEF
  wireWrite(I2C_STA333,0x16,255);
  //(Coefficient address register)DEF
  wireWrite(I2C_STA333,0x17,255);
  wireWrite(I2C_STA333,0x18,255);
  wireWrite(I2C_STA333,0x19,255);
  
  wireWrite(I2C_STA333,0x1A,255);
  wireWrite(I2C_STA333,0x1B,255);
  wireWrite(I2C_STA333,0x1C,255);
  //(Coefficient b2 data register bits)DEF
  wireWrite(I2C_STA333,0x1D,255);
  wireWrite(I2C_STA333,0x1E,255);
  wireWrite(I2C_STA333,0x1F,255);
  //(Coefficient a1 data register bits)DEF
  wireWrite(I2C_STA333,0x20,255);
  wireWrite(I2C_STA333,0x21,255);
  wireWrite(I2C_STA333,0x22,255);
  //(Coefficient a2 data register bits)DEF
  wireWrite(I2C_STA333,0x23,255);
  wireWrite(I2C_STA333,0x24,255);
  wireWrite(I2C_STA333,0x25,255);
  //(Coefficient b0 data register bits)DEF 
  wireWrite(I2C_STA333,0x26,255);
    
  }  

byte wireRead(byte addr, byte reg){ // I2C
  Wire.beginTransmission(addr);
  Wire.write (reg);
  Wire.endTransmission();
  Wire.requestFrom(addr,1);
  while(Wire.available()<1);
  byte value = Wire.read();
  return value;
  }  
 
void wireWrite(byte addr, byte reg, byte data){
  Wire.beginTransmission(addr);
  Wire.write (reg);
  Wire.write (data);
  Wire.endTransmission();
  }   

2

Re: STA333BW

http://forum.rcl-radio.ru/uploads/images/2023/02/4be9466c6e6a8a838b9153f7f1b665c5.png

http://rcl-radio.ru/wp-content/uploads/2022/07/%D0%A1%D0%BD%D0%B8%D0%BC%D0%BE%D0%BA-%D1%8D%D0%BA%D1%80%D0%B0%D0%BD%D0%B0-%D0%BE%D1%82-2022-07-18-22-20-19.png

#define I2C_STA333 0x1C // Address chip | PIN_SA = GND 

#define IR_1 0x2FDD02F // Кнопка menu up
#define IR_2 0x2FD32CD // Кнопка menu dw
#define IR_3 0x2FD906F // Кнопка >
#define IR_4 0x2FDF20D // Кнопка <
#define IR_5 0x2FDF00F // Кнопка MUTE
#define IR_6 0x2FD00FF // Кнопка STANDBY (POWER)
#define IR_7 0x2FD6A95 // DEMP

#include <Wire.h>
#include <OLED_I2C.h>           // http://rcl-radio.ru/wp-content/uploads/2022/01/OLED_I2C.zip
#include <Encoder.h>            // http://rcl-radio.ru/wp-content/uploads/2019/05/Encoder.zip    
#include <EEPROM.h>
#include <MsTimer2.h>           // http://rcl-radio.ru/wp-content/uploads/2018/11/MsTimer2.zip       
#include <boarddefs.h>          // входит в состав библиотеки IRremote
#include <IRremote.h>           // http://rcl-radio.ru/wp-content/uploads/2019/06/IRremote.zip
#include <DS3231.h>             // http://rcl-radio.ru/wp-content/uploads/2022/07/DS3231.zip

 OLED  myOLED(SDA, SCL, 8);
 IRrecv irrecv(12); // указываем вывод модуля IR приемника
 Encoder myEnc(9, 8);// DT, CLK
 decode_results ir; 
 DS3231 clock;RTCDateTime DateTime;
 
 int bass_q=3,bass,treb,vol,menu,ball,hour,minut,secon,old_sec;
 extern uint8_t SmallFont[],BigNumbers[];
 unsigned long times,oldPosition  = -999,newPosition;
 bool www,w,w2,gr1,gr2,mute,power,demp;
 byte a[6];


void setup() {
  Wire.begin();Serial.begin(9600);irrecv.enableIRIn();clock.begin();
  myOLED.begin();
  myOLED.setBrightness(100);
  pinMode(4,OUTPUT);               // RESET
  pinMode(5,OUTPUT);               // PWRDN
  digitalWrite(4,LOW);delay(10);   // RESET 
  digitalWrite(4,HIGH);delay(10);  // RESET 
  digitalWrite(5,HIGH);delay(10);  // PWRDN
  pinMode(10,INPUT);               // КНОПКА SW энкодера
  pinMode(A0,INPUT_PULLUP);        // КНОПКА MUTE
  pinMode(A1,INPUT_PULLUP);        // КНОПКА POWER
  pinMode(13,OUTPUT);              // ВЫХОД УПРАВЛЕНИЯ STANDBY
  MsTimer2::set(3, to_Timer);MsTimer2::start();
  if(EEPROM.read(100)!=0){for(int i=0;i<101;i++){EEPROM.update(i,0);}}// очистка памяти при первом включении  
  //  clock.setDateTime(__DATE__, __TIME__); // Устанавливаем время на часах, основываясь на времени компиляции скетча
  wireWrite(I2C_STA333,0x05,0b01011100);delay(10);
  myOLED.clrScr();
  myOLED.setFont(SmallFont);
  myOLED.print(F("Digital audio system"), CENTER, 10);
  myOLED.print(F("STA333BW"), CENTER, 30);
  myOLED.print(F("2.0 channel 40W"), CENTER, 50);
  myOLED.update();
  delay(2000);
  vol = EEPROM.read(0);treb = EEPROM.read(1);bass = EEPROM.read(2);
  bass_q = EEPROM.read(3)-100;ball = EEPROM.read(4)-100;demp = EEPROM.read(5);
  init_sta();
  Serial.println(wireRead(I2C_STA333,0x2D),BIN); 
}

void loop() {
/// IR ////////////////////////////////////////
  if ( irrecv.decode( &ir )) {Serial.print("0x");Serial.println( ir.value,HEX);irrecv.resume();times=millis();w=1;w2=1;}// IR приемник - чтение, в мониторе порта отображаются коды кнопок
  if(ir.value==0){gr1=0;gr2=0;}// запрет нажатий не активных кнопок пульта  

/////// BUTTON ////////////////////////////////////////////////////////////////////////////////////////////////////////
if(power==0){
/// menu
   if(digitalRead(10)==LOW||ir.value==IR_1){menu++;gr1=0;gr2=0;cl();delay(200);times=millis();w=1;w2=1;if(menu>4){menu=0;}}
   if(ir.value==IR_2){menu--;gr1=0;gr2=0;cl();delay(200);times=millis();w=1;w2=1;if(menu<0){menu=4;}}
/// mute
   if((digitalRead(A0)==LOW||ir.value==IR_5)&&mute==0){mute=1;w=1;menu=100;cl();wireWrite(I2C_STA333,0x06,0b00010110);
       myOLED.clrScr();myOLED.setFont(SmallFont);myOLED.print(F("MUTE"), CENTER, 25);myOLED.update();}
   if((digitalRead(A0)==LOW||ir.value==IR_5)&&mute==1){mute=0;w=1;menu=0;cl();wireWrite(I2C_STA333,0x06,0b00010000);} 
//// DEMP
   if(ir.value==IR_7&&demp==0){demp=1;w=1;cl();wireWrite(I2C_STA333,0x03,0b01000000|demp<<1);
       myOLED.clrScr();myOLED.setFont(SmallFont);myOLED.print(F("De-emphasis ON"), CENTER, 25);myOLED.update();delay(2000);menu=0;}
   if(ir.value==IR_7&&demp==1){demp=0;w=1;cl();wireWrite(I2C_STA333,0x03,0b01000000|demp<<1);
       myOLED.clrScr();myOLED.setFont(SmallFont);myOLED.print(F("De-emphasis OFF"), CENTER, 25);myOLED.update();delay(2000);menu=0;}       
   
   
}
 /// POWER ////////////////////////////////////
   if((digitalRead(A1)==LOW||ir.value==IR_6)&&power==0){power=1;menu=100;myOLED.setBrightness(1);cl();myEnc.write(0);
    myOLED.clrScr();myOLED.setFont(SmallFont);myOLED.print(F("POWER OFF"), CENTER, 10);myOLED.update();
    wireWrite(I2C_STA333,0x05,0b01011100);delay(2000);cl();}
    
   if((digitalRead(A1)==LOW||ir.value==IR_6)&&power==1&&digitalRead(10)==HIGH){power=0;menu=0;myOLED.setBrightness(100);cl();myEnc.write(0);w=1;
    myOLED.clrScr();myOLED.setFont(SmallFont);myOLED.print(F("POWER ON"), CENTER, 10);myOLED.update();
    wireWrite(I2C_STA333,0x05,0b11011100);delay(2000);cl();}  
    /// standby output 
   if(power==1){digitalWrite(13,LOW);}else{digitalWrite(13,HIGH);}  
 
     
//////// VOLUME //////////////////////////////////////////////////////////////////////////////////////////////////////////////  
  if(menu==0){
   if(newPosition != oldPosition){oldPosition = newPosition;vol=vol-newPosition;myEnc.write(0);newPosition=0;times=millis();w=1;w2=1;vol_func();www=1;}
 
   if(ir.value==IR_4){vol++;gr1=1;gr2=0;cl_vol();times=millis();w=1;w2=1;vol_func();www=1;}// кнопка > 
   if(ir.value==0xFFFFFFFF and gr1==1){vol++;gr2=0;cl_vol();times=millis();w=1;w2=1;vol_func();www=1;}// кнопка >>>>>>
   if(ir.value==IR_3){vol--;gr1=0;gr2=1;cl_vol();times=millis();w=1;w2=1;vol_func();www=1;}// кнопка <
   if(ir.value==0xFFFFFFFF and gr2==1){vol--;gr1=0;cl_vol();times=millis();w=1;w2=1;vol_func();www=1;}// кнопка <<<<<<

  if(www==1){www=0;  
    wireWrite(I2C_STA333,0x08,vol+ball*2);
    wireWrite(I2C_STA333,0x09,vol-ball*2);}
  
  if(w==1){w=0;
  myOLED.clrScr();
  myOLED.setFont(SmallFont);myOLED.print(F("VOLUME"), LEFT, 0);myOLED.setFont(BigNumbers);myOLED.printNumI(255-vol, 75, 0);
  myOLED.setFont(SmallFont);if(demp==0){myOLED.print(F("DEMP_OFF"), LEFT, 20);}
                              else{myOLED.print(F("DEMP_ON"), LEFT, 20);}
  myOLED.drawLine(0, 30, 128, 30);
  myOLED.setFont(SmallFont);myOLED.print(F("TREBLE"), LEFT, 35);myOLED.printNumI((treb-7)*2, 75, 35);myOLED.print(F("dB"), RIGHT, 35);
  myOLED.setFont(SmallFont);myOLED.print(F("BASS"), LEFT, 45);myOLED.printNumI((bass-7)*2, 75, 45);myOLED.print(F("dB"), RIGHT, 45);
  myOLED.setFont(SmallFont);myOLED.print(F("F_BASS"), LEFT, 55);bass_q_f(55);
  myOLED.update();
  }}
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////  

//////// TREBLE //////////////////////////////////////////////////////////////////////////////////////////////////////////////  
  if(menu==1){
   if(newPosition != oldPosition){oldPosition = newPosition;treb=treb+newPosition;myEnc.write(0);newPosition=0;times=millis();w=1;w2=1;treb_func();www=1;}
 
   if(ir.value==IR_3){treb++;gr1=1;gr2=0;cl();times=millis();w=1;w2=1;treb_func();www=1;}// кнопка > 
   if(ir.value==0xFFFFFFFF and gr1==1){treb++;gr2=0;cl();times=millis();w=1;w2=1;treb_func();www=1;}// кнопка >>>>>>
   if(ir.value==IR_4){treb--;gr1=0;gr2=1;cl();times=millis();w=1;w2=1;treb_func();www=1;}// кнопка <
   if(ir.value==0xFFFFFFFF and gr2==1){treb--;gr1=0;cl();times=millis();w=1;w2=1;treb_func();www=1;}// кнопка <<<<<<

  if(www==1){www=0;wireWrite(I2C_STA333,0x11,0|bass|treb<<4);}
  
  if(w==1){w=0;
  myOLED.clrScr();
  myOLED.setFont(SmallFont);myOLED.print(F("TREBLE"), LEFT, 0);myOLED.setFont(BigNumbers);myOLED.printNumI((treb-7)*2, 75, 0);
  myOLED.setFont(SmallFont);myOLED.print(F("dB"), RIGHT, 20);
  myOLED.drawLine(0, 30, 128, 30);
  myOLED.setFont(SmallFont);myOLED.print(F("BASS"), LEFT, 35);myOLED.printNumI((bass-7)*2, 75, 35);myOLED.print(F("dB"), RIGHT, 35);
  myOLED.setFont(SmallFont);myOLED.print(F("F_BASS"), LEFT, 45);myOLED.printNumI(bass_q, 75, 45);bass_q_f(45);
  myOLED.setFont(SmallFont);myOLED.print(F("BALANCE"), LEFT, 55);myOLED.printNumI(ball, 75, 55);myOLED.print(F("dB"), RIGHT, 55);
  myOLED.update();
  }}
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////  

//////// BASS //////////////////////////////////////////////////////////////////////////////////////////////////////////////  
  if(menu==2){
   if(newPosition != oldPosition){oldPosition = newPosition;bass=bass+newPosition;myEnc.write(0);newPosition=0;times=millis();w=1;w2=1;bass_func();www=1;}
 
   if(ir.value==IR_3){bass++;gr1=1;gr2=0;cl();times=millis();w=1;w2=1;bass_func();www=1;}// кнопка > 
   if(ir.value==0xFFFFFFFF and gr1==1){bass++;gr2=0;cl();times=millis();w=1;w2=1;bass_func();www=1;}// кнопка >>>>>>
   if(ir.value==IR_4){bass--;gr1=0;gr2=1;cl();times=millis();w=1;w2=1;bass_func();www=1;}// кнопка <
   if(ir.value==0xFFFFFFFF and gr2==1){bass--;gr1=0;cl();times=millis();w=1;w2=1;bass_func();www=1;}// кнопка <<<<<<

  if(www==1){www=0;wireWrite(I2C_STA333,0x11,0|bass|treb<<4);}
  
  if(w==1){w=0;
  myOLED.clrScr();
  myOLED.setFont(SmallFont);myOLED.print(F("BASS"), LEFT, 0);myOLED.setFont(BigNumbers);myOLED.printNumI((bass-7)*2, 75, 0);
  myOLED.setFont(SmallFont);myOLED.print(F("dB"), RIGHT, 20);
  myOLED.drawLine(0, 30, 128, 30);
  myOLED.setFont(SmallFont);myOLED.print(F("F_BASS"), LEFT, 35);myOLED.printNumI(bass_q, 75, 35);bass_q_f(35);
  myOLED.setFont(SmallFont);myOLED.print(F("BALANCE"), LEFT, 45);myOLED.printNumI(ball, 75, 45);myOLED.print(F("dB"), RIGHT, 45);
  myOLED.setFont(SmallFont);myOLED.print(F("VOLUME"), LEFT, 55);myOLED.printNumI(255-vol, 75, 55);
  myOLED.update();
  }}
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////  

//////// BASS_F //////////////////////////////////////////////////////////////////////////////////////////////////////////////  
  if(menu==3){
   if(newPosition != oldPosition){oldPosition = newPosition;bass_q=bass_q+newPosition;myEnc.write(0);newPosition=0;times=millis();w=1;w2=1;bass_q_func();www=1;}
 
   if(ir.value==IR_3){bass_q++;gr1=1;gr2=0;cl();times=millis();w=1;w2=1;bass_q_func();www=1;}// кнопка > 
   if(ir.value==0xFFFFFFFF and gr1==1){bass_q++;gr2=0;cl();times=millis();w=1;w2=1;bass_q_func();www=1;}// кнопка >>>>>>
   if(ir.value==IR_4){bass_q--;gr1=0;gr2=1;cl();times=millis();w=1;w2=1;bass_q_func();www=1;}// кнопка <
   if(ir.value==0xFFFFFFFF and gr2==1){bass_q--;gr1=0;cl();times=millis();w=1;w2=1;bass_q_func();www=1;}// кнопка <<<<<<

  if(www==1){www=0;wireWrite(I2C_STA333,0x0C,0b00001000|bass_q<<4);}
  
  if(w==1){w=0;
  myOLED.clrScr();
  myOLED.setFont(SmallFont);myOLED.print(F("F_BASS"), LEFT, 0);myOLED.setFont(BigNumbers);myOLED.printNumI(60+bass_q*20, 65, 0);
  myOLED.setFont(SmallFont);myOLED.print(F("Hz"), RIGHT, 20);
  myOLED.drawLine(0, 30, 128, 30);
  myOLED.setFont(SmallFont);myOLED.print(F("BALANCE"), LEFT, 35);myOLED.printNumI(ball, 75, 35);myOLED.print(F("dB"), RIGHT, 35);
  myOLED.setFont(SmallFont);myOLED.print(F("VOLUME"), LEFT, 45);myOLED.printNumI(255-vol, 75, 45);
  myOLED.setFont(SmallFont);myOLED.print(F("TREBLE"), LEFT, 55);myOLED.printNumI((treb-7)*2, 75, 55);myOLED.print(F("dB"), RIGHT, 55);
  myOLED.update();
  }}
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////  

//////// BALANCE //////////////////////////////////////////////////////////////////////////////////////////////////////////////  
  if(menu==4){
  if (newPosition != oldPosition){oldPosition = newPosition;ball=ball+newPosition;myEnc.write(0);newPosition=0;times=millis();w=1;w2=1;ball_fun();www=1;}
 
  if(ir.value==IR_3){ball++;gr1=1;gr2=0;cl();times=millis();w=1;w2=1;ball_fun();www=1;}// кнопка > 
  if(ir.value==IR_4){ball--;gr1=0;gr2=1;cl();times=millis();w=1;w2=1;ball_fun();www=1;}// кнопка <

  if(www==1){www=0;  
    wireWrite(I2C_STA333,0x08,vol+ball*2);
    wireWrite(I2C_STA333,0x09,vol-ball*2);}
    
  if(w==1){w=0;
  myOLED.clrScr();
  myOLED.setFont(SmallFont);myOLED.print(F("BALANCE"), LEFT, 0);myOLED.setFont(BigNumbers);myOLED.printNumI(abs(ball), 75, 0);
  myOLED.setFont(SmallFont);myOLED.print(F("dB"), RIGHT, 0);
  if(ball<=0){myOLED.print(F("LCH"), 35, 20);}
  if(ball>=0){myOLED.print(F("RCH"), RIGHT, 20);}
  myOLED.drawLine(0, 30, 128, 30);
  myOLED.setFont(SmallFont);myOLED.print(F("VOLUME"), LEFT, 35);myOLED.printNumI(255-vol, 75, 35);
  myOLED.setFont(SmallFont);myOLED.print(F("TREBLE"), LEFT, 45);myOLED.printNumI((treb-7)*2, 75, 45);myOLED.print(F("dB"), RIGHT, 45);
  myOLED.setFont(SmallFont);myOLED.print(F("BASS"), LEFT, 55);myOLED.printNumI((bass-7)*2, 75, 55);myOLED.print(F("dB"), RIGHT, 55);
  myOLED.update();
  }}
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

/////////////////// ЧАСЫ ///////////////////////////////////////////////////////////////////
if(power==1){menu=100;
  DateTime = clock.getDateTime();hour = DateTime.hour;minut = DateTime.minute;secon = DateTime.second;   
     a[0]=hour/10;
     a[1]=hour%10;
     a[2]=minut/10;
     a[3]=minut%10;
     a[4]=secon/10;
     a[5]=secon%10;
  if(old_sec!=secon || digitalRead(10)==LOW){
  myOLED.clrScr();
  myOLED.setFont(BigNumbers);myOLED.printNumI(a[0], 15, 5);myOLED.printNumI(a[1], 30, 5);
  myOLED.setFont(SmallFont);myOLED.print(F(":"), 45, 15);
  myOLED.setFont(BigNumbers);myOLED.printNumI(a[2], 50, 5);myOLED.printNumI(a[3], 65, 5);
  myOLED.setFont(SmallFont);myOLED.print(F(":"), 80, 15);
  myOLED.setFont(BigNumbers);myOLED.printNumI(a[4], 85, 5);myOLED.printNumI(a[5], 100, 5);
  myOLED.update();
  } 
  old_sec=secon;
//// set time ////
  if(digitalRead(10)==LOW&&digitalRead(A0)==LOW){hour++;if(hour>23){hour=0;} clock.setDateTime(2022, 7, 15, hour, minut, secon);delay(100);}//  MUTE HH++
  if(digitalRead(10)==LOW&&digitalRead(A1)==LOW){minut++;if(minut>59){minut=0;} clock.setDateTime(2022, 7, 15, hour, minut, secon);delay(100);}// POWER MM++
  if(digitalRead(10)==LOW&&newPosition != oldPosition){oldPosition = newPosition;myEnc.write(0);newPosition=0;clock.setDateTime(2022, 7, 15, hour, minut, 0);} // encoder +/- clear sec
}
   
////////////////// EEPROM //////////////////////////////////////////////////////////////
 if(millis()-times>10000 && w2==1 && mute==0 && power==0){
     EEPROM.update(0,vol);EEPROM.update(1,treb);EEPROM.update(2,bass);
     EEPROM.update(3,bass_q+100);EEPROM.update(4,ball+100);
     EEPROM.update(5,demp);
     cl();menu=0;w2=0;w=1;} 
  
  }

void ball_fun(){if(ball>4){ball=4;}if(ball<-4){ball=-4;}}
void bass_q_func(){if(bass_q>15){bass_q=15;}if(bass_q<1){bass_q=1;}}
void bass_func(){if(bass<1){bass=1;}if(bass>13){bass=13;}}  
void treb_func(){if(treb<1){treb=1;}if(treb>13){treb=13;}}
void vol_func(){if(vol<8){vol=8;}if(vol>246){vol=246;}}
void to_Timer(){newPosition = myEnc.read()/4;} 
void cl(){myOLED.clrScr();ir.value=0;delay(300);}
void cl_vol(){myOLED.clrScr();ir.value=0;delay(100);}

void bass_q_f(byte pp){
   switch(bass_q){
    case 1:myOLED.print(F("80     Hz"), RIGHT, pp);break;
    case 2:myOLED.print(F("100    Hz"), RIGHT, pp);break;
    case 3:myOLED.print(F("120    Hz"), RIGHT, pp);break;
    case 4:myOLED.print(F("140    Hz"), RIGHT, pp);break;
    case 5:myOLED.print(F("160    Hz"), RIGHT, pp);break;
    case 6:myOLED.print(F("180    Hz"), RIGHT, pp);break;
    case 7:myOLED.print(F("200    Hz"), RIGHT, pp);break;
    case 8:myOLED.print(F("220    Hz"), RIGHT, pp);break;
    case 9:myOLED.print(F("240    Hz"), RIGHT, pp);break;
    case 10:myOLED.print(F("260    Hz"), RIGHT, pp);break;
    case 11:myOLED.print(F("280    Hz"), RIGHT, pp);break;
    case 12:myOLED.print(F("300    Hz"), RIGHT, pp);break;
    case 13:myOLED.print(F("320    Hz"), RIGHT, pp);break;
    case 14:myOLED.print(F("340    Hz"), RIGHT, pp);break;
    case 15:myOLED.print(F("360    Hz"), RIGHT, pp);break;
    }
  }

void init_sta(){
  wireWrite(I2C_STA333,0x00,0b01101011);
  //[2:0][MCS2 MCS1 MCS0]=011
  //[4:3][IR1 IR0]=01(96K)
  //[5][TWRB]=1(TEMP_ERR АВТОВКЛЮЧ.ПОСЛЕ ПЕРЕГРЕВА-АКТИВНА)
  //[6][TWAB]=0(ОГРАНИЧ ВЫХ МОЩНОСТИ ПРИ ПЕРЕГРЕВЕ-АКТИВНА)0X37 - УКАЗАТЬ УРОВ. ОГР. МОЩН.
  //[7][FDRB]=0(ЗАЩИТА.ОТКЛ.ПИТАНИЯ ПРИ НЕИСПРАВНОСТИ-АКТИВНА)
  wireWrite(I2C_STA333,0x01,0b10100000); 
  //[3:0][SAI]=0000(I2S 64*fs 16 to 24 bit) 
  //[4][SAIFB]=0(MSB) MSB/LSB-first
  //[5][DSCKE]=1(АКТИВНА ТАКТОВАЯ ЗАДЕРЖКА)
  //[7:6][C1IM C2IM]=10(СОПАСТОНОВЛЕНИЕ КАНАЛОВ)DEF
  wireWrite(I2C_STA333,0x02,0b10011110);
  //[1:0][OM0 OM1]=10( FFX power output mode)DEF
  //[5:2][CSZ]=0111(FFX compensating pulse size register)DEF
  //[6][RESERVED]
  //[7][OCRB]=1(ЗАЩИТА ПО ТОКУ-АКТИВНА)
  wireWrite(I2C_STA333,0x03,0b01000000|demp<<1);
  //[0][HPB]=0(ФИЛЬТР HPB АКТИВЕН)DEF ОПАСНО ВЫКЛЮЧАТЬ!!! 
  //[1][DEMP]=0(De-emphasis)OFF
  //[2][DSPB]=0(DSP bypass)АКТИВНА-РЕГ.ТЕМБРА АКТИВНЫ
  //[3][PSL]=0(Postscale link)DEF
  //[4][BQL]=0(Biquad coefficient link)DEF
  //[5][DCR]=0(Dynamic range compression)DEF
  //[6][ZDE]=1(Zero-detect mute enable)DEF
  //[7][SME]=0(Submix mode enable)DEF  
  wireWrite(I2C_STA333,0x04,0b11000010);//def
  //[0][MPCV]=0(Max power correction variable)DEF
  //[1][MPC]=1(Max power correction)DEF
  //[2][NSBW]=0(Noise-shaper bandwidth selection)DEF
  //[3][AME]=0(AM mode enable)DEF
  //[4][PWMS]=1(PWM speed mode)DEF
  //[5][DCCV]=0(Distortion compensation variable enable)DEF
  //[6][ZCE]=1(Zero-crossing volume enable)DEF
  //[7][SVE]=1(Soft volume update enable)DEF
  wireWrite(I2C_STA333,0x05,0b11011100);
  //[1:0]RESERVED
  //[2][IDE]=1(Invalid input detect mute enable)DEF
  //[3][BCLE]=1(Binary output mode clock loss detection)DEF
  //[4][LDTE]=1(LRCK double trigger protection)DEF
  //[5][ECLE]=0(Auto EAPD on clock loss)DEF
  //[6][PWDN]=1(IC power down)DEF
  //[7][EAPD]=1(ВНЕШНЕЕ ПИТАНИЕ УСИЛИТЕЛЯ)АКТИВНО
  wireWrite(I2C_STA333,0x06,0b00010000);// DEF
  //Mute/line output configuration register
  wireWrite(I2C_STA333,0x07,0);// 0 dB
  //Master volume register BYTE 0...0xFE = 0 dB...-127,5 | 0xFF = MUTE
   wireWrite(I2C_STA333,0x08,vol+ball*2);
  //Channel 1 volume BYTE 0...0xEC = +48...-80 dB 0xFF = MUTE
  wireWrite(I2C_STA333,0x09,vol-ball*2);
  //Channel 2 volume BYTE 0...0xEC = +48...-80 dB 0xFF = MUTE 
  wireWrite(I2C_STA333,0x0A,255);
  wireWrite(I2C_STA333,0x0B,0b10000000);//DEF
  //[4:5][AMGC](Audio preset register 1)
  //Audio preset gain compression/limiters selection
  wireWrite(I2C_STA333,0x0C,0b00001000|bass_q<<4);
  //[0][amame]
  //[3:1][AMAM]=000(AM interference frequency switching)DEF
  //[7:4][XO]=0000(Кроссовер для управления басами)byte 0000...0001...1111 = DEF...80Hz...360Hz
  
  wireWrite(I2C_STA333,0x0E,0b00000000);
  //[0][TCB]=0(Tone control bypass)DEF
  //[1][EQBP]=0(EQ bypass)DEF
  //[2][VBP]=0(Volume bypass)DEF
  //[3][BO]=0(Binary output enable)DEF
  //[5:4][LS]=00(Channel limiter mapping as a function of CxLS bits)DEF
  //[7:6][OM]=00(Channel output mapping as a function of CxOM bits)DEF
  wireWrite(I2C_STA333,0x0F,0b01000000);
  //[0][TCB]=0(Tone control bypass)DEF
  //[1][EQBP]=0(EQ bypass)DEF
  //[2][VBP]=0(Volume bypass)DEF
  //[3][BO]=0(Binary output enable)DEF
  //[5:4][LS]=00(Channel limiter mapping as a function of CxLS bits)DEF
  //[7:6][OM]=00(Channel output mapping as a function of CxOM bits)DEF
  wireWrite(I2C_STA333,0x10,0b10000000);
  //[1:0]RESERVED
  //[2][VBP]=0(Volume bypass)DEF
  //[3][BO]=0(Binary output enable)DEF
  //[5:4][LS]=00(Channel limiter mapping as a function of CxLS bits)DEF
  //[7:6][OM]=00(Channel output mapping as a function of CxOM bits)DEF
  wireWrite(I2C_STA333,0x11,0|bass|treb<<4);// тембр ВЧ НЧ 
  
  wireWrite(I2C_STA333,0x12,0b01101010);
  //(Limiter 1 attack/release rate)DEF
  wireWrite(I2C_STA333,0x13,0b01101001);
  //(Limiter 1 attack/release threshold )DEF
  wireWrite(I2C_STA333,0x14,0b01101010);
  //(Limiter 2 attack/release rate)DEF
  wireWrite(I2C_STA333,0x15,0b01101001);
  //(Limiter 2 attack/release threshold)DEF
  wireWrite(I2C_STA333,0x16,255);
  //(Coefficient address register)DEF
  wireWrite(I2C_STA333,0x17,255);
  wireWrite(I2C_STA333,0x18,255);
  wireWrite(I2C_STA333,0x19,255);
  
  wireWrite(I2C_STA333,0x1A,255);
  wireWrite(I2C_STA333,0x1B,255);
  wireWrite(I2C_STA333,0x1C,255);
  //(Coefficient b2 data register bits)DEF
  wireWrite(I2C_STA333,0x1D,255);
  wireWrite(I2C_STA333,0x1E,255);
  wireWrite(I2C_STA333,0x1F,255);
  //(Coefficient a1 data register bits)DEF
  wireWrite(I2C_STA333,0x20,255);
  wireWrite(I2C_STA333,0x21,255);
  wireWrite(I2C_STA333,0x22,255);
  //(Coefficient a2 data register bits)DEF
  wireWrite(I2C_STA333,0x23,255);
  wireWrite(I2C_STA333,0x24,255);
  wireWrite(I2C_STA333,0x25,255);
  //(Coefficient b0 data register bits)DEF 
  wireWrite(I2C_STA333,0x26,255);
    
  }  

byte wireRead(byte addr, byte reg){ // I2C
  Wire.beginTransmission(addr);
  Wire.write (reg);
  Wire.endTransmission();
  Wire.requestFrom(addr,1);
  while(Wire.available()<1);
  byte value = Wire.read();
  return value;
  }  
 
void wireWrite(byte addr, byte reg, byte data){
  Wire.beginTransmission(addr);
  Wire.write (reg);
  Wire.write (data);
  Wire.endTransmission();
  }   

3

Re: STA333BW

Защита от выгорания пикселей OLED дисплея в режиме POWER OFF. 

#define I2C_STA333 0x1C // Address chip | PIN_SA = GND 

#define IR_1 0x2FDD02F // Кнопка menu up
#define IR_2 0x2FD32CD // Кнопка menu dw
#define IR_3 0x2FD906F // Кнопка >
#define IR_4 0x2FDF20D // Кнопка <
#define IR_5 0x2FDF00F // Кнопка MUTE
#define IR_6 0x2FD00FF // Кнопка STANDBY (POWER)
#define IR_7 0x2FD6A95 // DEMP

#include <Wire.h>
#include <OLED_I2C.h>           // http://rcl-radio.ru/wp-content/uploads/2022/01/OLED_I2C.zip
#include <Encoder.h>            // http://rcl-radio.ru/wp-content/uploads/2019/05/Encoder.zip    
#include <EEPROM.h>
#include <MsTimer2.h>           // http://rcl-radio.ru/wp-content/uploads/2018/11/MsTimer2.zip       
#include <boarddefs.h>          // входит в состав библиотеки IRremote
#include <IRremote.h>           // http://rcl-radio.ru/wp-content/uploads/2019/06/IRremote.zip
#include <DS3231.h>             // http://rcl-radio.ru/wp-content/uploads/2022/07/DS3231.zip

 OLED  myOLED(SDA, SCL, 8);
 IRrecv irrecv(12); // указываем вывод модуля IR приемника
 Encoder myEnc(9, 8);// DT, CLK
 decode_results ir; 
 DS3231 clock;RTCDateTime DateTime;
 
 int bass_q=3,bass,treb,vol,menu,ball,hour,minut,secon,old_sec;
 extern uint8_t SmallFont[],BigNumbers[];
 unsigned long times,oldPosition  = -999,newPosition,tim;
 bool www,w,w2,gr1,gr2,mute,power,demp,w3=0;
 byte a[6];


void setup() {
  Wire.begin();Serial.begin(9600);irrecv.enableIRIn();clock.begin();
  myOLED.begin();
  myOLED.setBrightness(100);
  pinMode(4,OUTPUT);               // RESET
  pinMode(5,OUTPUT);               // PWRDN
  digitalWrite(4,LOW);delay(10);   // RESET 
  digitalWrite(4,HIGH);delay(10);  // RESET 
  digitalWrite(5,HIGH);delay(10);  // PWRDN
  pinMode(10,INPUT);               // КНОПКА SW энкодера
  pinMode(A0,INPUT_PULLUP);        // КНОПКА MUTE
  pinMode(A1,INPUT_PULLUP);        // КНОПКА POWER
  pinMode(13,OUTPUT);              // ВЫХОД УПРАВЛЕНИЯ STANDBY
  MsTimer2::set(3, to_Timer);MsTimer2::start();
  if(EEPROM.read(100)!=0){for(int i=0;i<101;i++){EEPROM.update(i,0);}}// очистка памяти при первом включении  
  //  clock.setDateTime(__DATE__, __TIME__); // Устанавливаем время на часах, основываясь на времени компиляции скетча
  wireWrite(I2C_STA333,0x05,0b01011100);delay(10);
  myOLED.clrScr();
  myOLED.setFont(SmallFont);
  myOLED.print(F("Digital audio system"), CENTER, 10);
  myOLED.print(F("STA333BW"), CENTER, 30);
  myOLED.print(F("2.0 channel 40W"), CENTER, 50);
  myOLED.update();
  delay(2000);
  vol = EEPROM.read(0);treb = EEPROM.read(1);bass = EEPROM.read(2);
  bass_q = EEPROM.read(3)-100;ball = EEPROM.read(4)-100;demp = EEPROM.read(5);
  init_sta();
  Serial.println(wireRead(I2C_STA333,0x2D),BIN); 
}

void loop() {
/// IR ////////////////////////////////////////
  if ( irrecv.decode( &ir )) {Serial.print("0x");Serial.println( ir.value,HEX);irrecv.resume();times=millis();w=1;w2=1;}// IR приемник - чтение, в мониторе порта отображаются коды кнопок
  if(ir.value==0){gr1=0;gr2=0;}// запрет нажатий не активных кнопок пульта  

/////// BUTTON ////////////////////////////////////////////////////////////////////////////////////////////////////////
if(power==0){
/// menu
   if(digitalRead(10)==LOW||ir.value==IR_1){menu++;gr1=0;gr2=0;cl();delay(200);times=millis();w=1;w2=1;if(menu>4){menu=0;}}
   if(ir.value==IR_2){menu--;gr1=0;gr2=0;cl();delay(200);times=millis();w=1;w2=1;if(menu<0){menu=4;}}
/// mute
   if((digitalRead(A0)==LOW||ir.value==IR_5)&&mute==0){mute=1;w=1;menu=100;cl();wireWrite(I2C_STA333,0x06,0b00010110);
       myOLED.clrScr();myOLED.setFont(SmallFont);myOLED.print(F("MUTE"), CENTER, 25);myOLED.update();}
   if((digitalRead(A0)==LOW||ir.value==IR_5)&&mute==1){mute=0;w=1;menu=0;cl();wireWrite(I2C_STA333,0x06,0b00010000);} 
//// DEMP
   if(ir.value==IR_7&&demp==0){demp=1;w=1;cl();wireWrite(I2C_STA333,0x03,0b01000000|demp<<1);
       myOLED.clrScr();myOLED.setFont(SmallFont);myOLED.print(F("De-emphasis ON"), CENTER, 25);myOLED.update();delay(2000);menu=0;}
   if(ir.value==IR_7&&demp==1){demp=0;w=1;cl();wireWrite(I2C_STA333,0x03,0b01000000|demp<<1);
       myOLED.clrScr();myOLED.setFont(SmallFont);myOLED.print(F("De-emphasis OFF"), CENTER, 25);myOLED.update();delay(2000);menu=0;}       
   
   
}
 /// POWER ////////////////////////////////////
   if((digitalRead(A1)==LOW||ir.value==IR_6)&&power==0){power=1;menu=100;myOLED.setBrightness(1);cl();myEnc.write(0);
    myOLED.clrScr();myOLED.setFont(SmallFont);myOLED.print(F("POWER OFF"), CENTER, 10);myOLED.update();tim = millis();w3=1;
    wireWrite(I2C_STA333,0x05,0b01011100);delay(2000);cl();}
    
   if((digitalRead(A1)==LOW||ir.value==IR_6)&&power==1&&digitalRead(10)==HIGH){power=0;menu=0;myOLED.setBrightness(100);cl();myEnc.write(0);w=1;
    myOLED.clrScr();myOLED.setFont(SmallFont);myOLED.print(F("POWER ON"), CENTER, 10);myOLED.update();
    wireWrite(I2C_STA333,0x05,0b11011100);delay(2000);cl();}  
    /// standby output 
   if(power==1){digitalWrite(13,LOW);}else{digitalWrite(13,HIGH);}  
 
     
//////// VOLUME //////////////////////////////////////////////////////////////////////////////////////////////////////////////  
  if(menu==0){
   if(newPosition != oldPosition){oldPosition = newPosition;vol=vol-newPosition;myEnc.write(0);newPosition=0;times=millis();w=1;w2=1;vol_func();www=1;}
 
   if(ir.value==IR_4){vol++;gr1=1;gr2=0;cl_vol();times=millis();w=1;w2=1;vol_func();www=1;}// кнопка > 
   if(ir.value==0xFFFFFFFF and gr1==1){vol++;gr2=0;cl_vol();times=millis();w=1;w2=1;vol_func();www=1;}// кнопка >>>>>>
   if(ir.value==IR_3){vol--;gr1=0;gr2=1;cl_vol();times=millis();w=1;w2=1;vol_func();www=1;}// кнопка <
   if(ir.value==0xFFFFFFFF and gr2==1){vol--;gr1=0;cl_vol();times=millis();w=1;w2=1;vol_func();www=1;}// кнопка <<<<<<

  if(www==1){www=0;  
    wireWrite(I2C_STA333,0x08,vol+ball*2);
    wireWrite(I2C_STA333,0x09,vol-ball*2);}
  
  if(w==1){w=0;
  myOLED.clrScr();
  myOLED.setFont(SmallFont);myOLED.print(F("VOLUME"), LEFT, 0);myOLED.setFont(BigNumbers);myOLED.printNumI(255-vol, 75, 0);
  myOLED.setFont(SmallFont);if(demp==0){myOLED.print(F("DEMP_OFF"), LEFT, 20);}
                              else{myOLED.print(F("DEMP_ON"), LEFT, 20);}
  myOLED.drawLine(0, 30, 128, 30);
  myOLED.setFont(SmallFont);myOLED.print(F("TREBLE"), LEFT, 35);myOLED.printNumI((treb-7)*2, 75, 35);myOLED.print(F("dB"), RIGHT, 35);
  myOLED.setFont(SmallFont);myOLED.print(F("BASS"), LEFT, 45);myOLED.printNumI((bass-7)*2, 75, 45);myOLED.print(F("dB"), RIGHT, 45);
  myOLED.setFont(SmallFont);myOLED.print(F("F_BASS"), LEFT, 55);bass_q_f(55);
  myOLED.update();
  }}
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////  

//////// TREBLE //////////////////////////////////////////////////////////////////////////////////////////////////////////////  
  if(menu==1){
   if(newPosition != oldPosition){oldPosition = newPosition;treb=treb+newPosition;myEnc.write(0);newPosition=0;times=millis();w=1;w2=1;treb_func();www=1;}
 
   if(ir.value==IR_3){treb++;gr1=1;gr2=0;cl();times=millis();w=1;w2=1;treb_func();www=1;}// кнопка > 
   if(ir.value==0xFFFFFFFF and gr1==1){treb++;gr2=0;cl();times=millis();w=1;w2=1;treb_func();www=1;}// кнопка >>>>>>
   if(ir.value==IR_4){treb--;gr1=0;gr2=1;cl();times=millis();w=1;w2=1;treb_func();www=1;}// кнопка <
   if(ir.value==0xFFFFFFFF and gr2==1){treb--;gr1=0;cl();times=millis();w=1;w2=1;treb_func();www=1;}// кнопка <<<<<<

  if(www==1){www=0;wireWrite(I2C_STA333,0x11,0|bass|treb<<4);}
  
  if(w==1){w=0;
  myOLED.clrScr();
  myOLED.setFont(SmallFont);myOLED.print(F("TREBLE"), LEFT, 0);myOLED.setFont(BigNumbers);myOLED.printNumI((treb-7)*2, 75, 0);
  myOLED.setFont(SmallFont);myOLED.print(F("dB"), RIGHT, 20);
  myOLED.drawLine(0, 30, 128, 30);
  myOLED.setFont(SmallFont);myOLED.print(F("BASS"), LEFT, 35);myOLED.printNumI((bass-7)*2, 75, 35);myOLED.print(F("dB"), RIGHT, 35);
  myOLED.setFont(SmallFont);myOLED.print(F("F_BASS"), LEFT, 45);myOLED.printNumI(bass_q, 75, 45);bass_q_f(45);
  myOLED.setFont(SmallFont);myOLED.print(F("BALANCE"), LEFT, 55);myOLED.printNumI(ball, 75, 55);myOLED.print(F("dB"), RIGHT, 55);
  myOLED.update();
  }}
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////  

//////// BASS //////////////////////////////////////////////////////////////////////////////////////////////////////////////  
  if(menu==2){
   if(newPosition != oldPosition){oldPosition = newPosition;bass=bass+newPosition;myEnc.write(0);newPosition=0;times=millis();w=1;w2=1;bass_func();www=1;}
 
   if(ir.value==IR_3){bass++;gr1=1;gr2=0;cl();times=millis();w=1;w2=1;bass_func();www=1;}// кнопка > 
   if(ir.value==0xFFFFFFFF and gr1==1){bass++;gr2=0;cl();times=millis();w=1;w2=1;bass_func();www=1;}// кнопка >>>>>>
   if(ir.value==IR_4){bass--;gr1=0;gr2=1;cl();times=millis();w=1;w2=1;bass_func();www=1;}// кнопка <
   if(ir.value==0xFFFFFFFF and gr2==1){bass--;gr1=0;cl();times=millis();w=1;w2=1;bass_func();www=1;}// кнопка <<<<<<

  if(www==1){www=0;wireWrite(I2C_STA333,0x11,0|bass|treb<<4);}
  
  if(w==1){w=0;
  myOLED.clrScr();
  myOLED.setFont(SmallFont);myOLED.print(F("BASS"), LEFT, 0);myOLED.setFont(BigNumbers);myOLED.printNumI((bass-7)*2, 75, 0);
  myOLED.setFont(SmallFont);myOLED.print(F("dB"), RIGHT, 20);
  myOLED.drawLine(0, 30, 128, 30);
  myOLED.setFont(SmallFont);myOLED.print(F("F_BASS"), LEFT, 35);myOLED.printNumI(bass_q, 75, 35);bass_q_f(35);
  myOLED.setFont(SmallFont);myOLED.print(F("BALANCE"), LEFT, 45);myOLED.printNumI(ball, 75, 45);myOLED.print(F("dB"), RIGHT, 45);
  myOLED.setFont(SmallFont);myOLED.print(F("VOLUME"), LEFT, 55);myOLED.printNumI(255-vol, 75, 55);
  myOLED.update();
  }}
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////  

//////// BASS_F //////////////////////////////////////////////////////////////////////////////////////////////////////////////  
  if(menu==3){
   if(newPosition != oldPosition){oldPosition = newPosition;bass_q=bass_q+newPosition;myEnc.write(0);newPosition=0;times=millis();w=1;w2=1;bass_q_func();www=1;}
 
   if(ir.value==IR_3){bass_q++;gr1=1;gr2=0;cl();times=millis();w=1;w2=1;bass_q_func();www=1;}// кнопка > 
   if(ir.value==0xFFFFFFFF and gr1==1){bass_q++;gr2=0;cl();times=millis();w=1;w2=1;bass_q_func();www=1;}// кнопка >>>>>>
   if(ir.value==IR_4){bass_q--;gr1=0;gr2=1;cl();times=millis();w=1;w2=1;bass_q_func();www=1;}// кнопка <
   if(ir.value==0xFFFFFFFF and gr2==1){bass_q--;gr1=0;cl();times=millis();w=1;w2=1;bass_q_func();www=1;}// кнопка <<<<<<

  if(www==1){www=0;wireWrite(I2C_STA333,0x0C,0b00001000|bass_q<<4);}
  
  if(w==1){w=0;
  myOLED.clrScr();
  myOLED.setFont(SmallFont);myOLED.print(F("F_BASS"), LEFT, 0);myOLED.setFont(BigNumbers);myOLED.printNumI(60+bass_q*20, 65, 0);
  myOLED.setFont(SmallFont);myOLED.print(F("Hz"), RIGHT, 20);
  myOLED.drawLine(0, 30, 128, 30);
  myOLED.setFont(SmallFont);myOLED.print(F("BALANCE"), LEFT, 35);myOLED.printNumI(ball, 75, 35);myOLED.print(F("dB"), RIGHT, 35);
  myOLED.setFont(SmallFont);myOLED.print(F("VOLUME"), LEFT, 45);myOLED.printNumI(255-vol, 75, 45);
  myOLED.setFont(SmallFont);myOLED.print(F("TREBLE"), LEFT, 55);myOLED.printNumI((treb-7)*2, 75, 55);myOLED.print(F("dB"), RIGHT, 55);
  myOLED.update();
  }}
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////  

//////// BALANCE //////////////////////////////////////////////////////////////////////////////////////////////////////////////  
  if(menu==4){
  if (newPosition != oldPosition){oldPosition = newPosition;ball=ball+newPosition;myEnc.write(0);newPosition=0;times=millis();w=1;w2=1;ball_fun();www=1;}
 
  if(ir.value==IR_3){ball++;gr1=1;gr2=0;cl();times=millis();w=1;w2=1;ball_fun();www=1;}// кнопка > 
  if(ir.value==IR_4){ball--;gr1=0;gr2=1;cl();times=millis();w=1;w2=1;ball_fun();www=1;}// кнопка <

  if(www==1){www=0;  
    wireWrite(I2C_STA333,0x08,vol+ball*2);
    wireWrite(I2C_STA333,0x09,vol-ball*2);}
    
  if(w==1){w=0;
  myOLED.clrScr();
  myOLED.setFont(SmallFont);myOLED.print(F("BALANCE"), LEFT, 0);myOLED.setFont(BigNumbers);myOLED.printNumI(abs(ball), 75, 0);
  myOLED.setFont(SmallFont);myOLED.print(F("dB"), RIGHT, 0);
  if(ball<=0){myOLED.print(F("LCH"), 35, 20);}
  if(ball>=0){myOLED.print(F("RCH"), RIGHT, 20);}
  myOLED.drawLine(0, 30, 128, 30);
  myOLED.setFont(SmallFont);myOLED.print(F("VOLUME"), LEFT, 35);myOLED.printNumI(255-vol, 75, 35);
  myOLED.setFont(SmallFont);myOLED.print(F("TREBLE"), LEFT, 45);myOLED.printNumI((treb-7)*2, 75, 45);myOLED.print(F("dB"), RIGHT, 45);
  myOLED.setFont(SmallFont);myOLED.print(F("BASS"), LEFT, 55);myOLED.printNumI((bass-7)*2, 75, 55);myOLED.print(F("dB"), RIGHT, 55);
  myOLED.update();
  }}
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

if(power==1 && digitalRead(10)==LOW){tim = millis();w3=1;}
if(power==1 && digitalRead(A0)==LOW){tim = millis();w3=1;}
if(power==1 && millis()-tim >= 30000 && w3==1){w3=0;myOLED.clrScr();myOLED.update();}
/////////////////// ЧАСЫ ///////////////////////////////////////////////////////////////////
if(power==1 && millis()-tim < 30000){menu=100;
  DateTime = clock.getDateTime();hour = DateTime.hour;minut = DateTime.minute;secon = DateTime.second;   
     a[0]=hour/10;
     a[1]=hour%10;
     a[2]=minut/10;
     a[3]=minut%10;
     a[4]=secon/10;
     a[5]=secon%10;
  if(old_sec!=secon || digitalRead(10)==LOW){
  myOLED.clrScr();
  myOLED.setFont(BigNumbers);myOLED.printNumI(a[0], 15, 5);myOLED.printNumI(a[1], 30, 5);
  myOLED.setFont(SmallFont);myOLED.print(F(":"), 45, 15);
  myOLED.setFont(BigNumbers);myOLED.printNumI(a[2], 50, 5);myOLED.printNumI(a[3], 65, 5);
  myOLED.setFont(SmallFont);myOLED.print(F(":"), 80, 15);
  myOLED.setFont(BigNumbers);myOLED.printNumI(a[4], 85, 5);myOLED.printNumI(a[5], 100, 5);
  myOLED.update();
  } 
  old_sec=secon;
//// set time ////
  if(digitalRead(10)==LOW&&digitalRead(A0)==LOW){hour++;if(hour>23){hour=0;} clock.setDateTime(2022, 7, 15, hour, minut, secon);tim = millis();delay(100);}//  MUTE HH++
  if(digitalRead(10)==LOW&&digitalRead(A1)==LOW){minut++;if(minut>59){minut=0;} clock.setDateTime(2022, 7, 15, hour, minut, secon);tim = millis();delay(100);}// POWER MM++
  if(digitalRead(10)==LOW&&newPosition != oldPosition){oldPosition = newPosition;myEnc.write(0);newPosition=0;clock.setDateTime(2022, 7, 15, hour, minut, 0);tim = millis();} // encoder +/- clear sec
}
   
////////////////// EEPROM //////////////////////////////////////////////////////////////
 if(millis()-times>10000 && w2==1 && mute==0 && power==0){
     EEPROM.update(0,vol);EEPROM.update(1,treb);EEPROM.update(2,bass);
     EEPROM.update(3,bass_q+100);EEPROM.update(4,ball+100);
     EEPROM.update(5,demp);
     cl();menu=0;w2=0;w=1;} 
  
  }

void ball_fun(){if(ball>4){ball=4;}if(ball<-4){ball=-4;}}
void bass_q_func(){if(bass_q>15){bass_q=15;}if(bass_q<1){bass_q=1;}}
void bass_func(){if(bass<1){bass=1;}if(bass>13){bass=13;}}  
void treb_func(){if(treb<1){treb=1;}if(treb>13){treb=13;}}
void vol_func(){if(vol<8){vol=8;}if(vol>246){vol=246;}}
void to_Timer(){newPosition = myEnc.read()/4;} 
void cl(){myOLED.clrScr();ir.value=0;delay(300);}
void cl_vol(){myOLED.clrScr();ir.value=0;delay(100);}

void bass_q_f(byte pp){
   switch(bass_q){
    case 1:myOLED.print(F("80     Hz"), RIGHT, pp);break;
    case 2:myOLED.print(F("100    Hz"), RIGHT, pp);break;
    case 3:myOLED.print(F("120    Hz"), RIGHT, pp);break;
    case 4:myOLED.print(F("140    Hz"), RIGHT, pp);break;
    case 5:myOLED.print(F("160    Hz"), RIGHT, pp);break;
    case 6:myOLED.print(F("180    Hz"), RIGHT, pp);break;
    case 7:myOLED.print(F("200    Hz"), RIGHT, pp);break;
    case 8:myOLED.print(F("220    Hz"), RIGHT, pp);break;
    case 9:myOLED.print(F("240    Hz"), RIGHT, pp);break;
    case 10:myOLED.print(F("260    Hz"), RIGHT, pp);break;
    case 11:myOLED.print(F("280    Hz"), RIGHT, pp);break;
    case 12:myOLED.print(F("300    Hz"), RIGHT, pp);break;
    case 13:myOLED.print(F("320    Hz"), RIGHT, pp);break;
    case 14:myOLED.print(F("340    Hz"), RIGHT, pp);break;
    case 15:myOLED.print(F("360    Hz"), RIGHT, pp);break;
    }
  }

void init_sta(){
  wireWrite(I2C_STA333,0x00,0b01101011);
  //[2:0][MCS2 MCS1 MCS0]=011
  //[4:3][IR1 IR0]=01(96K)
  //[5][TWRB]=1(TEMP_ERR АВТОВКЛЮЧ.ПОСЛЕ ПЕРЕГРЕВА-АКТИВНА)
  //[6][TWAB]=0(ОГРАНИЧ ВЫХ МОЩНОСТИ ПРИ ПЕРЕГРЕВЕ-АКТИВНА)0X37 - УКАЗАТЬ УРОВ. ОГР. МОЩН.
  //[7][FDRB]=0(ЗАЩИТА.ОТКЛ.ПИТАНИЯ ПРИ НЕИСПРАВНОСТИ-АКТИВНА)
  wireWrite(I2C_STA333,0x01,0b10100000); 
  //[3:0][SAI]=0000(I2S 64*fs 16 to 24 bit) 
  //[4][SAIFB]=0(MSB) MSB/LSB-first
  //[5][DSCKE]=1(АКТИВНА ТАКТОВАЯ ЗАДЕРЖКА)
  //[7:6][C1IM C2IM]=10(СОПАСТОНОВЛЕНИЕ КАНАЛОВ)DEF
  wireWrite(I2C_STA333,0x02,0b10011110);
  //[1:0][OM0 OM1]=10( FFX power output mode)DEF
  //[5:2][CSZ]=0111(FFX compensating pulse size register)DEF
  //[6][RESERVED]
  //[7][OCRB]=1(ЗАЩИТА ПО ТОКУ-АКТИВНА)
  wireWrite(I2C_STA333,0x03,0b01000000|demp<<1);
  //[0][HPB]=0(ФИЛЬТР HPB АКТИВЕН)DEF ОПАСНО ВЫКЛЮЧАТЬ!!! 
  //[1][DEMP]=0(De-emphasis)OFF
  //[2][DSPB]=0(DSP bypass)АКТИВНА-РЕГ.ТЕМБРА АКТИВНЫ
  //[3][PSL]=0(Postscale link)DEF
  //[4][BQL]=0(Biquad coefficient link)DEF
  //[5][DCR]=0(Dynamic range compression)DEF
  //[6][ZDE]=1(Zero-detect mute enable)DEF
  //[7][SME]=0(Submix mode enable)DEF  
  wireWrite(I2C_STA333,0x04,0b11000010);//def
  //[0][MPCV]=0(Max power correction variable)DEF
  //[1][MPC]=1(Max power correction)DEF
  //[2][NSBW]=0(Noise-shaper bandwidth selection)DEF
  //[3][AME]=0(AM mode enable)DEF
  //[4][PWMS]=1(PWM speed mode)DEF
  //[5][DCCV]=0(Distortion compensation variable enable)DEF
  //[6][ZCE]=1(Zero-crossing volume enable)DEF
  //[7][SVE]=1(Soft volume update enable)DEF
  wireWrite(I2C_STA333,0x05,0b11011100);
  //[1:0]RESERVED
  //[2][IDE]=1(Invalid input detect mute enable)DEF
  //[3][BCLE]=1(Binary output mode clock loss detection)DEF
  //[4][LDTE]=1(LRCK double trigger protection)DEF
  //[5][ECLE]=0(Auto EAPD on clock loss)DEF
  //[6][PWDN]=1(IC power down)DEF
  //[7][EAPD]=1(ВНЕШНЕЕ ПИТАНИЕ УСИЛИТЕЛЯ)АКТИВНО
  wireWrite(I2C_STA333,0x06,0b00010000);// DEF
  //Mute/line output configuration register
  wireWrite(I2C_STA333,0x07,0);// 0 dB
  //Master volume register BYTE 0...0xFE = 0 dB...-127,5 | 0xFF = MUTE
   wireWrite(I2C_STA333,0x08,vol+ball*2);
  //Channel 1 volume BYTE 0...0xEC = +48...-80 dB 0xFF = MUTE
  wireWrite(I2C_STA333,0x09,vol-ball*2);
  //Channel 2 volume BYTE 0...0xEC = +48...-80 dB 0xFF = MUTE 
  wireWrite(I2C_STA333,0x0A,255);
  wireWrite(I2C_STA333,0x0B,0b10000000);//DEF
  //[4:5][AMGC](Audio preset register 1)
  //Audio preset gain compression/limiters selection
  wireWrite(I2C_STA333,0x0C,0b00001000|bass_q<<4);
  //[0][amame]
  //[3:1][AMAM]=000(AM interference frequency switching)DEF
  //[7:4][XO]=0000(Кроссовер для управления басами)byte 0000...0001...1111 = DEF...80Hz...360Hz
  
  wireWrite(I2C_STA333,0x0E,0b00000000);
  //[0][TCB]=0(Tone control bypass)DEF
  //[1][EQBP]=0(EQ bypass)DEF
  //[2][VBP]=0(Volume bypass)DEF
  //[3][BO]=0(Binary output enable)DEF
  //[5:4][LS]=00(Channel limiter mapping as a function of CxLS bits)DEF
  //[7:6][OM]=00(Channel output mapping as a function of CxOM bits)DEF
  wireWrite(I2C_STA333,0x0F,0b01000000);
  //[0][TCB]=0(Tone control bypass)DEF
  //[1][EQBP]=0(EQ bypass)DEF
  //[2][VBP]=0(Volume bypass)DEF
  //[3][BO]=0(Binary output enable)DEF
  //[5:4][LS]=00(Channel limiter mapping as a function of CxLS bits)DEF
  //[7:6][OM]=00(Channel output mapping as a function of CxOM bits)DEF
  wireWrite(I2C_STA333,0x10,0b10000000);
  //[1:0]RESERVED
  //[2][VBP]=0(Volume bypass)DEF
  //[3][BO]=0(Binary output enable)DEF
  //[5:4][LS]=00(Channel limiter mapping as a function of CxLS bits)DEF
  //[7:6][OM]=00(Channel output mapping as a function of CxOM bits)DEF
  wireWrite(I2C_STA333,0x11,0|bass|treb<<4);// тембр ВЧ НЧ 
  
  wireWrite(I2C_STA333,0x12,0b01101010);
  //(Limiter 1 attack/release rate)DEF
  wireWrite(I2C_STA333,0x13,0b01101001);
  //(Limiter 1 attack/release threshold )DEF
  wireWrite(I2C_STA333,0x14,0b01101010);
  //(Limiter 2 attack/release rate)DEF
  wireWrite(I2C_STA333,0x15,0b01101001);
  //(Limiter 2 attack/release threshold)DEF
  wireWrite(I2C_STA333,0x16,255);
  //(Coefficient address register)DEF
  wireWrite(I2C_STA333,0x17,255);
  wireWrite(I2C_STA333,0x18,255);
  wireWrite(I2C_STA333,0x19,255);
  
  wireWrite(I2C_STA333,0x1A,255);
  wireWrite(I2C_STA333,0x1B,255);
  wireWrite(I2C_STA333,0x1C,255);
  //(Coefficient b2 data register bits)DEF
  wireWrite(I2C_STA333,0x1D,255);
  wireWrite(I2C_STA333,0x1E,255);
  wireWrite(I2C_STA333,0x1F,255);
  //(Coefficient a1 data register bits)DEF
  wireWrite(I2C_STA333,0x20,255);
  wireWrite(I2C_STA333,0x21,255);
  wireWrite(I2C_STA333,0x22,255);
  //(Coefficient a2 data register bits)DEF
  wireWrite(I2C_STA333,0x23,255);
  wireWrite(I2C_STA333,0x24,255);
  wireWrite(I2C_STA333,0x25,255);
  //(Coefficient b0 data register bits)DEF 
  wireWrite(I2C_STA333,0x26,255);
    
  }  

byte wireRead(byte addr, byte reg){ // I2C
  Wire.beginTransmission(addr);
  Wire.write (reg);
  Wire.endTransmission();
  Wire.requestFrom(addr,1);
  while(Wire.available()<1);
  byte value = Wire.read();
  return value;
  }  
 
void wireWrite(byte addr, byte reg, byte data){
  Wire.beginTransmission(addr);
  Wire.write (reg);
  Wire.write (data);
  Wire.endTransmission();
  }   

4

Re: STA333BW

Проект завершен.