1

Тема: BD3491FS

Sound Processor with Built-in Surround Sound Function

General Description
Built in stereo 6 input selectors and volume that there is
not an impedance change of a volume terminal. And this
is sound processor can realize 2-band equalizer
(Bass/Treble, Gain±14dB / 2dB_step) and BassBoost,
Output gain, Surround by external components.

Features
 Equipped with 6 single ended stereo input
selectors
 Built-in input gain controller suitable for mobile audio.
 Volume input terminal can be used as a microphone
input terminal since its impedance remains constant
even if volume setting is changed.
 Bi-CMOS process is suitable for the design of low
current and low energy. It also provides more quality
for Bi-CMOS small scale regulator and heat in a set.
 The package of this IC is SSOP-A32. Sound input
terminals and output terminals arrangement is
optimized for easy and fast layout of PCB pattern. At
the same time, it minimizes PCB area.

Applications
 Suitable for mini-components or micro components.
Used for audio equipment of TV, DVD, etc.

Key Specification
 Current upon no signal: 7mA(typ)
 Total Harmonic Distortion: 0.002%(typ)
 Maximum Input Voltage: 2.4Vrms(typ)
 Crosstalk between Selectors: 100dB(typ)
 Volume Control Range: 0dB to -87dB
 Output Noise Voltage: 5µVrms(typ)
 Residual Output Noise Voltage: 5µVrms(typ)
 Operating Temperature Range: -40℃ to +85℃

Данный контент доступен только зарегистрированным пользователям.

http://forum.rcl-radio.ru/uploads/images/2019/11/66d0cebfd780026eb9dce79659c77725.png

https://github.com/liman324/BD3491FS.git

2

Re: BD3491FS

https://github.com/liman324/BD3491FS.git

BD3491FS.h

// ALEXSANDER LIMAN
// liman324@yandex.ru
// rcl-radio.ru
// 08.11.2019

#ifndef BD3491FS_H
#define BD3491FS_H

#define BD3491FS_address 0b1000001 

#define INPUT_SELECT        0x04
#define INPUT_GAIN          0x06
#define VOLUME_GAIN_1       0x21
#define VOLUME_GAIN_2       0x22
#define BASS_GAIN           0x51
#define TREBLE_GAIN         0x57
#define SURROUND            0x78

#include <Arduino.h>
class BD3491FS
{
  public:
    BD3491FS();
    void setSelect(int in);// int 0...7 === A B C D E F INPUT_SHORT INPUT_MUTE
    void setIn_gain(int in_gain); // int 0...7 === 0...20 dB    
    void setVol_1(int vol_1); // int 0...87 === 0...-87 dB
    void setVol_2(int vol_2); // int 0...87 === 0...-87 dB
    void setBass(int bass); // int -7...0...+7 === -7...+7 dB
    void setTreb(int treb); // int -7...0...+7 === -7...+7 dB
    void setSurround(int sur); // int 0...3 === OFF LOW MIDDLE HIGH
    
  private:
    void writeWire(char a, char b);
};
    
#endif //BD3491FS_H

BD3491FS.cpp

#include <Arduino.h>
#include <Wire.h>
#include "BD3491FS.h"

BD3491FS::BD3491FS(){
    Wire.begin();
}

void BD3491FS::setSelect(int in){
     writeWire(INPUT_SELECT, in); 
}

void BD3491FS::setIn_gain(int in_gain){
     switch(in_gain){
       case 0: in_gain = 0b00000000;break;
       case 1: in_gain = 0b00000010;break;
       case 2: in_gain = 0b00000100;break;
       case 3: in_gain = 0b00000110;break;
       case 4: in_gain = 0b00001000;break;
       case 5: in_gain = 0b00001100;break;
       case 6: in_gain = 0b00010000;break;
       case 7: in_gain = 0b00010100;break;
}
     writeWire(INPUT_GAIN, in_gain); 
}

void BD3491FS::setVol_1(int vol_1){
     writeWire(VOLUME_GAIN_1, vol_1 + 0b10000000); 
}

void BD3491FS::setVol_2(int vol_2){
     writeWire(VOLUME_GAIN_2, vol_2 + 0b10000000); 
}

void BD3491FS::setBass(int bass){
     switch(bass){
       case 0: bass = 0b00000000;break;
       case 1: bass = 0b00000010;break;
       case 2: bass = 0b00000100;break;
       case 3: bass = 0b00000110;break;
       case 4: bass = 0b00001000;break;
       case 5: bass = 0b00001010;break;
       case 6: bass = 0b00001100;break;
       case 7: bass = 0b00001110;break;
       case -1: bass = 0b10000010;break;
       case -2: bass = 0b10000100;break;
       case -3: bass = 0b10000110;break;
       case -4: bass = 0b10001000;break;
       case -5: bass = 0b10001010;break;
       case -6: bass = 0b10001100;break;
       case -7: bass = 0b10001110;break;
}
     writeWire(BASS_GAIN, bass); 
}

void BD3491FS::setTreb(int treb){
     switch(treb){
       case 0: treb = 0b00000000;break;
       case 1: treb = 0b00000010;break;
       case 2: treb = 0b00000100;break;
       case 3: treb = 0b00000110;break;
       case 4: treb = 0b00001000;break;
       case 5: treb = 0b00001010;break;
       case 6: treb = 0b00001100;break;
       case 7: treb = 0b00001110;break;
       case -1: treb = 0b10000010;break;
       case -2: treb = 0b10000100;break;
       case -3: treb = 0b10000110;break;
       case -4: treb = 0b10001000;break;
       case -5: treb = 0b10001010;break;
       case -6: treb = 0b10001100;break;
       case -7: treb = 0b10001110;break;
}
     writeWire(TREBLE_GAIN, treb); 
}

void BD3491FS::setSurround(int sur){
     switch(sur){
       case 0: sur = 0b10000000;break;
       case 1: sur = 0b10000101;break;
       case 2: sur = 0b10001010;break;
       case 3: sur = 0b10001111;break;
}
     writeWire(SURROUND, sur); 
}

void BD3491FS::writeWire(char a, char b){
  Wire.beginTransmission(BD3491FS_address);
  Wire.write (a);
  Wire.write (b);
  Wire.endTransmission();
}

BD3491.ino

#include <Wire.h> 
#include <BD3491FS.h>
BD3491FS bd; 

void setup(){
   Wire.begin();
   audio();
}

void loop(){}

void audio(){
    bd.setSelect(0);// int 0...7 === A B C D E F INPUT_SHORT INPUT_MUTE
    bd.setIn_gain(0); // int 0...7 === 0...20 dB    
    bd.setVol_1(0); // int 0...87 === 0...-87 dB
    bd.setVol_2(0); // int 0...87 === 0...-87 dB
    bd.setBass(0); // int -7...0...+7 === -7...+7 dB
    bd.setTreb(0); // int -7...0...+7 === -7...+7 dB
    bd.setSurround(1); // int 0...3 === OFF LOW MIDDLE HIGH
  }

3

Re: BD3491FS

http://forum.rcl-radio.ru/uploads/images/2020/01/12e7e9eb8996adfde8ce2db86449cc6d.png
http://forum.rcl-radio.ru/uploads/images/2020/01/d3f8fbafae476133b37ffd4d9f29b926.png
http://forum.rcl-radio.ru/uploads/images/2020/01/ab06e5993010bbe28ee370fc34e2ae92.png
http://forum.rcl-radio.ru/uploads/images/2020/01/9cd2d4ef49a79e62c6a0d5b6a89cf71f.png
http://forum.rcl-radio.ru/uploads/images/2020/01/0914720229ba0c41fd12d4af4ce26a2a.png


#define IR_1 0x2FDD02F // Кнопка вверх
#define IR_2 0x2FD32CD // Кнопка вниз
#define IR_3 0x2FD906F // Кнопка >
#define IR_4 0x2FDF20D // Кнопка <
#define IR_5 0x2FD708F // Кнопка IN

#include <Wire.h> 
#include <LiquidCrystal_I2C.h>
#include <BD3491FS.h>
#include <Encoder.h>
#include <EEPROM.h>
#include <MsTimer2.h>
#include <boarddefs.h>
#include <IRremote.h>
  BD3491FS bd; 
  LiquidCrystal_I2C lcd(0x27,16,2);  // Устанавливаем дисплей
  IRrecv irrecv(12); // указываем вывод модуля IR приемника
  Encoder myEnc(8, 9);//  CLK, DT
  decode_results ir; 
   byte a1[8] = {0b00000,0b10101,0b10101,0b10101,0b10101,0b10101,0b10101,0b00000};
   byte a2[8] = {0b00000,0b10100,0b10100,0b10100,0b10100,0b10100,0b10100,0b00000};
   byte a3[8] = {0b00000,0b10000,0b10000,0b10000,0b10000,0b10000,0b10000,0b00000};  
   unsigned long time,oldPosition  = -999,newPosition; 
   int menu,w,w2,vol,vol_d,gr1,gr2,z,z0,z1,treb,treb_d,bass,bass_d,in,www,gain1,gain2,gain3,gain4,gain5,gain6,gain0,gain_d,sur; 

void setup(){
  irrecv.enableIRIn();lcd.init();lcd.backlight();
  lcd.setCursor(0,0);lcd.print("    BD3491FS    ");delay(2000);cl();
  Serial.begin(9600); lcd.createChar(0,a1);lcd.createChar(1,a2);lcd.createChar(2,a3);
  pinMode(10,INPUT);  // МЕНЮ КНОПКА SW энкодера
  MsTimer2::set(3, to_Timer);MsTimer2::start();
  if(EEPROM.read(100)!=0){for(int i=0;i<101;i++){EEPROM.update(i,0);}}// очистка памяти при первом включении 
   vol = EEPROM.read(0)-87;treb = EEPROM.read(1)-7;bass = EEPROM.read(2)-7;
   in = EEPROM.read(3);sur = EEPROM.read(10);
   gain1 = EEPROM.read(4);gain2 = EEPROM.read(5);gain3 = EEPROM.read(6);
   gain4 = EEPROM.read(7);gain5 = EEPROM.read(8);gain6 = EEPROM.read(9);
   audio();
}

void loop(){
  if(digitalRead(10)==LOW){menu++;cl();time=millis();w=1;w2=1;if(menu>4){menu=0;}}// меню
  if(digitalRead(2)==HIGH){in++;;cl();time=millis();w=1;w2=1;www=1;if(in>5){in=0;};lcd.setCursor(0,0);lcd.print("    INPUT ");lcd.print(in+1);audio();delay(2000);}// КНОПКА ВЫБОРА ВХОДА I

 ////////////////////// IR /////////////////////////////////////////////////
  if ( irrecv.decode( &ir )) {Serial.print("0x");Serial.println( ir.value,HEX);irrecv.resume();time=millis();w=1;}// IR приемник - чтение, в мониторе порта отображаются коды кнопок
  if(ir.value==0){gr1=0;gr2=0;}// запрет нажатий не активных кнопок пульта
  if(ir.value==IR_1){menu++;gr1=0;gr2=0;cl();time=millis();w=1;w2=1;if(menu>4){menu=0;}}// меню кнопка вверх 
  if(ir.value==IR_2){menu--;gr1=0;gr2=0;cl();time=millis();w=1;w2=1;if(menu<0){menu=4;}}// меню кнопка вниз
  if(ir.value==IR_5){in++;gr1=0;gr2=0;cl();time=millis();w=1;w2=1;www=1;if(in>5){in=0;};lcd.setCursor(0,0);lcd.print("    INPUT ");lcd.print(in+1);audio();delay(2000);}// КНОПКА ВЫБОРА ВХОДА IN

/////////////////////////////// VOLUME -87 ... +0 дБ | step 1 dB////////////////////////////////////////////////
 if(menu==0){
     if(ir.value==IR_3){vol++;gr1=1;gr2=0;cl1();w2=1;vol_func();audio();}// кнопка > 
     if(ir.value==0xFFFFFFFF and gr1==1){vol++;gr2=0;cl1();w2=1;vol_func();audio();}// кнопка >>>>>>
     if(ir.value==IR_4){vol--;gr1=0;gr2=1;cl1();w2=1;vol_func();audio();}// кнопка <
     if(ir.value==0xFFFFFFFF and gr2==1){vol--;gr1=0;cl1();w2=1;vol_func();audio();}// кнопка <<<<<<
   
   if (newPosition != oldPosition){oldPosition = newPosition;
     vol=vol+newPosition;myEnc.write(0);newPosition=0;time=millis();w=1;w2=1;vol_func();audio();} 
     lcd.setCursor(0,0);lcd.print("VOLUME  ");
     lcd.print(" ");lcd.print(vol);lcd.print(" ");lcd.setCursor(13,0);lcd.print("dB");vol_d=vol+48;
   if(w2==1){
   for(z=0,z0=0,z1=0;z<=vol_d;z++,z1++){if(z1>2){z1=0;z0++;}
   if(z1==1){lcd.setCursor(z0,1);lcd.write((uint8_t)0);lcd.setCursor(z0+1,1);lcd.print("   ");}}
   if(z1==3){lcd.setCursor(z0,1);lcd.write((uint8_t)1);}
   if(z1==2){lcd.setCursor(z0,1);lcd.write((uint8_t)2);}w2=0;}}  

///////////////////////// TREBLE +/-14 dB | step 2 dB/////////////////////////////////////////////////////////
   if(menu==1){
     if(ir.value==IR_3){treb++;gr1=1;gr2=0;cl1();w2=1;treb_func();audio();}// кнопка > 
     if(ir.value==0xFFFFFFFF and gr1==1){treb++;gr2=0;cl1();w2=1;treb_func();audio();}// кнопка >>>>>>
     if(ir.value==IR_4){treb--;gr1=0;gr2=1;cl1();w2=1;treb_func();audio();}// кнопка < 
     if(ir.value==0xFFFFFFFF and gr2==1){treb--;gr1=0;cl1();w2=1;treb_func();audio();}// кнопка <<<<<<
    
     if (newPosition != oldPosition) {
    oldPosition = newPosition;
    treb=treb+newPosition;myEnc.write(0);newPosition=0;time=millis();w=1;w2=1;treb_func();audio();} 
   lcd.setCursor(0,0);lcd.print("TREBLE  ");
   lcd.print(" ");lcd.print(treb*2);lcd.print(" ");lcd.setCursor(13,0);lcd.print("dB");treb_d=treb*2+14;
   if(w2==1){
   for(z=0,z0=0,z1=0;z<=treb_d;z++,z1++){if(z1>2){z1=0;z0++;}
   if(z1==1){lcd.setCursor(z0+3,1);lcd.write((uint8_t)0);lcd.setCursor(z0+1+3,1);lcd.print("   ");}}
   if(z1==3){lcd.setCursor(z0+3,1);lcd.write((uint8_t)1);}
   if(z1==2){lcd.setCursor(z0+3,1);lcd.write((uint8_t)2);}w2=0;}}   
  
/////////////////////// BASS +/-14 dB | step 2 dB///////////////////////////////////////////////////////////
   if(menu==2){
     if(ir.value==IR_3){bass++;gr1=1;gr2=0;cl1();w2=1;bass_func();audio();}// кнопка > 
     if(ir.value==0xFFFFFFFF and gr1==1){bass++;gr2=0;cl1();w2=1;bass_func();audio();}// кнопка >>>>>>
     if(ir.value==IR_4){bass--;gr1=0;gr2=1;cl1();w2=1;bass_func();audio();}// кнопка < 
     if(ir.value==0xFFFFFFFF and gr2==1){bass--;gr1=0;cl1();w2=1;bass_func();audio();}// кнопка <<<<<<  
    
    if (newPosition != oldPosition) {
    oldPosition = newPosition;
    bass=bass+newPosition;myEnc.write(0);newPosition=0;time=millis();w=1;w2=1;bass_func();audio();} 
   lcd.setCursor(0,0);lcd.print("BASS    ");
   lcd.print(" ");lcd.print(bass*2);lcd.print(" ");lcd.setCursor(13,0);lcd.print("dB");bass_d=bass*2+14;
   if(w2==1){
   for(z=0,z0=0,z1=0;z<=bass_d;z++,z1++){if(z1>2){z1=0;z0++;}
   if(z1==1){lcd.setCursor(z0+3,1);lcd.write((uint8_t)0);lcd.setCursor(z0+1+3,1);lcd.print("   ");}}
   if(z1==3){lcd.setCursor(z0+3,1);lcd.write((uint8_t)1);}
   if(z1==2){lcd.setCursor(z0+3,1);lcd.write((uint8_t)2);}w2=0;}} 

   //////////////// IN + GAIN /////////////////////////////////////////////////////////////
   if(menu==3){ 
       switch(in){
     case 0: gain0 = gain1;break;
     case 1: gain0 = gain2;break;
     case 2: gain0 = gain3;break;
     case 3: gain0 = gain4;break;
     case 4: gain0 = gain5;break;
     case 5: gain0 = gain6;break;
     }
     if(ir.value==IR_3){gain0++;gr1=1;gr2=0;cl1();w2=1;gain_func();audio();}// кнопка > 
     if(ir.value==0xFFFFFFFF and gr1==1){gain0++;gr2=0;cl1();w2=1;gain_func();audio();}// кнопка >>>>>>
     if(ir.value==IR_4){gain0--;gr1=0;gr2=1;cl1();w2=1;gain_func();audio();}// кнопка < 
     if(ir.value==0xFFFFFFFF and gr2==1){gain0--;gr1=0;cl1();w2=1;gain_func();audio();}// кнопка <<<<<<

    if (newPosition != oldPosition) {
    oldPosition = newPosition;
    gain0=gain0+newPosition;myEnc.write(0);newPosition=0;time=millis();w=1;w2=1;gain_func();audio();} 
   switch(in){
     case 0: gain1 = gain0;break;
     case 1: gain2 = gain0;break;
     case 2: gain3 = gain0;break;
     case 3: gain4 = gain0;break;
     case 4: gain5 = gain0;break;
     case 5: gain6 = gain0;break;
     } 
    if(www==1){audio();www=0;}
  lcd.setCursor(0,0);lcd.print("Gain IN ");lcd.print(in+1);
      lcd.setCursor(10,0);lcd.print(" ");lcd.print(gain0*2);lcd.print(" ");lcd.setCursor(14,0);lcd.print("dB");gain_d=gain0*2;
   if(w2==1){
   for(z=0,z0=0,z1=0;z<=gain_d;z++,z1++){if(z1>2){z1=0;z0++;}
   if(z1==1){lcd.setCursor(z0+6,1);lcd.write((uint8_t)0);lcd.setCursor(z0+1+6,1);lcd.print("   ");}}
   if(z1==3){lcd.setCursor(z0+6,1);lcd.write((uint8_t)1);}
   if(z1==2){lcd.setCursor(z0+6,1);lcd.write((uint8_t)2);}}w2=0;}

  ////////////////////////////// Surround ////////////////////////////////////////////////////
 if(menu==4){  
     if(ir.value==IR_3){sur++;gr1=1;gr2=0;cl1();w2=1;sur_func();audio();}// кнопка > 
     if(ir.value==0xFFFFFFFF and gr1==1){sur++;gr2=0;cl1();w2=1;sur_func();audio();}// кнопка >>>>>>
     if(ir.value==IR_4){sur--;gr1=0;gr2=1;cl1();w2=1;sur_func();audio();}// кнопка < 
     if(ir.value==0xFFFFFFFF and gr2==1){sur--;gr1=0;cl1();w2=1;sur_func();audio();}// кнопка <<<<<< 
  
    if (newPosition != oldPosition) {
    oldPosition = newPosition;
    sur=sur+newPosition;myEnc.write(0);newPosition=0;time=millis();w=1;w2=1;sur_func();audio();} 

    lcd.setCursor(0,0);lcd.print("Surround Gain");
    lcd.setCursor(0,1);
      switch(sur){
         case 0: lcd.print("OFF   ");break;
         case 1: lcd.print("LOW   ");break;
         case 2: lcd.print("MIDDLE");break;
         case 3: lcd.print("HIGH  ");break;}}  
  


 ///////////////////// EEPROM ///////////////////////////////////////////////////////////////         
  if(millis()-time>10000 && w==1){
     EEPROM.update(0,vol+87);EEPROM.update(1,treb+7);EEPROM.update(2,bass+7);
     EEPROM.update(3,in);EEPROM.update(10,sur);
     EEPROM.update(4,gain1);EEPROM.update(5,gain2);EEPROM.update(6,gain3);
     EEPROM.update(7,gain4);EEPROM.update(8,gain5);EEPROM.update(9,gain6);
     menu=0;w=0;w2=1;cl();}
  
  }//loop

void sur_func(){if(sur>3){sur=0;}if(sur<0){sur=3;}}
void gain_func(){if(gain0<0){gain0=0;}if(gain0>7){gain0=7;}}
void bass_func(){if(bass>7){bass=7;}if(bass<-7){bass=-7;}} 
void treb_func(){if(treb>7){treb=7;}if(treb<-7){treb=-7;}}
void vol_func(){if(vol<-87){vol=-87;}if(vol>0){vol=0;}}
void cl(){ir.value=0;delay(300);lcd.clear();}
void cl1(){ir.value=0;delay(100);}
void to_Timer(){newPosition = myEnc.read()/4;}  

void audio(){
    bd.setSelect(in);// int 0...7 === A B C D E F INPUT_SHORT INPUT_MUTE
    bd.setIn_gain(gain0); // int 0...7 === 0...14 dB    
    bd.setVol_1(abs(vol)); // int 0...87 === 0...-87 dB
    bd.setVol_2(abs(vol)); // int 0...87 === 0...-87 dB
    bd.setBass(bass); // int -7...0...+7 === -7...+7 dB
    bd.setTreb(treb); // int -7...0...+7 === -7...+7 dB
    bd.setSurround(sur); // int 0...3 === OFF LOW MIDDLE HIGH
  }

4

Re: BD3491FS

http://forum.rcl-radio.ru/uploads/images/2020/01/3059aa0a19c4420ae9f4d03c5d54fad3.png
http://forum.rcl-radio.ru/uploads/images/2020/01/456d1f1b7d191600f69f763d675d5a54.png
http://forum.rcl-radio.ru/uploads/images/2020/01/5ffd136e889d36cf2d63cb4937cf97c8.png


#define IR_1 0x2FDD02F // Кнопка вверх
#define IR_2 0x2FD32CD // Кнопка вниз
#define IR_3 0x2FD906F // Кнопка >
#define IR_4 0x2FDF20D // Кнопка <
#define IR_5 0x2FD708F // Кнопка IN

#include <Wire.h> 
#include <LiquidCrystal_I2C.h>
#include <BD3491FS.h>
#include <Encoder.h>
#include <EEPROM.h>
#include <MsTimer2.h>
#include <boarddefs.h>
#include <IRremote.h>
  BD3491FS bd; 
  LiquidCrystal_I2C lcd(0x27,16,2);  // Устанавливаем дисплей
  IRrecv irrecv(12); // указываем вывод модуля IR приемника
  Encoder myEnc(8, 9);//  CLK, DT
  decode_results ir; 
      byte v1[8] = {31,31,31,31,31,31,31,31};
      byte v2[8] = {31,31,31, 0, 0, 0, 0, 0};      
      byte v3[8] = { 0, 0, 0, 0, 0,31,31,31};
      byte v4[8] = {31,31, 0, 0, 0, 0,31,31};
      byte v5[8] = { 0, 0, 0, 0, 0, 0, 0, 0};
      byte v7[8] = { 0, 0, 0, 0, 0, 0,31,31};
   unsigned long time,oldPosition  = -999,newPosition; 
   int menu,w,w2,vol,vol_d,gr1,gr2,z,z0,z1,treb,treb_d,bass,bass_d,in,www,gain1,gain2,gain3,gain4,gain5,gain6,gain0,gain_d,sur; 
    byte a[2];
    byte i,d1,d2,d3,d4,d5,d6,e1,e2,e3;

void setup(){
  irrecv.enableIRIn();lcd.init();lcd.backlight();
  lcd.setCursor(0,0);lcd.print("    BD3491FS    ");delay(2000);cl();
  Serial.begin(9600); lcd.createChar(1, v1);lcd.createChar(2, v2);lcd.createChar(3, v3);lcd.createChar(4, v4);lcd.createChar(5, v5);lcd.createChar(7, v7);
  pinMode(10,INPUT);  // МЕНЮ КНОПКА SW энкодера
  MsTimer2::set(3, to_Timer);MsTimer2::start();
  if(EEPROM.read(100)!=0){for(int i=0;i<101;i++){EEPROM.update(i,0);}}// очистка памяти при первом включении 
   vol = EEPROM.read(0)-87;treb = EEPROM.read(1)-7;bass = EEPROM.read(2)-7;
   in = EEPROM.read(3);sur = EEPROM.read(10);
   gain1 = EEPROM.read(4);gain2 = EEPROM.read(5);gain3 = EEPROM.read(6);
   gain4 = EEPROM.read(7);gain5 = EEPROM.read(8);gain6 = EEPROM.read(9);
   audio();
}

void loop(){
  if(digitalRead(10)==LOW){menu++;cl();time=millis();w=1;w2=1;if(menu>4){menu=0;}}// меню
  if(digitalRead(2)==HIGH){in++;;cl();time=millis();w=1;w2=1;www=1;if(in>5){in=0;};lcd.setCursor(0,0);lcd.print("    INPUT ");lcd.print(in+1);audio();delay(2000);cl();}// КНОПКА ВЫБОРА ВХОДА I

 ////////////////////// IR /////////////////////////////////////////////////
  if ( irrecv.decode( &ir )) {Serial.print("0x");Serial.println( ir.value,HEX);irrecv.resume();time=millis();w=1;}// IR приемник - чтение, в мониторе порта отображаются коды кнопок
  if(ir.value==0){gr1=0;gr2=0;}// запрет нажатий не активных кнопок пульта
  if(ir.value==IR_1){menu++;gr1=0;gr2=0;cl();time=millis();w=1;w2=1;if(menu>4){menu=0;}}// меню кнопка вверх 
  if(ir.value==IR_2){menu--;gr1=0;gr2=0;cl();time=millis();w=1;w2=1;if(menu<0){menu=4;}}// меню кнопка вниз
  if(ir.value==IR_5){in++;gr1=0;gr2=0;cl();time=millis();w=1;w2=1;www=1;if(in>5){in=0;};lcd.setCursor(0,0);lcd.print("    INPUT ");lcd.print(in+1);audio();delay(2000);cl();}// КНОПКА ВЫБОРА ВХОДА IN

/////////////////////////////// VOLUME -87 ... +0 дБ | step 1 dB////////////////////////////////////////////////
 if(menu==0){
     if(ir.value==IR_3){vol++;gr1=1;gr2=0;cl1();w2=1;vol_func();audio();}// кнопка > 
     if(ir.value==0xFFFFFFFF and gr1==1){vol++;gr2=0;cl1();w2=1;vol_func();audio();}// кнопка >>>>>>
     if(ir.value==IR_4){vol--;gr1=0;gr2=1;cl1();w2=1;vol_func();audio();}// кнопка <
     if(ir.value==0xFFFFFFFF and gr2==1){vol--;gr1=0;cl1();w2=1;vol_func();audio();}// кнопка <<<<<<
   
  if (newPosition != oldPosition){oldPosition = newPosition;vol=vol+newPosition;myEnc.write(0);newPosition=0;time=millis();w=1;w2=1;vol_func();audio();}
    vol_d = 87-abs(vol);
    a[0]= vol_d/10;a[1]=vol_d%10;

    for(i=0;i<2;i++){
      switch(i){
        case 0: e1=9,e2=10,e3=11;break;
        case 1: e1=13,e2=14,e3=15;break;}       
      switch(a[i]){
        case 0: d1=1,d2=2,d3=1,d4=1,d5=3,d6=1;break;
        case 1: d1=2,d2=1,d3=5,d4=7,d5=1,d6=7;break;
        case 2: d1=2,d2=4,d3=1,d4=1,d5=3,d6=3;break;
        case 3: d1=2,d2=4,d3=1,d4=3,d5=3,d6=1;break;
        case 4: d1=1,d2=3,d3=1,d4=5,d5=5,d6=1;break;
        case 5: d1=1,d2=4,d3=2,d4=3,d5=3,d6=1;break;
        case 6: d1=1,d2=4,d3=2,d4=1,d5=3,d6=1;break;
        case 7: d1=2,d2=2,d3=1,d4=5,d5=5,d6=1;break;
        case 8: d1=1,d2=4,d3=1,d4=1,d5=3,d6=1;break;
        case 9: d1=1,d2=4,d3=1,d4=3,d5=3,d6=1;break;
       case 11: d1=5,d2=5,d3=5,d4=5,d5=5,d6=5;break;
    }
     
      lcd.setCursor(e1,0);lcd.write((uint8_t)d1);lcd.setCursor(e2,0);lcd.write((uint8_t)d2);lcd.setCursor(e3,0);lcd.write((uint8_t)d3);
      lcd.setCursor(e1,1);lcd.write((uint8_t)d4);lcd.setCursor(e2,1);lcd.write((uint8_t)d5);lcd.setCursor(e3,1);lcd.write((uint8_t)d6);}
   //   if(vol<0){lcd.setCursor(7,0);lcd.write((uint8_t)7);}else{lcd.setCursor(7,0);lcd.write((uint8_t)5);}
      lcd.setCursor(0,0);lcd.print("VOLUME");
      lcd.setCursor(0,1);lcd.print("IN ");lcd.print(in+1);
  }

///////////////////////// TREBLE +/-14 dB | step 2 dB/////////////////////////////////////////////////////////
   if(menu==1){
     if(ir.value==IR_3){treb++;gr1=1;gr2=0;cl1();w2=1;treb_func();audio();}// кнопка > 
     if(ir.value==0xFFFFFFFF and gr1==1){treb++;gr2=0;cl1();w2=1;treb_func();audio();}// кнопка >>>>>>
     if(ir.value==IR_4){treb--;gr1=0;gr2=1;cl1();w2=1;treb_func();audio();}// кнопка < 
     if(ir.value==0xFFFFFFFF and gr2==1){treb--;gr1=0;cl1();w2=1;treb_func();audio();}// кнопка <<<<<<
    
      if (newPosition != oldPosition) {
     oldPosition = newPosition;
treb=treb+newPosition;myEnc.write(0);newPosition=0;time=millis();w=1;w2=1;treb_func();audio();}

    treb_d = abs(treb*2);
    a[0]= treb_d/10;a[1]=treb_d%10;

    for(i=0;i<2;i++){
      switch(i){
        case 0: e1=9,e2=10,e3=11;break;
        case 1: e1=13,e2=14,e3=15;break;}       
      switch(a[i]){
        case 0: d1=1,d2=2,d3=1,d4=1,d5=3,d6=1;break;
        case 1: d1=2,d2=1,d3=5,d4=7,d5=1,d6=7;break;
        case 2: d1=2,d2=4,d3=1,d4=1,d5=3,d6=3;break;
        case 3: d1=2,d2=4,d3=1,d4=3,d5=3,d6=1;break;
        case 4: d1=1,d2=3,d3=1,d4=5,d5=5,d6=1;break;
        case 5: d1=1,d2=4,d3=2,d4=3,d5=3,d6=1;break;
        case 6: d1=1,d2=4,d3=2,d4=1,d5=3,d6=1;break;
        case 7: d1=2,d2=2,d3=1,d4=5,d5=5,d6=1;break;
        case 8: d1=1,d2=4,d3=1,d4=1,d5=3,d6=1;break;
        case 9: d1=1,d2=4,d3=1,d4=3,d5=3,d6=1;break;
       case 11: d1=5,d2=5,d3=5,d4=5,d5=5,d6=5;break;
    }
     
      lcd.setCursor(e1,0);lcd.write((uint8_t)d1);lcd.setCursor(e2,0);lcd.write((uint8_t)d2);lcd.setCursor(e3,0);lcd.write((uint8_t)d3);
      lcd.setCursor(e1,1);lcd.write((uint8_t)d4);lcd.setCursor(e2,1);lcd.write((uint8_t)d5);lcd.setCursor(e3,1);lcd.write((uint8_t)d6);}

       if(treb<0){lcd.setCursor(7,0);lcd.write((uint8_t)7);}else{lcd.setCursor(7,0);lcd.write((uint8_t)5);}
      lcd.setCursor(0,0);lcd.print("TREBLE");
      lcd.setCursor(0,1);lcd.print("10 kHz");
  }   
  
/////////////////////// BASS +/-14 dB | step 2 dB///////////////////////////////////////////////////////////
   if(menu==2){
     if(ir.value==IR_3){bass++;gr1=1;gr2=0;cl1();w2=1;bass_func();audio();}// кнопка > 
     if(ir.value==0xFFFFFFFF and gr1==1){bass++;gr2=0;cl1();w2=1;bass_func();audio();}// кнопка >>>>>>
     if(ir.value==IR_4){bass--;gr1=0;gr2=1;cl1();w2=1;bass_func();audio();}// кнопка < 
     if(ir.value==0xFFFFFFFF and gr2==1){bass--;gr1=0;cl1();w2=1;bass_func();audio();}// кнопка <<<<<<  
    
    if (newPosition != oldPosition) {
    oldPosition = newPosition;
    bass=bass+newPosition;myEnc.write(0);newPosition=0;time=millis();w=1;w2=1;bass_func();audio();} 
   
   bass_d = abs(bass*2);
    a[0]= bass_d/10;a[1]=bass_d%10;

    for(i=0;i<2;i++){
      switch(i){
        case 0: e1=9,e2=10,e3=11;break;
        case 1: e1=13,e2=14,e3=15;break;}       
      switch(a[i]){
        case 0: d1=1,d2=2,d3=1,d4=1,d5=3,d6=1;break;
        case 1: d1=2,d2=1,d3=5,d4=7,d5=1,d6=7;break;
        case 2: d1=2,d2=4,d3=1,d4=1,d5=3,d6=3;break;
        case 3: d1=2,d2=4,d3=1,d4=3,d5=3,d6=1;break;
        case 4: d1=1,d2=3,d3=1,d4=5,d5=5,d6=1;break;
        case 5: d1=1,d2=4,d3=2,d4=3,d5=3,d6=1;break;
        case 6: d1=1,d2=4,d3=2,d4=1,d5=3,d6=1;break;
        case 7: d1=2,d2=2,d3=1,d4=5,d5=5,d6=1;break;
        case 8: d1=1,d2=4,d3=1,d4=1,d5=3,d6=1;break;
        case 9: d1=1,d2=4,d3=1,d4=3,d5=3,d6=1;break;
       case 11: d1=5,d2=5,d3=5,d4=5,d5=5,d6=5;break;
    }
     
      lcd.setCursor(e1,0);lcd.write((uint8_t)d1);lcd.setCursor(e2,0);lcd.write((uint8_t)d2);lcd.setCursor(e3,0);lcd.write((uint8_t)d3);
      lcd.setCursor(e1,1);lcd.write((uint8_t)d4);lcd.setCursor(e2,1);lcd.write((uint8_t)d5);lcd.setCursor(e3,1);lcd.write((uint8_t)d6);}

       if(bass<0){lcd.setCursor(7,0);lcd.write((uint8_t)7);}else{lcd.setCursor(7,0);lcd.write((uint8_t)5);}
      lcd.setCursor(0,0);lcd.print("BASS  ");
      lcd.setCursor(0,1);lcd.print("100 Hz");
  }   

   //////////////// IN + GAIN /////////////////////////////////////////////////////////////
   if(menu==3){ 
       switch(in){
     case 0: gain0 = gain1;break;
     case 1: gain0 = gain2;break;
     case 2: gain0 = gain3;break;
     case 3: gain0 = gain4;break;
     case 4: gain0 = gain5;break;
     case 5: gain0 = gain6;break;
     }
     if(ir.value==IR_3){gain0++;gr1=1;gr2=0;cl1();w2=1;gain_func();audio();}// кнопка > 
     if(ir.value==0xFFFFFFFF and gr1==1){gain0++;gr2=0;cl1();w2=1;gain_func();audio();}// кнопка >>>>>>
     if(ir.value==IR_4){gain0--;gr1=0;gr2=1;cl1();w2=1;gain_func();audio();}// кнопка < 
     if(ir.value==0xFFFFFFFF and gr2==1){gain0--;gr1=0;cl1();w2=1;gain_func();audio();}// кнопка <<<<<<

    if (newPosition != oldPosition) {
    oldPosition = newPosition;
    gain0=gain0+newPosition;myEnc.write(0);newPosition=0;time=millis();w=1;w2=1;gain_func();audio();} 
   switch(in){
     case 0: gain1 = gain0;break;
     case 1: gain2 = gain0;break;
     case 2: gain3 = gain0;break;
     case 3: gain4 = gain0;break;
     case 4: gain5 = gain0;break;
     case 5: gain6 = gain0;break;
     } 
    if(www==1){audio();www=0;}
  lcd.setCursor(0,0);lcd.print("Gain");
  lcd.setCursor(0,1);lcd.print("IN ");lcd.print(in+1);
  
     gain0 = abs(gain0*2);
    a[0]= gain0/10;a[1]=gain0%10;

    for(i=0;i<2;i++){
      switch(i){
        case 0: e1=9,e2=10,e3=11;break;
        case 1: e1=13,e2=14,e3=15;break;}       
      switch(a[i]){
        case 0: d1=1,d2=2,d3=1,d4=1,d5=3,d6=1;break;
        case 1: d1=2,d2=1,d3=5,d4=7,d5=1,d6=7;break;
        case 2: d1=2,d2=4,d3=1,d4=1,d5=3,d6=3;break;
        case 3: d1=2,d2=4,d3=1,d4=3,d5=3,d6=1;break;
        case 4: d1=1,d2=3,d3=1,d4=5,d5=5,d6=1;break;
        case 5: d1=1,d2=4,d3=2,d4=3,d5=3,d6=1;break;
        case 6: d1=1,d2=4,d3=2,d4=1,d5=3,d6=1;break;
        case 7: d1=2,d2=2,d3=1,d4=5,d5=5,d6=1;break;
        case 8: d1=1,d2=4,d3=1,d4=1,d5=3,d6=1;break;
        case 9: d1=1,d2=4,d3=1,d4=3,d5=3,d6=1;break;
       case 11: d1=5,d2=5,d3=5,d4=5,d5=5,d6=5;break;
    }
     
      lcd.setCursor(e1,0);lcd.write((uint8_t)d1);lcd.setCursor(e2,0);lcd.write((uint8_t)d2);lcd.setCursor(e3,0);lcd.write((uint8_t)d3);
      lcd.setCursor(e1,1);lcd.write((uint8_t)d4);lcd.setCursor(e2,1);lcd.write((uint8_t)d5);lcd.setCursor(e3,1);lcd.write((uint8_t)d6);}
   }

  ////////////////////////////// Surround ////////////////////////////////////////////////////
 if(menu==4){  
     if(ir.value==IR_3){sur++;gr1=1;gr2=0;cl1();w2=1;sur_func();audio();}// кнопка > 
     if(ir.value==0xFFFFFFFF and gr1==1){sur++;gr2=0;cl1();w2=1;sur_func();audio();}// кнопка >>>>>>
     if(ir.value==IR_4){sur--;gr1=0;gr2=1;cl1();w2=1;sur_func();audio();}// кнопка < 
     if(ir.value==0xFFFFFFFF and gr2==1){sur--;gr1=0;cl1();w2=1;sur_func();audio();}// кнопка <<<<<< 
  
    if (newPosition != oldPosition) {
    oldPosition = newPosition;
    sur=sur+newPosition;myEnc.write(0);newPosition=0;time=millis();w=1;w2=1;sur_func();audio();} 

    lcd.setCursor(0,0);lcd.print("Surround Gain");
    lcd.setCursor(0,1);
      switch(sur){
         case 0: lcd.print("OFF   ");break;
         case 1: lcd.print("LOW   ");break;
         case 2: lcd.print("MIDDLE");break;
         case 3: lcd.print("HIGH  ");break;}}  
  


 ///////////////////// EEPROM ///////////////////////////////////////////////////////////////         
  if(millis()-time>10000 && w==1){
     EEPROM.update(0,vol+87);EEPROM.update(1,treb+7);EEPROM.update(2,bass+7);
     EEPROM.update(3,in);EEPROM.update(10,sur);
     EEPROM.update(4,gain1);EEPROM.update(5,gain2);EEPROM.update(6,gain3);
     EEPROM.update(7,gain4);EEPROM.update(8,gain5);EEPROM.update(9,gain6);
     menu=0;w=0;w2=1;cl();}
  
  }//loop

void sur_func(){if(sur>3){sur=0;}if(sur<0){sur=3;}}
void gain_func(){if(gain0<0){gain0=0;}if(gain0>7){gain0=7;}}
void bass_func(){if(bass>7){bass=7;}if(bass<-7){bass=-7;}} 
void treb_func(){if(treb>7){treb=7;}if(treb<-7){treb=-7;}}
void vol_func(){if(vol<-87){vol=-87;}if(vol>0){vol=0;}}
void cl(){ir.value=0;delay(300);lcd.clear();}
void cl1(){ir.value=0;delay(100);}
void to_Timer(){newPosition = myEnc.read()/4;}  

void audio(){
    bd.setSelect(in);// int 0...7 === A B C D E F INPUT_SHORT INPUT_MUTE
    bd.setIn_gain(gain0); // int 0...7 === 0...14 dB    
    bd.setVol_1(abs(vol)); // int 0...87 === 0...-87 dB
    bd.setVol_2(abs(vol)); // int 0...87 === 0...-87 dB
    bd.setBass(bass); // int -7...0...+7 === -7...+7 dB
    bd.setTreb(treb); // int -7...0...+7 === -7...+7 dB
    bd.setSurround(sur); // int 0...3 === OFF LOW MIDDLE HIGH
  }

5

Re: BD3491FS

Предустановленный выбор тембра (pop, classic,rock)

#define IR_1 0x807F926D // Up button
#define IR_2 0x807FB04F // Down button
#define IR_3 0x807F32CD // Button>
#define IR_4 0x807F728D // Button <
#define IR_5 0x807FB24D // IN button


#include <Wire.h>
#include <LiquidCrystal_I2C.h>
#include <BD3491FS.h>
#include <Encoder.h>
#include <EEPROM.h>
#include <MsTimer2.h>
#include <boarddefs.h>
#include <IRremote.h>
BD3491FS bd;
LiquidCrystal_I2C lcd (0x27,16,2); // Set up the display
IRrecv irrecv (12); // specify the output of the IR receiver module
Encoder myEnc (8, 9); // CLK, DT
decode_results ir;
byte a1 [8] = {0b00000,0b10101,0b10101,0b10101,0b10101,0b10101,0b10101,0b00000};
byte a2 [8] = {0b00000,0b10100,0b10100,0b10100,0b10100,0b10100,0b10100,0b00000};
byte a3 [8] = {0b00000,0b10000,0b10000,0b10000,0b10000,0b10000,0b10000,0b00000};
unsigned long time, oldPosition = -999, newPosition;
int menu, w, w2, vol, vol_d, gr1, gr2, z, z0, z1, treb, treb_d, bass, bass_d, in, www, gain1, gain2, gain3, gain4, gain5, gain6, gain0, gain_d, sur ;
int tembr;

void setup () {
irrecv.enableIRIn();lcd.init();lcd.backlight();
  lcd.setCursor(0,0);lcd.print("    BD3491FS    ");delay(2000);cl();
  Serial.begin(9600); lcd.createChar(0,a1);lcd.createChar(1,a2);lcd.createChar(2,a3);
  pinMode(10,INPUT);  // МЕНЮ КНОПКА SW энкодера
  pinMode(11, INPUT_PULLUP); // Tone mode selection button
  pinMode(2, INPUT_PULLUP); // Input button

  MsTimer2::set(3, to_Timer);MsTimer2::start();
  if(EEPROM.read(100)!=0){for(int i=0;i<101;i++){EEPROM.update(i,0);}}// очистка памяти при первом включении 
   vol = EEPROM.read(0)-87;treb = EEPROM.read(1)-7;bass = EEPROM.read(2)-7;
   in = EEPROM.read(3);sur = EEPROM.read(10);
   gain1 = EEPROM.read(4);gain2 = EEPROM.read(5);gain3 = EEPROM.read(6);
   gain4 = EEPROM.read(7);gain5 = EEPROM.read(8);gain6 = EEPROM.read(9);
   audio();
}

void loop(){
if(digitalRead(11)==LOW){tembr++;cl();time=millis();w=1;w2=1;if(tembr>2){tembr=0;}
switch(tembr){
    case 0: bass=8;treb=0;cl();lcd.setCursor(0,0);lcd.print("      ROCK     "); audio();break;
    case 1: bass=0;treb=0;cl();lcd.setCursor(0,0);lcd.print("      POP      "); audio();break;
    case 2: bass=2;treb=4;cl();lcd.setCursor(0,0);lcd.print("    CLASSIC    "); audio();break;
}delay(2000);menu=0;}
if(digitalRead(10) == LOW){menu++;cl();time = millis();w = 1;w2 = 1;if(menu> 4){menu = 0;}} // menu
if(digitalRead(2) == LOW){in++;cl();time = millis(); w = 1; w2 = 1; www = 1; if(in> 5){in = 0;}; lcd.setCursor(0,0); lcd.print("INPUT"); lcd.print(in + 1); audio(); delay(2000);} // INPUT SELECTOR BUTTON I

////////////////////// IR /////////////////////////// //////////////////////
if(irrecv.decode( &ir )){Serial.print("0x");Serial.println( ir.value,HEX);irrecv.resume();time=millis();w=1;}// IR приемник - чтение, в мониторе порта отображаются коды кнопок
  if(ir.value==0){gr1=0;gr2=0;}// запрет нажатий не активных кнопок пульта
  if(ir.value==IR_1){menu++;gr1=0;gr2=0;cl();time=millis();w=1;w2=1;if(menu>4){menu=0;}}// меню кнопка вверх 
  if(ir.value==IR_2){menu--;gr1=0;gr2=0;cl();time=millis();w=1;w2=1;if(menu<0){menu=4;}}// меню кнопка вниз
  if(ir.value==IR_5){in++;gr1=0;gr2=0;cl();time=millis();w=1;w2=1;www=1;if(in>5){in=0;};lcd.setCursor(0,0);lcd.print("    INPUT ");lcd.print(in+1);audio();delay(2000);}// КНОПКА ВЫБОРА ВХОДА IN
   
/////////////////////////////// VOLUME -87 ... +0 dB | step 1 dB ///////////////////////////////////////////// /
if(menu==0){
     if(ir.value==IR_3){vol++;gr1=1;gr2=0;cl1();w2=1;vol_func();audio();}// кнопка > 
     if(ir.value==0xFFFFFFFF and gr1==1){vol++;gr2=0;cl1();w2=1;vol_func();audio();}// кнопка >>>>>>
     if(ir.value==IR_4){vol--;gr1=0;gr2=1;cl1();w2=1;vol_func();audio();}// кнопка <
     if(ir.value==0xFFFFFFFF and gr2==1){vol--;gr1=0;cl1();w2=1;vol_func();audio();}// кнопка <<<<<<
   
   if (newPosition != oldPosition){oldPosition = newPosition;
     vol=vol+newPosition;myEnc.write(0);newPosition=0;time=millis();w=1;w2=1;vol_func;audio();} 
     lcd.setCursor(0,0);lcd.print("VOLUME   ");
     lcd.print(" ");lcd.print(87+vol);lcd.print(" ");lcd.setCursor(13,0);lcd.print("dB");vol_d=vol+48;
   if(w2==1){
   for(z=0,z0=0,z1=0;z<=vol_d;z++,z1++){if(z1>2){z1=0;z0++;}
   if(z1==1){lcd.setCursor(z0,1);lcd.write((uint8_t)0);lcd.setCursor(z0+1,1);lcd.print("   ");}}
   if(z1==3){lcd.setCursor(z0,1);lcd.write((uint8_t)1);}
   if(z1==2){lcd.setCursor(z0,1);lcd.write((uint8_t)2);}w2=0;}}  
///////////////////////// TREBLE +/- 14 dB | step 2 dB ///////////////////////////////////////////// //////////
if(menu==1){
     if(ir.value==IR_3){treb++;gr1=1;gr2=0;cl1();w2=1;treb_func();audio();}// кнопка > 
     if(ir.value==0xFFFFFFFF and gr1==1){treb++;gr2=0;cl1();w2=1;treb_func();audio();}// кнопка >>>>>>
     if(ir.value==IR_4){treb--;gr1=0;gr2=1;cl1();w2=1;treb_func();audio();}// кнопка < 
     if(ir.value==0xFFFFFFFF and gr2==1){treb--;gr1=0;cl1();w2=1;treb_func();audio();}// кнопка <<<<<<
    
     if (newPosition != oldPosition) {
    oldPosition = newPosition;
    treb=treb+newPosition;myEnc.write(0);newPosition=0;time=millis();w=1;w2=1;treb_func();audio();} 
   lcd.setCursor(0,0);lcd.print("TREBLE  ");
   lcd.print(" ");lcd.print(treb*2);lcd.print(" ");lcd.setCursor(13,0);lcd.print("dB");treb_d=treb*2+14;
   if(w2==1){
   for(z=0,z0=0,z1=0;z<=treb_d;z++,z1++){if(z1>2){z1=0;z0++;}
   if(z1==1){lcd.setCursor(z0+3,1);lcd.write((uint8_t)0);lcd.setCursor(z0+1+3,1);lcd.print("   ");}}
   if(z1==3){lcd.setCursor(z0+3,1);lcd.write((uint8_t)1);}
   if(z1==2){lcd.setCursor(z0+3,1);lcd.write((uint8_t)2);}w2=0;}}   
  
/////////////////////// BASS +/- 14 dB | step 2 dB ///////////////////////////////////////////// ////////////
if(menu==2){
     if(ir.value==IR_3){bass++;gr1=1;gr2=0;cl1();w2=1;bass_func();audio();}// кнопка > 
     if(ir.value==0xFFFFFFFF and gr1==1){bass++;gr2=0;cl1();w2=1;bass_func();audio();}// кнопка >>>>>>
     if(ir.value==IR_4){bass--;gr1=0;gr2=1;cl1();w2=1;bass_func();audio();}// кнопка < 
     if(ir.value==0xFFFFFFFF and gr2==1){bass--;gr1=0;cl1();w2=1;bass_func();audio();}// кнопка <<<<<<  
    
    if (newPosition != oldPosition) {
    oldPosition = newPosition;
    bass=bass+newPosition;myEnc.write(0);newPosition=0;time=millis();w=1;w2=1;bass_func();audio();} 
   lcd.setCursor(0,0);lcd.print("BASS    ");
   lcd.print(" ");lcd.print(bass*2);lcd.print(" ");lcd.setCursor(13,0);lcd.print("dB");bass_d=bass*2+14;
   if(w2==1){
   for(z=0,z0=0,z1=0;z<=bass_d;z++,z1++){if(z1>2){z1=0;z0++;}
   if(z1==1){lcd.setCursor(z0+3,1);lcd.write((uint8_t)0);lcd.setCursor(z0+1+3,1);lcd.print("   ");}}
   if(z1==3){lcd.setCursor(z0+3,1);lcd.write((uint8_t)1);}
   if(z1==2){lcd.setCursor(z0+3,1);lcd.write((uint8_t)2);}w2=0;}} 


//////////////// IN + GAIN ///////////////////////////// //////////////////////////////
 if(menu==3){ 
       switch(in){
     case 0: gain0 = gain1;break;
     case 1: gain0 = gain2;break;
     case 2: gain0 = gain3;break;
     case 3: gain0 = gain4;break;
     case 4: gain0 = gain5;break;
     case 5: gain0 = gain6;break;
     }
     if(ir.value==IR_3){gain0++;gr1=1;gr2=0;cl1();w2=1;gain_func();audio();}// кнопка > 
     if(ir.value==0xFFFFFFFF and gr1==1){gain0++;gr2=0;cl1();w2=1;gain_func();audio();}// кнопка >>>>>>
     if(ir.value==IR_4){gain0--;gr1=0;gr2=1;cl1();w2=1;gain_func();audio();}// кнопка < 
     if(ir.value==0xFFFFFFFF and gr2==1){gain0--;gr1=0;cl1();w2=1;gain_func();audio();}// кнопка <<<<<<

    if (newPosition != oldPosition) {
    oldPosition = newPosition;
    gain0=gain0+newPosition;myEnc.write(0);newPosition=0;time=millis();w=1;w2=1;gain_func();audio();} 
   switch(in){
     case 0: gain1 = gain0;break;
     case 1: gain2 = gain0;break;
     case 2: gain3 = gain0;break;
     case 3: gain4 = gain0;break;
     case 4: gain5 = gain0;break;
     case 5: gain6 = gain0;break;
     } 
    if(www==1){audio();www=0;}
  lcd.setCursor(0,0);lcd.print("Gain IN ");lcd.print(in+1);
      lcd.setCursor(10,0);lcd.print(" ");lcd.print(gain0*2);lcd.print(" ");lcd.setCursor(14,0);lcd.print("dB");gain_d=gain0*2;
   if(w2==1){
   for(z=0,z0=0,z1=0;z<=gain_d;z++,z1++){if(z1>2){z1=0;z0++;}
   if(z1==1){lcd.setCursor(z0+6,1);lcd.write((uint8_t)0);lcd.setCursor(z0+1+6,1);lcd.print("   ");}}
   if(z1==3){lcd.setCursor(z0+6,1);lcd.write((uint8_t)1);}
   if(z1==2){lcd.setCursor(z0+6,1);lcd.write((uint8_t)2);}}w2=0;}

////////////////////////////// Surround /////////////////// /////////////////////////////////
if(menu==4){  
     if(ir.value==IR_3){sur++;gr1=1;gr2=0;cl1();w2=1;sur_func();audio();}// кнопка > 
     if(ir.value==0xFFFFFFFF and gr1==1){sur++;gr2=0;cl1();w2=1;sur_func();audio();}// кнопка >>>>>>
     if(ir.value==IR_4){sur--;gr1=0;gr2=1;cl1();w2=1;sur_func();audio();}// кнопка < 
     if(ir.value==0xFFFFFFFF and gr2==1){sur--;gr1=0;cl1();w2=1;sur_func();audio();}// кнопка <<<<<< 
  
    if (newPosition != oldPosition) {
    oldPosition = newPosition;
    sur=sur+newPosition;myEnc.write(0);newPosition=0;time=millis();w=1;w2=1;sur_func();audio();} 

    lcd.setCursor(0,0);lcd.print("Surround Gain");
    lcd.setCursor(0,1);
      switch(sur){
         case 0: lcd.print("OFF   ");break;
         case 1: lcd.print("LOW   ");break;
         case 2: lcd.print("MIDDLE");break;
         case 3: lcd.print("HIGH  ");break;}}  




///////////////////// EEPROM //////////////////////////// ///////////////////////////////////
if (millis() - time > 10000 && w == 1) {
EEPROM.update(0, vol + 87); EEPROM.update(1, treb + 7); EEPROM.update(2, bass + 7);
EEPROM.update(3, in); EEPROM.update(10, sur);
EEPROM.update(4, gain1); EEPROM.update(5, gain2); EEPROM.update(6, gain3);
EEPROM.update(7, gain4); EEPROM.update(8, gain5); EEPROM.update(9, gain6);
menu=0;w=0;w2=1;cl();}

} // loop

void sur_func(){if(sur>3){sur=0;}if(sur <0){sur=3;}}
void gain_func(){if(gain0<0){gain0 = 0;}if(gain0> 7){gain0 = 7;}}
void bass_func(){if(bass> 7){bass = 7;}if(bass <-7){bass = -7;}}
void treb_func(){if(treb> 7) {treb = 7;}if(treb <-7){treb = -7;}}
void vol_func(){if(vol <-87) {vol = -87;}if(vol> 0){vol = 0;}}
void cl(){ir.value = 0; delay(300); lcd.clear();}
void cl1(){ir.value = 0; delay(100);}
void to_Timer(){newPosition = myEnc.read()/4;}

void audio () {
bd.setSelect(in); // int 0 ... 7 === ABCDEF INPUT_SHORT INPUT_MUTE
bd.setIn_gain(gain0); // int 0 ... 7 === 0 ... 14 dB
bd.setVol_1(abs(vol)); // int 0 ... 87 === 0 ...- 87 dB
bd.setVol_2(abs(vol)); // int 0 ... 87 === 0 ...- 87 dB
bd.setBass(bass); // int -7 ... 0 ... + 7 === -7 ... + 7 dB
bd.setTreb(treb); // int -7 ... 0 ... + 7 === -7 ... + 7 dB
bd.setSurround(sur); // int 0 ... 3 === OFF LOW MIDDLE HIGH
}