1

Тема: PT2319

тестовый скетч (протестировано!!!)

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


#define CE 2
#define DI 3
#define CL 4

byte fader_m[16]={0b1111,0b0111,0b1011,0b0011,0b1101,0b0101,0b1001,0b0001,0b1110,0b0110,0b1010,0b0010,0b1100,0b0100,0b1000,0b0000};
byte sup_bass_m[11]={0b0000,0b1000,0b0100,0b1100,0b0010,0b1010,0b0110,0b1110,0b0001,0b1001,0b0101};
byte tembr_m[15]={0b1111,0b0111,0b1011,0b0011,0b1101,0b0101,0b1001,0b0000,0b1000,0b0100,0b1100,0b0010,0b1010,0b0110,0b1110};
byte in_gain_m[16]={0b0000,0b1000,0b0100,0b1100,0b0010,0b1010,0b0110,0b1110,0b0001,0b1001,0b0101,0b1101,0b0011,0b1011,0b0111,0b1111};
byte vol_m[81]={0b00100101,0b11000101,0b01000101,0b10000101,0b00111001,0b11011001,0b01011001,0b10011001,0b00101001,
                0b11001001,0b01001001,0b10001001,0b00110001,0b11010001,0b01010001,0b10010001,0b00100001,0b11000001,
                0b01000001,0b10000001,0b00111110,0b11011110,0b01011110,0b10011110,0b00101110,0b11001110,0b01001110,
                0b10001110,0b00110110,0b11010110,0b01010110,0b10010110,0b00100110,0b11000110,0b01000110,0b10000110,
                0b00111010,0b11011010,0b01011010,0b10011010,0b00101010,0b11001010,0b01001010,0b10001010,0b00110010,
                0b11010010,0b01010010,0b10010010,0b00100010,0b11000010,0b01000010,0b10000010,0b00111100,0b11011100,
                0b01011100,0b10011100,0b00101100,0b11001100,0b01001100,0b10001100,0b00110100,0b11010100,0b01010100,
                0b10010100,0b00100100,0b11000100,0b01000100,0b10000100,0b00111000,0b11011000,0b01011000,0b10011000,
                0b00101000,0b11001000,0b01001000,0b10001000,0b00110000,0b11010000,0b01010000,0b10010000,0b00000000};

void setup() {
   pinMode(CE,OUTPUT);pinMode(DI,OUTPUT);pinMode(CL,OUTPUT);
   digitalWrite(CL,LOW);digitalWrite(CE,LOW);digitalWrite(DI,LOW);
   Serial.begin(9600);
   Write(0,0,0,0,0,0,0,0,0,0,0);delay(100);  
}

void loop() {
  Write(0,1,7,15,0,0,1,0,0,3,0);
 
  delay(1000);
}

void Write(byte fader, byte sup_bass,byte bass, byte treb, int vol, byte in_gain,long in,long f_r,long out_gain,long c_set,long mute){  
 // fader 0...-60 ∞ dB >> byte 0...15 - ослабление тыл
 // sup_bass step0...step10 >> byte 0...10
 // bass step1...step15 >> byte 0...15
 // treb step1...step15 >> byte 0...15
 // vol 0...-79 ∞ dB >> int 0...80
 // in_gain 0...18.75 dB step 1.25dB >> int 0...15
 // in 1...5 >> int 1...5
 // f_r - Fader resr/front control >> int 0 >> не менять
 // out_gain 0, 6.5, 8.5 dB >> int 0...2
 // c_set >> int 0...3 >> 3 - не менять
 // mute >> 0 - off, 1 - on
 
  digitalWrite(CL,LOW);
  digitalWrite(CE,LOW);
  byte addr = 0b10000001;
     for(int i = 7; i >= 0; i--){
        digitalWrite(CL,LOW);
        digitalWrite(DI, (addr >> i) & 0x01);
        digitalWrite(CL,HIGH);
        }   
  digitalWrite(CE,HIGH);
     for(int i = 3; i >= 0; i--){
        digitalWrite(CL,LOW);
        digitalWrite(DI, (fader_m[fader] >> i) & 0x01);
        digitalWrite(CL,HIGH);
        }
     for(int i = 3; i >= 0; i--){
        digitalWrite(CL,LOW);
        digitalWrite(DI, (sup_bass_m[sup_bass] >> i) & 0x01); 
        digitalWrite(CL,HIGH);
        }                
     for(int i = 3; i >= 0; i--){
        digitalWrite(CL,LOW); 
        digitalWrite(DI, (tembr_m[bass] >> i) & 0x01);
        digitalWrite(CL,HIGH);
        } 
     for(int i = 3; i >= 0; i--){
        digitalWrite(CL,LOW);
        digitalWrite(DI, (tembr_m[treb] >> i) & 0x01);
        digitalWrite(CL,HIGH);
        } 
     for(int i = 7; i >= 0; i--){
        digitalWrite(CL,LOW); 
        digitalWrite(DI, (vol_m[vol] >> i) & 0x01);
        digitalWrite(CL,HIGH);
        }
     for(int i = 3; i >= 0; i--){
        digitalWrite(CL,LOW);
        digitalWrite(DI, (in_gain_m[in_gain] >> i) & 0x01);
        digitalWrite(CL,HIGH);
        } 
     long in1,in2,out_gain1,out_gain2;      
     switch(in){
      case 1: in1=0b00;in2=1;break;
      case 2: in1=0b10;in2=1;break;
      case 3: in1=0b01;in2=1;break;
      case 4: in1=0b11;in2=1;break;
      case 5: in1=0;in2=0;break;
      }
     switch(out_gain){
      case 0: out_gain1=0;out_gain2=1;break;
      case 1: out_gain1=1;out_gain2=0;break;
      case 2: out_gain1=1;out_gain2=1;break;
      } 
      
     long grup = (in1<<14)+(f_r<<13)+(out_gain1<<12)+(in2<<11)+(c_set<<9)+(mute<<8)+(out_gain2<<4);  
     for(int i = 15; i >= 0; i--){
        digitalWrite(CL,LOW); 
        digitalWrite(DI, (grup >> i) & 0x01); 
        digitalWrite(CL,HIGH); 
        }              
        digitalWrite(CL,LOW);
        digitalWrite(CE,LOW);
        Serial.println(grup,BIN);
  }

2

Re: PT2319

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

#define CE 2
#define DI 3
#define CL 4

#define IR1 0x2FDF00F // main/setting menu
#define IR2 0x2FDB24D // button encoder
#define IR3 0x2FDB04F // mute
#define IR4 0x2FD906F // >>>
#define IR5 0x2FDF20D // <<<
#define IR6 0x2FD6A95 // INPUT
#define IR7 0x2FD6563 // POWER
#define IN1 0x2FD6454 // IN1
#define IN2 0x2FD6235 // IN2
#define IN3 0x2FD5655 // IN3
#define IN4 0x2FD8454 // IN4
#define IN5 0x2FD6458 // IN5

#include <Wire.h> 
#include <LiquidCrystal_I2C.h> // http://forum.rcl-radio.ru/misc.php?action=pan_download&item=45&download=1
#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>
#include <IRremote.h>          // http://rcl-radio.ru/wp-content/uploads/2019/06/IRremote.zip
#include <DS3231.h>            // https://github.com/jarzebski/Arduino-DS3231/archive/master.zip

LiquidCrystal_I2C lcd(0x27,16,2);  // Устанавливаем дисплей
Encoder myEnc(8, 9);// DT, CLK
IRrecv irrecv(12); // указываем вывод модуля IR приемника
decode_results ir; 
DS3231 clock;RTCDateTime DateTime;

byte fader_m[16]={0b1111,0b0111,0b1011,0b0011,0b1101,0b0101,0b1001,0b0001,0b1110,0b0110,0b1010,0b0010,0b1100,0b0100,0b1000,0b0000};
byte sup_bass_m[11]={0b0000,0b1000,0b0100,0b1100,0b0010,0b1010,0b0110,0b1110,0b0001,0b1001,0b0101};
byte tembr_m[15]={0b1111,0b0111,0b1011,0b0011,0b1101,0b0101,0b1001,0b0000,0b1000,0b0100,0b1100,0b0010,0b1010,0b0110,0b1110};
byte in_gain_m[16]={0b0000,0b1000,0b0100,0b1100,0b0010,0b1010,0b0110,0b1110,0b0001,0b1001,0b0101,0b1101,0b0011,0b1011,0b0111,0b1111};
byte vol_m[81]={0b00100101,0b11000101,0b01000101,0b10000101,0b00111001,0b11011001,0b01011001,0b10011001,0b00101001,
                0b11001001,0b01001001,0b10001001,0b00110001,0b11010001,0b01010001,0b10010001,0b00100001,0b11000001,
                0b01000001,0b10000001,0b00111110,0b11011110,0b01011110,0b10011110,0b00101110,0b11001110,0b01001110,
                0b10001110,0b00110110,0b11010110,0b01010110,0b10010110,0b00100110,0b11000110,0b01000110,0b10000110,
                0b00111010,0b11011010,0b01011010,0b10011010,0b00101010,0b11001010,0b01001010,0b10001010,0b00110010,
                0b11010010,0b01010010,0b10010010,0b00100010,0b11000010,0b01000010,0b10000010,0b00111100,0b11011100,
                0b01011100,0b10011100,0b00101100,0b11001100,0b01001100,0b10001100,0b00110100,0b11010100,0b01010100,
                0b10010100,0b00100100,0b11000100,0b01000100,0b10000100,0b00111000,0b11011000,0b01011000,0b10011000,
                0b00101000,0b11001000,0b01001000,0b10001000,0b00110000,0b11010000,0b01010000,0b10010000,0b00000000};
byte v1[8] = {0b00111,0b00111,0b00111,0b00111,0b00111,0b00111,0b00111,0b00111};
byte v2[8] = {0b00111,0b00111,0b00000,0b00000,0b00000,0b00000,0b00000,0b00000};      
byte v3[8] = {0b00000,0b00000,0b00000,0b00000,0b00000,0b00000,0b11111,0b11111};
byte v4[8] = {0b11111,0b11111,0b00000,0b00000,0b00000,0b00000,0b11111,0b11111};
byte v5[8] = {0b11100,0b11100,0b00000,0b00000,0b00000,0b00000,0b11100,0b11100};
byte v6[8] = {0b11100,0b11100,0b11100,0b11100,0b11100,0b11100,0b11100,0b11100};
byte v7[8] = {0b00000,0b00000,0b00000,0b00000,0b00000,0b00000,0b00111,0b00111};
byte v8[8] = {0b11111,0b11111,0b00000,0b00000,0b00000,0b00000,0b00000,0b00000}; 

int menu0=100,menu,vol_reg,in_reg,treb_reg,bass_reg,super_bass_reg,gain0,gain1,gain2,gain3,gain4,gain5,out_gain_reg,att_rear,mute_reg;
byte a[6],d1,d2,d3,d4,d5,d6,e1,e2,e3,w,w2,x,www,gr1,gr2,power;
unsigned long times,oldPosition  = -999,newPosition;
int minut,secon,hour,brig_h=25,brig_l=5;

void setup() {
   irrecv.enableIRIn();lcd.init();lcd.backlight();clock.begin(); 
    //  clock.setDateTime(__DATE__, __TIME__); // Устанавливаем время на часах, основываясь на времени компиляции скетча
   lcd.createChar(1, v1);lcd.createChar(2, v2);lcd.createChar(3, v3);lcd.createChar(4, v4);
   lcd.createChar(5, v5);lcd.createChar(6, v6);lcd.createChar(7, v7);lcd.createChar(8, v8);
   pinMode(CE,OUTPUT);pinMode(DI,OUTPUT);pinMode(CL,OUTPUT);
   pinMode(10,INPUT);// encoder SW
   pinMode(11,INPUT_PULLUP);// input button
   pinMode(A0,INPUT_PULLUP);// menu set/main button
   pinMode(A1,INPUT_PULLUP);// mute button
   pinMode(A2,INPUT_PULLUP);// power button
   pinMode(6,OUTPUT);  // output led pwm
   pinMode(13,OUTPUT);  // output STANDBY pin
   digitalWrite(CL,LOW);digitalWrite(CE,LOW);digitalWrite(DI,LOW);
   MsTimer2::set(1, to_Timer);MsTimer2::start();
   if(EEPROM.read(100)!=0){for(int i=0;i<101;i++){EEPROM.update(i,0);}}// очистка памяти при первом включении  
   Serial.begin(9600);
   Write(0,0,0,0,0,0,0,0,0,0,0);delay(100);// clear register  
   vol_reg = EEPROM.read(0);treb_reg = EEPROM.read(1);bass_reg = EEPROM.read(2);super_bass_reg = EEPROM.read(3);
   gain1 = EEPROM.read(4);gain2 = EEPROM.read(5);gain3 = EEPROM.read(6);gain4 = EEPROM.read(7);gain5 = EEPROM.read(8);
   in_reg = EEPROM.read(9);out_gain_reg = EEPROM.read(10);out_gain_reg = EEPROM.read(10);att_rear = EEPROM.read(11);
   brig_h = EEPROM.read(12);brig_l = EEPROM.read(13);
   analogWrite(6, brig_h*10);
   audio();
}

void loop() {
  /// IR
  if ( irrecv.decode( &ir )) {Serial.print("0x");Serial.println( ir.value,HEX);irrecv.resume();times=millis();w=1;}// IR приемник - чтение, в мониторе порта отображаются коды кнопок
  if(ir.value==0){gr1=0;gr2=0;}// запрет нажатий не активных кнопок пульта  
  /// BUTTON 
  if((digitalRead(A2)==LOW||ir.value==IR7)&&power==0){power=1;cl();lcd.setCursor(3,0);lcd.print("POWER  OFF");menu=100;menu0=100;mute_reg=1;audio();analogWrite(6, brig_l*10);delay(3000);lcd.clear();}// power off
  if((digitalRead(A2)==LOW||ir.value==IR7)&&power==1){power=0;cl();lcd.setCursor(3,0);lcd.print("POWER   ON ");menu=0;menu0=100;mute_reg=0;audio();analogWrite(6, brig_h*10);delay(3000);lcd.clear();}// power on
  if(power==0){digitalWrite(13,HIGH);}else{digitalWrite(13,LOW);}
  if(power==0){
  if((digitalRead(10)==LOW||ir.value==IR2)&&menu0==100){menu++;menu0=100;cl();times=millis();w=1;if(menu>3){menu=0;}}
  if((digitalRead(10)==LOW||ir.value==IR2)&&menu==100){menu0++;menu=100;cl();times=millis();w=1;if(menu0>4){menu0=0;}}
  if((digitalRead(11)==LOW||ir.value==IR6)){in_reg++;cl();times=millis();w=1;if(in_reg>5){in_reg=1;}audio();lcd.setCursor(4,0);lcd.print("INPUT ");lcd.print(in_reg);delay(1000);cl();}
  if(ir.value==IN1){in_reg=1;cl();times=millis();w=1;audio();lcd.setCursor(4,0);lcd.print("INPUT ");lcd.print(in_reg);delay(1000);cl();}
  if(ir.value==IN2){in_reg=2;cl();times=millis();w=1;audio();lcd.setCursor(4,0);lcd.print("INPUT ");lcd.print(in_reg);delay(1000);cl();}
  if(ir.value==IN3){in_reg=3;cl();times=millis();w=1;audio();lcd.setCursor(4,0);lcd.print("INPUT ");lcd.print(in_reg);delay(1000);cl();}
  if(ir.value==IN4){in_reg=4;cl();times=millis();w=1;audio();lcd.setCursor(4,0);lcd.print("INPUT ");lcd.print(in_reg);delay(1000);cl();}
  if(ir.value==IN5){in_reg=5;cl();times=millis();w=1;audio();lcd.setCursor(4,0);lcd.print("INPUT ");lcd.print(in_reg);delay(1000);cl();}
  if((digitalRead(A0)==LOW||ir.value==IR1)&&menu<100){menu=100;menu0=0;gr1=0;gr2=0;cl();times=millis();w=1;lcd.setCursor(2,0);lcd.print("SETTING MENU");delay(1000);cl();}
  if((digitalRead(A0)==LOW||ir.value==IR1)&&menu0<100){menu0=100;menu=0;gr1=0;gr2=0;cl();times=millis();w=1;lcd.setCursor(3,0);lcd.print("MAIN MENU");delay(1000);cl();}
  if((digitalRead(A1)==LOW||ir.value==IR3)&&mute_reg==0){mute_reg=1;menu0=100;menu=0;cl();audio();}
  if((digitalRead(A1)==LOW||ir.value==IR3)&&mute_reg==1){mute_reg=0;menu0=100;menu=0;cl();audio();}
  }
////////////// VOLUME ///////////////////////////////////////////////////////////////////
 if(menu==0){
   if(ir.value==IR4){vol_reg++;gr1=1;gr2=0;cl1();times=millis();w=1;w2=1;vol_func();audio();}// кнопка > 
   if(ir.value==0xFFFFFFFF and gr1==1){vol_reg++;gr2=0;cl1();times=millis();w=1;w2=1;vol_func();audio();}// кнопка >>>>>>
   if(ir.value==IR5){vol_reg--;gr1=0;gr2=1;cl1();times=millis();w=1;w2=1;vol_func();audio();}// кнопка <
   if(ir.value==0xFFFFFFFF and gr2==1){vol_reg--;gr1=0;cl1();times=millis();w=1;w2=1;vol_func();audio();}// кнопка <<<<<<
   
   if (newPosition != oldPosition){oldPosition = newPosition;vol_reg=vol_reg+newPosition;myEnc.write(0);newPosition=0;times=millis();w=1;w2=1;vol_func();audio();}
   a[0]= vol_reg/10;a[1]=vol_reg%10;
   for(x=0;x<2;x++){switch(x){case 0: e1=10,e2=11,e3=12;break;case 1: e1=13,e2=14,e3=15;break;}digit();}
   if(mute_reg==0){lcd.setCursor(0,0);lcd.print("VOLUME");}else{lcd.setCursor(0,0);lcd.print("MUTE");}
   lcd.setCursor(0,1);lcd.print("INPUT ");lcd.print(in_reg);
   }
////////////// TREBLE ///////////////////////////////////////////////////////////////////
 if(menu==1){
   if(ir.value==IR4){treb_reg++;gr1=1;gr2=0;cl1();times=millis();w=1;w2=1;treb_func();audio();}// кнопка > 
   if(ir.value==0xFFFFFFFF and gr1==1){treb_reg++;gr2=0;cl1();times=millis();w=1;w2=1;treb_func();audio();}// кнопка >>>>>>
   if(ir.value==IR5){treb_reg--;gr1=0;gr2=1;cl1();times=millis();w=1;w2=1;treb_func();audio();}// кнопка <
   if(ir.value==0xFFFFFFFF and gr2==1){treb_reg--;gr1=0;cl1();times=millis();w=1;w2=1;treb_func();audio();}// кнопка <<<<<<
     
   if (newPosition != oldPosition){oldPosition = newPosition;treb_reg=treb_reg+newPosition;myEnc.write(0);newPosition=0;times=millis();w=1;w2=1;treb_func();
   audio();}
   a[0]= treb_reg/10;a[1]=treb_reg%10;
   for(x=0;x<2;x++){switch(x){case 0: e1=10,e2=11,e3=12;break;case 1: e1=13,e2=14,e3=15;break;}digit();}
   lcd.setCursor(0,0);lcd.print("TREBLE");lcd.setCursor(0,1);lcd.print("CONTROL");
   }  
////////////// BASS ///////////////////////////////////////////////////////////////////
 if(menu==2){
   if(ir.value==IR4){bass_reg++;gr1=1;gr2=0;cl1();times=millis();w=1;w2=1;bass_func();audio();}// кнопка > 
   if(ir.value==0xFFFFFFFF and gr1==1){bass_reg++;gr2=0;cl1();times=millis();w=1;w2=1;bass_func();audio();}// кнопка >>>>>>
   if(ir.value==IR5){bass_reg--;gr1=0;gr2=1;cl1();times=millis();w=1;w2=1;bass_func();audio();}// кнопка <
   if(ir.value==0xFFFFFFFF and gr2==1){bass_reg--;gr1=0;cl1();times=millis();w=1;w2=1;bass_func();audio();}// кнопка <<<<<<
     
   if (newPosition != oldPosition){oldPosition = newPosition;bass_reg=bass_reg+newPosition;myEnc.write(0);newPosition=0;times=millis();w=1;w2=1;bass_func();audio();}
   a[0]= bass_reg/10;a[1]=bass_reg%10;
   for(x=0;x<2;x++){switch(x){case 0: e1=10,e2=11,e3=12;break;case 1: e1=13,e2=14,e3=15;break;}digit();}
   lcd.setCursor(0,0);lcd.print("BASS");lcd.setCursor(0,1);lcd.print("CONTROL");
   }  
////////////// SUPER BASS ///////////////////////////////////////////////////////////////////
 if(menu==3){
   if(ir.value==IR4){super_bass_reg++;gr1=1;gr2=0;cl1();times=millis();w=1;w2=1;super_bass_func();audio();}// кнопка > 
   if(ir.value==0xFFFFFFFF and gr1==1){super_bass_reg++;gr2=0;cl1();times=millis();w=1;w2=1;super_bass_func();audio();}// кнопка >>>>>>
   if(ir.value==IR5){super_bass_reg--;gr1=0;gr2=1;cl1();times=millis();w=1;w2=1;super_bass_func();audio();}// кнопка <
   if(ir.value==0xFFFFFFFF and gr2==1){super_bass_reg--;gr1=0;cl1();times=millis();w=1;w2=1;super_bass_func();audio();}// кнопка <<<<<<
     
   if (newPosition != oldPosition){oldPosition = newPosition;super_bass_reg=super_bass_reg+newPosition;myEnc.write(0);newPosition=0;times=millis();w=1;w2=1;super_bass_func();audio();}
   a[0]= super_bass_reg/10;a[1]=super_bass_reg%10;
   for(x=0;x<2;x++){switch(x){case 0: e1=10,e2=11,e3=12;break;case 1: e1=13,e2=14,e3=15;break;}digit();}
   lcd.setCursor(0,0);lcd.print("SUPER BASS");lcd.setCursor(0,1);lcd.print("CONTROL");
   }   

////// MENU SET ///////////////////////////////////////////////////////////////////////////////////////////////////////
////////////// INPUT GAIN ///////////////////////////////////////////////////////////////////
 if(menu0==0){
  switch(in_reg){
     case 1: gain0 = gain1;break;
     case 2: gain0 = gain2;break;
     case 3: gain0 = gain3;break;
     case 4: gain0 = gain4;break;
     case 5: gain0 = gain5;break;}
     
   if(ir.value==IR4){gain0++;gr1=1;gr2=0;cl1();times=millis();w=1;w2=1;gain_func();audio();}// кнопка > 
   if(ir.value==0xFFFFFFFF and gr1==1){gain0++;gr2=0;cl1();times=millis();w=1;w2=1;gain_func();audio();}// кнопка >>>>>>
   if(ir.value==IR5){gain0--;gr1=0;gr2=1;cl1();times=millis();w=1;w2=1;gain_func();audio();}// кнопка <
   if(ir.value==0xFFFFFFFF and gr2==1){gain0--;gr1=0;cl1();times=millis();w=1;w2=1;gain_func();audio();}// кнопка <<<<<<
   
  if (newPosition != oldPosition){oldPosition = newPosition;gain0=gain0+newPosition;myEnc.write(0);newPosition=0;times=millis();www=1;w=1;gain_func();}
  switch(in_reg){
     case 1: gain1 = gain0;break;
     case 2: gain2 = gain0;break;
     case 3: gain3 = gain0;break;
     case 4: gain4 = gain0;break;
     case 5: gain5 = gain0;break;}  
     a[0]= gain0/10;a[1]=gain0%10;
   for(x=0;x<2;x++){switch(x){case 0: e1=10,e2=11,e3=12;break;case 1: e1=13,e2=14,e3=15;break;}digit();}
   if(www==1){audio();www=0;}
   lcd.setCursor(0,0);lcd.print("IN GAIN");
   lcd.setCursor(0,1);lcd.print("INPUT ");lcd.print(in_reg);}
////////////// OUT GAIN ///////////////////////////////////////////////////////////////////
 if(menu0==1){
   if(ir.value==IR4){out_gain_reg++;gr1=1;gr2=0;cl1();times=millis();w=1;w2=1;out_gain_func();audio();}// кнопка > 
   if(ir.value==0xFFFFFFFF and gr1==1){out_gain_reg++;gr2=0;cl1();times=millis();w=1;w2=1;out_gain_func();audio();}// кнопка >>>>>>
   if(ir.value==IR5){out_gain_reg--;gr1=0;gr2=1;cl1();times=millis();w=1;w2=1;out_gain_func();audio();}// кнопка <
   if(ir.value==0xFFFFFFFF and gr2==1){out_gain_reg--;gr1=0;cl1();times=millis();w=1;w2=1;out_gain_func();audio();}// кнопка <<<<<<
     
   if (newPosition != oldPosition){oldPosition = newPosition;out_gain_reg=out_gain_reg+newPosition;myEnc.write(0);newPosition=0;times=millis();w=1;w2=1;out_gain_func();audio();}
   a[0]= out_gain_reg;
   for(x=0;x<1;x++){switch(x){case 0: e1=13,e2=14,e3=15;;break;case 1: e1=13,e2=14,e3=15;break;}digit();}
   lcd.setCursor(0,0);lcd.print("OUT GAIN");
   } 
 ////////////// ATT REAR ///////////////////////////////////////////////////////////////////
 if(menu0==2){
   if(ir.value==IR4){att_rear++;gr1=1;gr2=0;cl1();times=millis();w=1;w2=1;rear_func();audio();}// кнопка > 
   if(ir.value==0xFFFFFFFF and gr1==1){att_rear++;gr2=0;cl1();times=millis();w=1;w2=1;rear_func();audio();}// кнопка >>>>>>
   if(ir.value==IR5){att_rear--;gr1=0;gr2=1;cl1();times=millis();w=1;w2=1;rear_func();audio();}// кнопка <
   if(ir.value==0xFFFFFFFF and gr2==1){att_rear--;gr1=0;cl1();times=millis();w=1;w2=1;rear_func();audio();}// кнопка <<<<<<
     
   if (newPosition != oldPosition){oldPosition = newPosition;att_rear=att_rear+newPosition;myEnc.write(0);newPosition=0;times=millis();w=1;w2=1;rear_func();audio();}
   a[0]= att_rear/10;a[1]=att_rear%10;
   for(x=0;x<2;x++){switch(x){case 0: e1=10,e2=11,e3=12;break;case 1: e1=13,e2=14,e3=15;break;}digit();}
   lcd.setCursor(0,0);lcd.print("ATT REAR");
   } 
 ////////////// BRIG_H  ///////////////////////////////////////////////////////////////////
 if(menu0==3){
   if(ir.value==IR4){brig_h++;gr1=1;gr2=0;cl1();times=millis();w=1;w2=1;brig_h_func();}// кнопка > 
   if(ir.value==0xFFFFFFFF and gr1==1){brig_h++;gr2=0;cl1();times=millis();w=1;w2=1;brig_h_func();}// кнопка >>>>>>
   if(ir.value==IR5){brig_h--;gr1=0;gr2=1;cl1();times=millis();w=1;w2=1;brig_h_func();}// кнопка <
   if(ir.value==0xFFFFFFFF and gr2==1){brig_h--;gr1=0;cl1();times=millis();w=1;w2=1;brig_h_func();}// кнопка <<<<<<
     
   if (newPosition != oldPosition){oldPosition = newPosition;brig_h=brig_h+newPosition;myEnc.write(0);newPosition=0;times=millis();w=1;w2=1;brig_h_func();}
   a[0]= brig_h/10;a[1]=brig_h%10;
   for(x=0;x<2;x++){switch(x){case 0: e1=10,e2=11,e3=12;break;case 1: e1=13,e2=14,e3=15;break;}digit();}
   lcd.setCursor(0,0);lcd.print("BRIG HIGH");
   }  
 ////////////// BRIG_L  ///////////////////////////////////////////////////////////////////
 if(menu0==4){
   if(ir.value==IR4){brig_l++;gr1=1;gr2=0;cl1();times=millis();w=1;w2=1;brig_l_func();}// кнопка > 
   if(ir.value==0xFFFFFFFF and gr1==1){brig_l++;gr2=0;cl1();times=millis();w=1;w2=1;brig_l_func();}// кнопка >>>>>>
   if(ir.value==IR5){brig_l--;gr1=0;gr2=1;cl1();times=millis();w=1;w2=1;brig_l_func();}// кнопка <
   if(ir.value==0xFFFFFFFF and gr2==1){brig_l--;gr1=0;cl1();times=millis();w=1;w2=1;brig_l_func();}// кнопка <<<<<<
     
   if (newPosition != oldPosition){oldPosition = newPosition;brig_l=brig_l+newPosition;myEnc.write(0);newPosition=0;times=millis();w=1;w2=1;brig_l_func();}
   a[0]= brig_l/10;a[1]=brig_l%10;
   for(x=0;x<2;x++){switch(x){case 0: e1=10,e2=11,e3=12;break;case 1: e1=13,e2=14,e3=15;break;}digit();}
   lcd.setCursor(0,0);lcd.print("BRIG LOW");
   }     
     

   /////////////////// ЧАСЫ ///////////////////////////////////////////////////////////////////
DateTime = clock.getDateTime();hour = DateTime.hour;minut = DateTime.minute;secon = DateTime.second;   
if(power==1){
     a[0]=DateTime.hour/10;
     a[1]=DateTime.hour%10;
     a[2]=DateTime.minute/10;
     a[3]=DateTime.minute%10;
     a[4]=DateTime.second/10;
     a[5]=DateTime.second%10;
   for(x=0;x<4;x++){
    switch(x){
        case 0: e1=0,e2=1,e3=2;break;
        case 1: e1=3,e2=4,e3=5;break;
        case 2: e1=7,e2=8,e3=9;break;
        case 3: e1=10,e2=11,e3=12;break;
   }digit();}
 
   lcd.setCursor(6,0);lcd.print(".");lcd.setCursor(6,1);lcd.print(".");
   lcd.setCursor(14,1);lcd.print(a[4]);lcd.setCursor(15,1);lcd.print(a[5]);   
//// set time ////
  if(digitalRead(10)==LOW&&digitalRead(11)==LOW){hour++;if(hour>23){hour=0;} clock.setDateTime(2020, 9, 15, hour, minut, secon);delay(100);}// input button
  if(digitalRead(10)==LOW&&digitalRead(A0)==LOW){minut++;if(minut>59){minut=0;} clock.setDateTime(2020, 9, 15, hour, minut, secon);delay(100); }// menu set/main button
  if(digitalRead(10)==LOW&&digitalRead(A1)==LOW){secon=0; clock.setDateTime(2020, 9, 15, hour, minut, secon);delay(100); }// mute button
}    

   
////////////////////////////////////////////////////////////////////////////////////////////
  if(millis()-times>10000 && w==1 && power==0){
     EEPROM.write(0,vol_reg);EEPROM.write(1,treb_reg);EEPROM.write(2,bass_reg);EEPROM.write(3,super_bass_reg);
     EEPROM.update(4,gain1);EEPROM.update(5,gain2);EEPROM.update(6,gain3);EEPROM.update(7,gain4);EEPROM.update(8,gain5);
     EEPROM.update(9,in_reg);EEPROM.update(10,out_gain_reg);EEPROM.update(11,att_rear);
     EEPROM.update(12,brig_h);EEPROM.update(13,brig_l);
     if(menu!=0){lcd.clear();menu=0;menu0=100;w=0;}}

  }// loop     
     
void audio(){Write(att_rear,super_bass_reg,bass_reg,treb_reg,80-vol_reg,gain0,in_reg,0,out_gain_reg,3,mute_reg);}
void cl(){ir.value=0;delay(300);lcd.clear();}
void cl1(){ir.value=0;delay(300);}
void vol_func(){if(vol_reg<0){vol_reg=0;}if(vol_reg>80){vol_reg=80;}}
void treb_func(){if(treb_reg<0){treb_reg=0;}if(treb_reg>14){treb_reg=14;}}
void bass_func(){if(bass_reg<0){bass_reg=0;}if(bass_reg>14){bass_reg=14;}}
void out_gain_func(){if(out_gain_reg<0){out_gain_reg=0;}if(out_gain_reg>2){out_gain_reg=2;}}
void super_bass_func(){if(super_bass_reg<0){super_bass_reg=0;}if(super_bass_reg>10){super_bass_reg=10;}}
void gain_func(){{if(gain0<0){gain0=0;}if(gain0>15){gain0=15;}}}
void rear_func(){{if(att_rear<0){att_rear=0;}if(att_rear>15){att_rear=15;}}}
void brig_h_func(){if(brig_h<0){brig_h=0;}if(brig_h>25){brig_h=25;}}
void brig_l_func(){if(brig_l<0){brig_l=0;}if(brig_l>25){brig_l=25;}}
void to_Timer(){newPosition = myEnc.read()/4;}  
 
void digit(){switch(a[x]){
case 0: d1=1,d2=8,d3=6,d4=1,d5=3,d6=6;break;case 1: d1=32,d2=2,d3=6,d4=32,d5=32,d6=6;break;
case 2: d1=2,d2=8,d3=6,d4=1,d5=4,d6=5;break;case 3: d1=2,d2=4,d3=6,d4=7,d5=3,d6=6;break;
case 4: d1=1,d2=3,d3=6,d4=32,d5=32,d6=6;break;case 5: d1=1,d2=4,d3=5,d4=7,d5=3,d6=6;break;
case 6: d1=1,d2=4,d3=5,d4=1,d5=3,d6=6;break;case 7: d1=1,d2=8,d3=6,d4=32,d5=32,d6=6;break;
case 8: d1=1,d2=4,d3=6,d4=1,d5=3,d6=6;break;case 9: d1=1,d2=4,d3=6,d4=7,d5=3,d6=6;break;}
lcd.setCursor(e1,0);lcd.write((uint8_t)d1);lcd.setCursor(e2,0);lcd.write((uint8_t)d2);lcd.setCursor(e3,0);lcd.write((uint8_t)d3);
lcd.setCursor(e1,1);lcd.write((uint8_t)d4);lcd.setCursor(e2,1);lcd.write((uint8_t)d5);lcd.setCursor(e3,1);lcd.write((uint8_t)d6);}


void Write(byte fader, byte sup_bass,byte bass, byte treb, int vol, byte in_gain,long in,long f_r,long out_gain,long c_set,long mute){  
 // fader 0...-60 ∞ dB >> byte 0...15 - ослабление тыл
 // sup_bass step0...step10 >> byte 0...10
 // bass step1...step15 >> byte 0...14
 // treb step1...step15 >> byte 0...14
 // vol 0...-79 ∞ dB >> int 0...81
 // in_gain 0...18.75 dB step 1.25dB >> int 0...15
 // in 1...5 >> int 1...5
 // f_r - Fader resr/front control >> int 0 >> не менять
 // out_gain 0, 6.5, 8.5 dB >> int 0...2
 // c_set >> int 0...3 >> 3 - не менять
 // mute >> 0 - off, 1 - on
 
  digitalWrite(CL,LOW);
  digitalWrite(CE,LOW);
  byte addr = 0b10000001;
     for(int i = 7; i >= 0; i--){
        digitalWrite(CL,LOW);
        digitalWrite(DI, (addr >> i) & 0x01);
        digitalWrite(CL,HIGH);
        }   
  digitalWrite(CE,HIGH);
     for(int i = 3; i >= 0; i--){
        digitalWrite(CL,LOW);
        digitalWrite(DI, (fader_m[fader] >> i) & 0x01);
        digitalWrite(CL,HIGH);
        }
     for(int i = 3; i >= 0; i--){
        digitalWrite(CL,LOW);
        digitalWrite(DI, (sup_bass_m[sup_bass] >> i) & 0x01); 
        digitalWrite(CL,HIGH);
        }                
     for(int i = 3; i >= 0; i--){
        digitalWrite(CL,LOW); 
        digitalWrite(DI, (tembr_m[bass] >> i) & 0x01);
        digitalWrite(CL,HIGH);
        } 
     for(int i = 3; i >= 0; i--){
        digitalWrite(CL,LOW);
        digitalWrite(DI, (tembr_m[treb] >> i) & 0x01);
        digitalWrite(CL,HIGH);
        } 
     for(int i = 7; i >= 0; i--){
        digitalWrite(CL,LOW); 
        digitalWrite(DI, (vol_m[vol] >> i) & 0x01);
        digitalWrite(CL,HIGH);
        }
     for(int i = 3; i >= 0; i--){
        digitalWrite(CL,LOW);
        digitalWrite(DI, (in_gain_m[in_gain] >> i) & 0x01);
        digitalWrite(CL,HIGH);
        } 
     long in1,in2,out_gain1,out_gain2;      
     switch(in){
      case 1: in1=0b00;in2=1;break;
      case 2: in1=0b10;in2=1;break;
      case 3: in1=0b01;in2=1;break;
      case 4: in1=0b11;in2=1;break;
      case 5: in1=0b00;in2=0;break;
      }
     switch(out_gain){
      case 0: out_gain1=0;out_gain2=1;break;
      case 1: out_gain1=1;out_gain2=0;break;
      case 2: out_gain1=1;out_gain2=1;break;
      } 
      
     long grup = (in1<<14)+(f_r<<13)+(out_gain1<<12)+(in2<<11)+(c_set<<9)+(mute<<8)+(out_gain2<<4);  
     for(int i = 15; i >= 0; i--){
        digitalWrite(CL,LOW); 
        digitalWrite(DI, (grup >> i) & 0x01); 
        digitalWrite(CL,HIGH); 
        }              
        digitalWrite(CL,LOW);
        digitalWrite(CE,LOW);
  }

3

Re: PT2319

#define CE 2
#define DI 3
#define CL 4

#define IR1 0x2FDF00F // main/setting menu
#define IR2 0x2FDB24D // button encoder
#define IR3 0x2FDB04F // mute
#define IR4 0x2FD906F // >>>
#define IR5 0x2FDF20D // <<<
#define IR6 0x2FD6A95 // INPUT
#define IR7 0x2FD00FF // POWER
#define IN1 0x2FD629D // IN1
#define IN2 0x2FD22DD // IN2
#define IN3 0x2FD40BF // IN3
#define IN4 0x2FDA25D // IN4
#define IN5 0x2FDE01F // IN5
#define POW10 0x2FDE21D // POWER TIME 10 MIN


#include <Wire.h> 
#include <LiquidCrystal_I2C.h> // http://forum.rcl-radio.ru/misc.php?action=pan_download&item=45&download=1
#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>
#include <IRremote.h>          // http://rcl-radio.ru/wp-content/uploads/2019/06/IRremote.zip
#include <DS3231.h>            // https://github.com/jarzebski/Arduino-DS3231/archive/master.zip

LiquidCrystal_I2C lcd(0x27,16,2);  // Устанавливаем дисплей
Encoder myEnc(8, 9);// DT, CLK
IRrecv irrecv(12); // указываем вывод модуля IR приемника
decode_results ir; 
DS3231 clock;RTCDateTime DateTime;

byte fader_m[16]={0b1111,0b0111,0b1011,0b0011,0b1101,0b0101,0b1001,0b0001,0b1110,0b0110,0b1010,0b0010,0b1100,0b0100,0b1000,0b0000};
byte sup_bass_m[11]={0b0000,0b1000,0b0100,0b1100,0b0010,0b1010,0b0110,0b1110,0b0001,0b1001,0b0101};
byte tembr_m[15]={0b1111,0b0111,0b1011,0b0011,0b1101,0b0101,0b1001,0b0000,0b1000,0b0100,0b1100,0b0010,0b1010,0b0110,0b1110};
byte in_gain_m[16]={0b0000,0b1000,0b0100,0b1100,0b0010,0b1010,0b0110,0b1110,0b0001,0b1001,0b0101,0b1101,0b0011,0b1011,0b0111,0b1111};
byte vol_m[81]={0b00100101,0b11000101,0b01000101,0b10000101,0b00111001,0b11011001,0b01011001,0b10011001,0b00101001,
                0b11001001,0b01001001,0b10001001,0b00110001,0b11010001,0b01010001,0b10010001,0b00100001,0b11000001,
                0b01000001,0b10000001,0b00111110,0b11011110,0b01011110,0b10011110,0b00101110,0b11001110,0b01001110,
                0b10001110,0b00110110,0b11010110,0b01010110,0b10010110,0b00100110,0b11000110,0b01000110,0b10000110,
                0b00111010,0b11011010,0b01011010,0b10011010,0b00101010,0b11001010,0b01001010,0b10001010,0b00110010,
                0b11010010,0b01010010,0b10010010,0b00100010,0b11000010,0b01000010,0b10000010,0b00111100,0b11011100,
                0b01011100,0b10011100,0b00101100,0b11001100,0b01001100,0b10001100,0b00110100,0b11010100,0b01010100,
                0b10010100,0b00100100,0b11000100,0b01000100,0b10000100,0b00111000,0b11011000,0b01011000,0b10011000,
                0b00101000,0b11001000,0b01001000,0b10001000,0b00110000,0b11010000,0b01010000,0b10010000,0b00000000};
byte v1[8] = {0b00111,0b00111,0b00111,0b00111,0b00111,0b00111,0b00111,0b00111};
byte v2[8] = {0b00111,0b00111,0b00000,0b00000,0b00000,0b00000,0b00000,0b00000};      
byte v3[8] = {0b00000,0b00000,0b00000,0b00000,0b00000,0b00000,0b11111,0b11111};
byte v4[8] = {0b11111,0b11111,0b00000,0b00000,0b00000,0b00000,0b11111,0b11111};
byte v5[8] = {0b11100,0b11100,0b00000,0b00000,0b00000,0b00000,0b11100,0b11100};
byte v6[8] = {0b11100,0b11100,0b11100,0b11100,0b11100,0b11100,0b11100,0b11100};
byte v7[8] = {0b00000,0b00000,0b00000,0b00000,0b00000,0b00000,0b00111,0b00111};
byte v8[8] = {0b11111,0b11111,0b00000,0b00000,0b00000,0b00000,0b00000,0b00000}; 

int menu0=100,menu,vol_reg,in_reg,treb_reg,bass_reg,super_bass_reg,gain0,gain1,gain2,gain3,gain4,gain5,out_gain_reg,att_rear,mute_reg;
byte a[6],d1,d2,d3,d4,d5,d6,e1,e2,e3,w,w2,x,www,gr1,gr2,power,w_pow,w_al,al_power_on=0;;
unsigned long times,oldPosition  = -999,newPosition,times1,times2;
int minut,secon,hour,brig_h=25,brig_l=5,pow10=0,alarm_hour,alarm_minut,alarm;

void setup() {
   irrecv.enableIRIn();lcd.init();lcd.backlight();clock.begin(); 
    //  clock.setDateTime(__DATE__, __TIME__); // Устанавливаем время на часах, основываясь на времени компиляции скетча
   lcd.createChar(1, v1);lcd.createChar(2, v2);lcd.createChar(3, v3);lcd.createChar(4, v4);
   lcd.createChar(5, v5);lcd.createChar(6, v6);lcd.createChar(7, v7);lcd.createChar(8, v8);
   pinMode(CE,OUTPUT);pinMode(DI,OUTPUT);pinMode(CL,OUTPUT);
   pinMode(10,INPUT);// encoder SW
   pinMode(11,INPUT_PULLUP);// input button
   pinMode(A0,INPUT_PULLUP);// menu set/main button
   pinMode(A1,INPUT_PULLUP);// mute button
   pinMode(A2,INPUT_PULLUP);// power button
   pinMode(6,OUTPUT);  // output led pwm
   pinMode(13,OUTPUT);  // output STANDBY pin
   digitalWrite(CL,LOW);digitalWrite(CE,LOW);digitalWrite(DI,LOW);
   MsTimer2::set(1, to_Timer);MsTimer2::start();
   if(EEPROM.read(100)!=0){for(int i=0;i<101;i++){EEPROM.update(i,0);}}// очистка памяти при первом включении  
   Serial.begin(9600);
   Write(0,0,0,0,0,0,0,0,0,0,0);delay(100);// clear register  
   vol_reg = EEPROM.read(0);treb_reg = EEPROM.read(1);bass_reg = EEPROM.read(2);super_bass_reg = EEPROM.read(3);
   gain1 = EEPROM.read(4);gain2 = EEPROM.read(5);gain3 = EEPROM.read(6);gain4 = EEPROM.read(7);gain5 = EEPROM.read(8);
   in_reg = EEPROM.read(9);out_gain_reg = EEPROM.read(10);out_gain_reg = EEPROM.read(10);att_rear = EEPROM.read(11);
   brig_h = EEPROM.read(12);brig_l = EEPROM.read(13);alarm_hour = EEPROM.read(14);alarm_minut = EEPROM.read(15);alarm = EEPROM.read(16);
   
   analogWrite(6, brig_h*10);
   audio();
}

void loop() {
  /// IR
  if ( irrecv.decode( &ir )) {Serial.print("0x");Serial.println( ir.value,HEX);irrecv.resume();times=millis();w=1;}// IR приемник - чтение, в мониторе порта отображаются коды кнопок
  if(ir.value==0){gr1=0;gr2=0;}// запрет нажатий не активных кнопок пульта  
  /// BUTTON 
  if((digitalRead(A2)==LOW||ir.value==IR7||pow10==1)&&power==0){power=1;pow10=0;cl();lcd.setCursor(3,0);lcd.print("POWER  OFF");menu=100;menu0=100;mute_reg=1;audio();analogWrite(6, brig_l*10);delay(3000);lcd.clear();}// power off
  if((digitalRead(A2)==LOW||ir.value==IR7||al_power_on==1)&&power==1){power=0;al_power_on=0;cl();lcd.setCursor(3,0);lcd.print("POWER   ON ");menu=0;menu0=100;mute_reg=0;audio();analogWrite(6, brig_h*10);delay(3000);lcd.clear();}// power on
  if(power==0){digitalWrite(13,HIGH);}else{digitalWrite(13,LOW);}
  if(power==0){
  if((digitalRead(10)==LOW||ir.value==IR2)&&menu0==100){menu++;menu0=100;cl();times=millis();w=1;if(menu>3){menu=0;}}
  if((digitalRead(10)==LOW||ir.value==IR2)&&menu==100){menu0++;menu=100;cl();times=millis();w=1;if(menu0>4){menu0=0;}}
  if((digitalRead(11)==LOW||ir.value==IR6)){in_reg++;cl();times=millis();w=1;if(in_reg>5){in_reg=1;}audio();lcd.setCursor(4,0);lcd.print("INPUT ");lcd.print(in_reg);delay(1000);cl();}
  if(ir.value==IN1){in_reg=1;cl();times=millis();w=1;audio();lcd.setCursor(4,0);lcd.print("INPUT ");lcd.print(in_reg);delay(1000);cl();}
  if(ir.value==IN2){in_reg=2;cl();times=millis();w=1;audio();lcd.setCursor(4,0);lcd.print("INPUT ");lcd.print(in_reg);delay(1000);cl();}
  if(ir.value==IN3){in_reg=3;cl();times=millis();w=1;audio();lcd.setCursor(4,0);lcd.print("INPUT ");lcd.print(in_reg);delay(1000);cl();}
  if(ir.value==IN4){in_reg=4;cl();times=millis();w=1;audio();lcd.setCursor(4,0);lcd.print("INPUT ");lcd.print(in_reg);delay(1000);cl();}
  if(ir.value==IN5){in_reg=5;cl();times=millis();w=1;audio();lcd.setCursor(4,0);lcd.print("INPUT ");lcd.print(in_reg);delay(1000);cl();}
  if((digitalRead(A0)==LOW||ir.value==IR1)&&menu<100){menu=100;menu0=0;gr1=0;gr2=0;cl();times=millis();w=1;lcd.setCursor(2,0);lcd.print("SETTING MENU");delay(1000);cl();}
  if((digitalRead(A0)==LOW||ir.value==IR1)&&menu0<100){menu0=100;menu=0;gr1=0;gr2=0;cl();times=millis();w=1;lcd.setCursor(3,0);lcd.print("MAIN MENU");delay(1000);cl();}
  if((digitalRead(A1)==LOW||ir.value==IR3)&&mute_reg==0){mute_reg=1;menu0=100;menu=0;cl();audio();}
  if((digitalRead(A1)==LOW||ir.value==IR3)&&mute_reg==1){mute_reg=0;menu0=100;menu=0;cl();audio();}
  if(ir.value==POW10){cl();times1=millis();w_pow=1;lcd.setCursor(2,0);lcd.print("POWER 10 MIN");delay(2000);cl();}
  }
  if(millis()-times1>600000&&w_pow==1){pow10=1;w_pow=0;}
////////////// VOLUME ///////////////////////////////////////////////////////////////////
 if(menu==0){
   if(ir.value==IR4){vol_reg++;gr1=1;gr2=0;cl1();times=millis();w=1;w2=1;vol_func();audio();}// кнопка > 
   if(ir.value==0xFFFFFFFF and gr1==1){vol_reg++;gr2=0;cl1();times=millis();w=1;w2=1;vol_func();audio();}// кнопка >>>>>>
   if(ir.value==IR5){vol_reg--;gr1=0;gr2=1;cl1();times=millis();w=1;w2=1;vol_func();audio();}// кнопка <
   if(ir.value==0xFFFFFFFF and gr2==1){vol_reg--;gr1=0;cl1();times=millis();w=1;w2=1;vol_func();audio();}// кнопка <<<<<<
   
   if (newPosition != oldPosition){oldPosition = newPosition;vol_reg=vol_reg+newPosition;myEnc.write(0);newPosition=0;times=millis();w=1;w2=1;vol_func();audio();}
   a[0]= vol_reg/10;a[1]=vol_reg%10;
   for(x=0;x<2;x++){switch(x){case 0: e1=10,e2=11,e3=12;break;case 1: e1=13,e2=14,e3=15;break;}digit();}
   if(mute_reg==0){lcd.setCursor(0,0);lcd.print("VOLUME");}else{lcd.setCursor(0,0);lcd.print("MUTE");}
   lcd.setCursor(0,1);lcd.print("INPUT ");lcd.print(in_reg);
   }
////////////// TREBLE ///////////////////////////////////////////////////////////////////
 if(menu==1){
   if(ir.value==IR4){treb_reg++;gr1=1;gr2=0;cl1();times=millis();w=1;w2=1;treb_func();audio();}// кнопка > 
   if(ir.value==0xFFFFFFFF and gr1==1){treb_reg++;gr2=0;cl1();times=millis();w=1;w2=1;treb_func();audio();}// кнопка >>>>>>
   if(ir.value==IR5){treb_reg--;gr1=0;gr2=1;cl1();times=millis();w=1;w2=1;treb_func();audio();}// кнопка <
   if(ir.value==0xFFFFFFFF and gr2==1){treb_reg--;gr1=0;cl1();times=millis();w=1;w2=1;treb_func();audio();}// кнопка <<<<<<
     
   if (newPosition != oldPosition){oldPosition = newPosition;treb_reg=treb_reg+newPosition;myEnc.write(0);newPosition=0;times=millis();w=1;w2=1;treb_func();
   audio();}
   a[0]= treb_reg/10;a[1]=treb_reg%10;
   for(x=0;x<2;x++){switch(x){case 0: e1=10,e2=11,e3=12;break;case 1: e1=13,e2=14,e3=15;break;}digit();}
   lcd.setCursor(0,0);lcd.print("TREBLE");lcd.setCursor(0,1);lcd.print("CONTROL");
   }  
////////////// BASS ///////////////////////////////////////////////////////////////////
 if(menu==2){
   if(ir.value==IR4){bass_reg++;gr1=1;gr2=0;cl1();times=millis();w=1;w2=1;bass_func();audio();}// кнопка > 
   if(ir.value==0xFFFFFFFF and gr1==1){bass_reg++;gr2=0;cl1();times=millis();w=1;w2=1;bass_func();audio();}// кнопка >>>>>>
   if(ir.value==IR5){bass_reg--;gr1=0;gr2=1;cl1();times=millis();w=1;w2=1;bass_func();audio();}// кнопка <
   if(ir.value==0xFFFFFFFF and gr2==1){bass_reg--;gr1=0;cl1();times=millis();w=1;w2=1;bass_func();audio();}// кнопка <<<<<<
     
   if (newPosition != oldPosition){oldPosition = newPosition;bass_reg=bass_reg+newPosition;myEnc.write(0);newPosition=0;times=millis();w=1;w2=1;bass_func();audio();}
   a[0]= bass_reg/10;a[1]=bass_reg%10;
   for(x=0;x<2;x++){switch(x){case 0: e1=10,e2=11,e3=12;break;case 1: e1=13,e2=14,e3=15;break;}digit();}
   lcd.setCursor(0,0);lcd.print("BASS");lcd.setCursor(0,1);lcd.print("CONTROL");
   }  
////////////// SUPER BASS ///////////////////////////////////////////////////////////////////
 if(menu==3){
   if(ir.value==IR4){super_bass_reg++;gr1=1;gr2=0;cl1();times=millis();w=1;w2=1;super_bass_func();audio();}// кнопка > 
   if(ir.value==0xFFFFFFFF and gr1==1){super_bass_reg++;gr2=0;cl1();times=millis();w=1;w2=1;super_bass_func();audio();}// кнопка >>>>>>
   if(ir.value==IR5){super_bass_reg--;gr1=0;gr2=1;cl1();times=millis();w=1;w2=1;super_bass_func();audio();}// кнопка <
   if(ir.value==0xFFFFFFFF and gr2==1){super_bass_reg--;gr1=0;cl1();times=millis();w=1;w2=1;super_bass_func();audio();}// кнопка <<<<<<
     
   if (newPosition != oldPosition){oldPosition = newPosition;super_bass_reg=super_bass_reg+newPosition;myEnc.write(0);newPosition=0;times=millis();w=1;w2=1;super_bass_func();audio();}
   a[0]= super_bass_reg/10;a[1]=super_bass_reg%10;
   for(x=0;x<2;x++){switch(x){case 0: e1=10,e2=11,e3=12;break;case 1: e1=13,e2=14,e3=15;break;}digit();}
   lcd.setCursor(0,0);lcd.print("SUPER BASS");lcd.setCursor(0,1);lcd.print("CONTROL");
   }   

////// MENU SET ///////////////////////////////////////////////////////////////////////////////////////////////////////
////////////// INPUT GAIN ///////////////////////////////////////////////////////////////////
 if(menu0==0){
  switch(in_reg){
     case 1: gain0 = gain1;break;
     case 2: gain0 = gain2;break;
     case 3: gain0 = gain3;break;
     case 4: gain0 = gain4;break;
     case 5: gain0 = gain5;break;}
     
   if(ir.value==IR4){gain0++;gr1=1;gr2=0;cl1();times=millis();w=1;w2=1;gain_func();audio();}// кнопка > 
   if(ir.value==0xFFFFFFFF and gr1==1){gain0++;gr2=0;cl1();times=millis();w=1;w2=1;gain_func();audio();}// кнопка >>>>>>
   if(ir.value==IR5){gain0--;gr1=0;gr2=1;cl1();times=millis();w=1;w2=1;gain_func();audio();}// кнопка <
   if(ir.value==0xFFFFFFFF and gr2==1){gain0--;gr1=0;cl1();times=millis();w=1;w2=1;gain_func();audio();}// кнопка <<<<<<
   
  if (newPosition != oldPosition){oldPosition = newPosition;gain0=gain0+newPosition;myEnc.write(0);newPosition=0;times=millis();www=1;w=1;gain_func();}
  switch(in_reg){
     case 1: gain1 = gain0;break;
     case 2: gain2 = gain0;break;
     case 3: gain3 = gain0;break;
     case 4: gain4 = gain0;break;
     case 5: gain5 = gain0;break;}  
     a[0]= gain0/10;a[1]=gain0%10;
   for(x=0;x<2;x++){switch(x){case 0: e1=10,e2=11,e3=12;break;case 1: e1=13,e2=14,e3=15;break;}digit();}
   if(www==1){audio();www=0;}
   lcd.setCursor(0,0);lcd.print("IN GAIN");
   lcd.setCursor(0,1);lcd.print("INPUT ");lcd.print(in_reg);}
////////////// OUT GAIN ///////////////////////////////////////////////////////////////////
 if(menu0==1){
   if(ir.value==IR4){out_gain_reg++;gr1=1;gr2=0;cl1();times=millis();w=1;w2=1;out_gain_func();audio();}// кнопка > 
   if(ir.value==0xFFFFFFFF and gr1==1){out_gain_reg++;gr2=0;cl1();times=millis();w=1;w2=1;out_gain_func();audio();}// кнопка >>>>>>
   if(ir.value==IR5){out_gain_reg--;gr1=0;gr2=1;cl1();times=millis();w=1;w2=1;out_gain_func();audio();}// кнопка <
   if(ir.value==0xFFFFFFFF and gr2==1){out_gain_reg--;gr1=0;cl1();times=millis();w=1;w2=1;out_gain_func();audio();}// кнопка <<<<<<
     
   if (newPosition != oldPosition){oldPosition = newPosition;out_gain_reg=out_gain_reg+newPosition;myEnc.write(0);newPosition=0;times=millis();w=1;w2=1;out_gain_func();audio();}
   a[0]= out_gain_reg;
   for(x=0;x<1;x++){switch(x){case 0: e1=13,e2=14,e3=15;;break;case 1: e1=13,e2=14,e3=15;break;}digit();}
   lcd.setCursor(0,0);lcd.print("OUT GAIN");
   } 
 ////////////// ATT REAR ///////////////////////////////////////////////////////////////////
 if(menu0==2){
   if(ir.value==IR4){att_rear++;gr1=1;gr2=0;cl1();times=millis();w=1;w2=1;rear_func();audio();}// кнопка > 
   if(ir.value==0xFFFFFFFF and gr1==1){att_rear++;gr2=0;cl1();times=millis();w=1;w2=1;rear_func();audio();}// кнопка >>>>>>
   if(ir.value==IR5){att_rear--;gr1=0;gr2=1;cl1();times=millis();w=1;w2=1;rear_func();audio();}// кнопка <
   if(ir.value==0xFFFFFFFF and gr2==1){att_rear--;gr1=0;cl1();times=millis();w=1;w2=1;rear_func();audio();}// кнопка <<<<<<
     
   if (newPosition != oldPosition){oldPosition = newPosition;att_rear=att_rear+newPosition;myEnc.write(0);newPosition=0;times=millis();w=1;w2=1;rear_func();audio();}
   a[0]= att_rear/10;a[1]=att_rear%10;
   for(x=0;x<2;x++){switch(x){case 0: e1=10,e2=11,e3=12;break;case 1: e1=13,e2=14,e3=15;break;}digit();}
   lcd.setCursor(0,0);lcd.print("ATT REAR");
   } 
 ////////////// BRIG_H  ///////////////////////////////////////////////////////////////////
 if(menu0==3){
   if(ir.value==IR4){brig_h++;gr1=1;gr2=0;cl1();times=millis();w=1;w2=1;brig_h_func();}// кнопка > 
   if(ir.value==0xFFFFFFFF and gr1==1){brig_h++;gr2=0;cl1();times=millis();w=1;w2=1;brig_h_func();}// кнопка >>>>>>
   if(ir.value==IR5){brig_h--;gr1=0;gr2=1;cl1();times=millis();w=1;w2=1;brig_h_func();}// кнопка <
   if(ir.value==0xFFFFFFFF and gr2==1){brig_h--;gr1=0;cl1();times=millis();w=1;w2=1;brig_h_func();}// кнопка <<<<<<
     
   if (newPosition != oldPosition){oldPosition = newPosition;brig_h=brig_h+newPosition;myEnc.write(0);newPosition=0;times=millis();w=1;w2=1;brig_h_func();}
   a[0]= brig_h/10;a[1]=brig_h%10;
   for(x=0;x<2;x++){switch(x){case 0: e1=10,e2=11,e3=12;break;case 1: e1=13,e2=14,e3=15;break;}digit();}
   lcd.setCursor(0,0);lcd.print("BRIG HIGH");
   }  
 ////////////// BRIG_L  ///////////////////////////////////////////////////////////////////
 if(menu0==4){
   if(ir.value==IR4){brig_l++;gr1=1;gr2=0;cl1();times=millis();w=1;w2=1;brig_l_func();}// кнопка > 
   if(ir.value==0xFFFFFFFF and gr1==1){brig_l++;gr2=0;cl1();times=millis();w=1;w2=1;brig_l_func();}// кнопка >>>>>>
   if(ir.value==IR5){brig_l--;gr1=0;gr2=1;cl1();times=millis();w=1;w2=1;brig_l_func();}// кнопка <
   if(ir.value==0xFFFFFFFF and gr2==1){brig_l--;gr1=0;cl1();times=millis();w=1;w2=1;brig_l_func();}// кнопка <<<<<<
     
   if (newPosition != oldPosition){oldPosition = newPosition;brig_l=brig_l+newPosition;myEnc.write(0);newPosition=0;times=millis();w=1;w2=1;brig_l_func();}
   a[0]= brig_l/10;a[1]=brig_l%10;
   for(x=0;x<2;x++){switch(x){case 0: e1=10,e2=11,e3=12;break;case 1: e1=13,e2=14,e3=15;break;}digit();}
   lcd.setCursor(0,0);lcd.print("BRIG LOW");
   }     
     

   /////////////////// TIME ///////////////////////////////////////////////////////////////////
DateTime = clock.getDateTime();hour = DateTime.hour;minut = DateTime.minute;secon = DateTime.second;   
if(power==1&&digitalRead(10)==HIGH){
     a[0]=DateTime.hour/10;
     a[1]=DateTime.hour%10;
     a[2]=DateTime.minute/10;
     a[3]=DateTime.minute%10;
     a[4]=DateTime.second/10;
     a[5]=DateTime.second%10;
   for(x=0;x<4;x++){
    switch(x){
        case 0: e1=0,e2=1,e3=2;break;
        case 1: e1=3,e2=4,e3=5;break;
        case 2: e1=7,e2=8,e3=9;break;
        case 3: e1=10,e2=11,e3=12;break;
   }digit();}
 
   lcd.setCursor(6,0);lcd.print(".");lcd.setCursor(6,1);lcd.print(".");
   lcd.setCursor(14,1);lcd.print(a[4]);lcd.setCursor(15,1);lcd.print(a[5]);   
//// set time ////
  if(digitalRead(11)==LOW){hour++;if(hour>23){hour=0;} clock.setDateTime(2020, 9, 15, hour, minut, secon);delay(100);}// input button
  if(digitalRead(A0)==LOW){minut++;if(minut>59){minut=0;} clock.setDateTime(2020, 9, 15, hour, minut, secon);delay(100); }// menu set/main button
  if(digitalRead(A1)==LOW){secon=0; clock.setDateTime(2020, 9, 15, hour, minut, secon);delay(100); }// mute button
}   

   /////////////////// ALARM ///////////////////////////////////////////////////////////////////
DateTime = clock.getDateTime();hour = DateTime.hour;minut = DateTime.minute;secon = DateTime.second;   
if(power==1&&digitalRead(10)==LOW){
     a[0]=alarm_hour/10;
     a[1]=alarm_hour%10;
     a[2]=alarm_minut/10;
     a[3]=alarm_minut%10;

   for(x=0;x<4;x++){
    switch(x){
        case 0: e1=0,e2=1,e3=2;break;
        case 1: e1=3,e2=4,e3=5;break;
        case 2: e1=7,e2=8,e3=9;break;
        case 3: e1=10,e2=11,e3=12;break;
   }digit();}
 
   lcd.setCursor(6,0);lcd.print(".");lcd.setCursor(6,1);lcd.print(".");
   lcd.setCursor(14,1);
   if(alarm==0)lcd.print("--"); 
   if(alarm==1)lcd.print("ON");   
//// set time ////
  if(digitalRead(11)==LOW){alarm_hour++;if(alarm_hour>23){alarm_hour=0;}times2=millis();w_al=1;delay(100);}// input button
  if(digitalRead(A0)==LOW){alarm_minut++;if(alarm_minut>59){alarm_minut=0;}times2=millis();w_al=1;delay(100); }// menu set/main button
  if(digitalRead(A1)==LOW&&alarm==0){alarm=1;delay(300);times2=millis();w_al=1;}// mute button
  if(digitalRead(A1)==LOW&&alarm==1){alarm=0;delay(300);times2=millis();w_al=1;}// mute button
}    

 if(secon==0&&alarm==1&&(hour*100+minut==alarm_hour*100+alarm_minut)){al_power_on=1;}
   
////////////////////////////////////////////////////////////////////////////////////////////
  if(millis()-times>10000 && w==1 && power==0){
     EEPROM.write(0,vol_reg);EEPROM.write(1,treb_reg);EEPROM.write(2,bass_reg);EEPROM.write(3,super_bass_reg);
     EEPROM.update(4,gain1);EEPROM.update(5,gain2);EEPROM.update(6,gain3);EEPROM.update(7,gain4);EEPROM.update(8,gain5);
     EEPROM.update(9,in_reg);EEPROM.update(10,out_gain_reg);EEPROM.update(11,att_rear);
     EEPROM.update(12,brig_h);EEPROM.update(13,brig_l);
     if(menu!=0){lcd.clear();menu=0;menu0=100;}
     w=0;
     }
  if(millis()-times2>10000 && w_al==1 && power==1){
     EEPROM.update(14,alarm_hour);EEPROM.update(15,alarm_minut);EEPROM.update(16,alarm);
     w_al=0;
    }   

  }// loop     
     
void audio(){Write(att_rear,super_bass_reg,bass_reg,treb_reg,80-vol_reg,gain0,in_reg,0,out_gain_reg,3,mute_reg);}
void cl(){ir.value=0;delay(300);lcd.clear();}
void cl1(){ir.value=0;delay(300);}
void vol_func(){if(vol_reg<0){vol_reg=0;}if(vol_reg>80){vol_reg=80;}}
void treb_func(){if(treb_reg<0){treb_reg=0;}if(treb_reg>14){treb_reg=14;}}
void bass_func(){if(bass_reg<0){bass_reg=0;}if(bass_reg>14){bass_reg=14;}}
void out_gain_func(){if(out_gain_reg<0){out_gain_reg=0;}if(out_gain_reg>2){out_gain_reg=2;}}
void super_bass_func(){if(super_bass_reg<0){super_bass_reg=0;}if(super_bass_reg>10){super_bass_reg=10;}}
void gain_func(){{if(gain0<0){gain0=0;}if(gain0>15){gain0=15;}}}
void rear_func(){{if(att_rear<0){att_rear=0;}if(att_rear>15){att_rear=15;}}}
void brig_h_func(){if(brig_h<0){brig_h=0;}if(brig_h>25){brig_h=25;}}
void brig_l_func(){if(brig_l<0){brig_l=0;}if(brig_l>25){brig_l=25;}}
void to_Timer(){newPosition = myEnc.read()/4;}  
 
void digit(){switch(a[x]){
case 0: d1=1,d2=8,d3=6,d4=1,d5=3,d6=6;break;case 1: d1=32,d2=2,d3=6,d4=32,d5=32,d6=6;break;
case 2: d1=2,d2=8,d3=6,d4=1,d5=4,d6=5;break;case 3: d1=2,d2=4,d3=6,d4=7,d5=3,d6=6;break;
case 4: d1=1,d2=3,d3=6,d4=32,d5=32,d6=6;break;case 5: d1=1,d2=4,d3=5,d4=7,d5=3,d6=6;break;
case 6: d1=1,d2=4,d3=5,d4=1,d5=3,d6=6;break;case 7: d1=1,d2=8,d3=6,d4=32,d5=32,d6=6;break;
case 8: d1=1,d2=4,d3=6,d4=1,d5=3,d6=6;break;case 9: d1=1,d2=4,d3=6,d4=7,d5=3,d6=6;break;}
lcd.setCursor(e1,0);lcd.write((uint8_t)d1);lcd.setCursor(e2,0);lcd.write((uint8_t)d2);lcd.setCursor(e3,0);lcd.write((uint8_t)d3);
lcd.setCursor(e1,1);lcd.write((uint8_t)d4);lcd.setCursor(e2,1);lcd.write((uint8_t)d5);lcd.setCursor(e3,1);lcd.write((uint8_t)d6);}


void Write(byte fader, byte sup_bass,byte bass, byte treb, int vol, byte in_gain,long in,long f_r,long out_gain,long c_set,long mute){  
 // fader 0...-60 ∞ dB >> byte 0...15 - ослабление тыл
 // sup_bass step0...step10 >> byte 0...10
 // bass step1...step15 >> byte 0...14
 // treb step1...step15 >> byte 0...14
 // vol 0...-79 ∞ dB >> int 0...81
 // in_gain 0...18.75 dB step 1.25dB >> int 0...15
 // in 1...5 >> int 1...5
 // f_r - Fader resr/front control >> int 0 >> не менять
 // out_gain 0, 6.5, 8.5 dB >> int 0...2
 // c_set >> int 0...3 >> 3 - не менять
 // mute >> 0 - off, 1 - on
 
  digitalWrite(CL,LOW);
  digitalWrite(CE,LOW);
  byte addr = 0b10000001;
     for(int i = 7; i >= 0; i--){
        digitalWrite(CL,LOW);
        digitalWrite(DI, (addr >> i) & 0x01);
        digitalWrite(CL,HIGH);
        }   
  digitalWrite(CE,HIGH);
     for(int i = 3; i >= 0; i--){
        digitalWrite(CL,LOW);
        digitalWrite(DI, (fader_m[fader] >> i) & 0x01);
        digitalWrite(CL,HIGH);
        }
     for(int i = 3; i >= 0; i--){
        digitalWrite(CL,LOW);
        digitalWrite(DI, (sup_bass_m[sup_bass] >> i) & 0x01); 
        digitalWrite(CL,HIGH);
        }                
     for(int i = 3; i >= 0; i--){
        digitalWrite(CL,LOW); 
        digitalWrite(DI, (tembr_m[bass] >> i) & 0x01);
        digitalWrite(CL,HIGH);
        } 
     for(int i = 3; i >= 0; i--){
        digitalWrite(CL,LOW);
        digitalWrite(DI, (tembr_m[treb] >> i) & 0x01);
        digitalWrite(CL,HIGH);
        } 
     for(int i = 7; i >= 0; i--){
        digitalWrite(CL,LOW); 
        digitalWrite(DI, (vol_m[vol] >> i) & 0x01);
        digitalWrite(CL,HIGH);
        }
     for(int i = 3; i >= 0; i--){
        digitalWrite(CL,LOW);
        digitalWrite(DI, (in_gain_m[in_gain] >> i) & 0x01);
        digitalWrite(CL,HIGH);
        } 
     long in1,in2,out_gain1,out_gain2;      
     switch(in){
      case 1: in1=0b00;in2=1;break;
      case 2: in1=0b10;in2=1;break;
      case 3: in1=0b01;in2=1;break;
      case 4: in1=0b11;in2=1;break;
      case 5: in1=0b00;in2=0;break;
      }
     switch(out_gain){
      case 0: out_gain1=0;out_gain2=1;break;
      case 1: out_gain1=1;out_gain2=0;break;
      case 2: out_gain1=1;out_gain2=1;break;
      } 
      
     long grup = (in1<<14)+(f_r<<13)+(out_gain1<<12)+(in2<<11)+(c_set<<9)+(mute<<8)+(out_gain2<<4);  
     for(int i = 15; i >= 0; i--){
        digitalWrite(CL,LOW); 
        digitalWrite(DI, (grup >> i) & 0x01); 
        digitalWrite(CL,HIGH); 
        }              
        digitalWrite(CL,LOW);
        digitalWrite(CE,LOW);
  }