76

Re: PT2314

щелчёк победил

if (ir.value == IR_9)  {in = 0;mute=1;digitalWrite(11,HIGH);
gr1 = 0;gr2 = 0;cl();times = millis();w = 1;w2 = 1;audio();lcd.setCursor(3, 0);lcd.print(" Bluetooth");delay(1500);}
     if (ir.value == IR_10) {in = 1;mute=1;digitalWrite(13,HIGH);
gr1 = 0;gr2 = 0;cl();times = millis();w = 1;w2 = 1;audio();lcd.setCursor(3, 0);lcd.print("  RADIO");delay(1500);}

ВСЕМ спасибо, удачи.

77

Re: PT2314

Повторил устройство, спасибо автору, все вполне достойно работает. Добавил выбор входов с отдельных кнопок и выключение через 10 мин. Звук при срабатывании 10 мин задержки и переходе в повер офф не пропадает, это и хорошо, гасится экран, не светит впустую. Навело на мысль, что экран хорошо бы должен притухать после минуты простоя с выводом часов и подниматься в рабочий режим с любой кнопки пульта или механики. Но можно оставить все так как есть. Ток подсветки моего экрана был около 70ма, отпаял подтягивающий резистор 4.7к на 7 ножке чипа на плате i2c и на базу управляющего транзистора, через 1.8к подал управление. Отпаивать 7 ногу не стал, работает хорошо, заметно начинает светить со значения 20 и до максимума при значении 255.
http://forum.rcl-radio.ru/uploads/images/2021/09/849a91edb2a5901d9f689799c0202cd4.jpg
Аудиопроцессор был голый, распаял на макетке sop28, обвязку выполнил на пленочных конденсаторах поверх монтажа, получилось малогабаритно.
http://forum.rcl-radio.ru/uploads/images/2021/09/fb2791b519187af9f582db1245d57c33.jpg

78

Re: PT2314

Здравствуйте, а можно ли из скетча исключить пульт и анализатор?

Надеюсь, мой вопрос имеет смысл, я использую Google Переводчик.

Спасибо за ваш проект.

79

Re: PT2314

Укажите ссылку на скетч.

80

Re: PT2314

http://forum.rcl-radio.ru/viewtopic.php?pid=1084#p1084
Набросок из поста №3. По какой-то причине код не работает, если я не подключаю пульт.

81

Re: PT2314

Я убрал лишнее, не тестировал.

 #include <Wire.h> 
#include <PT2314.h>
#include <Wire.h> 
#include <LiquidCrystal.h>
//#include <LiquidCrystal_I2C.h> 
#include <Encoder.h>            
#include <EEPROM.h>
#include <MsTimer2.h>           
#include <DS3231.h>
   DS3231 clock;RTCDateTime DateTime;
   PT2314 pt;
   //LiquidCrystal_I2C lcd(0x27,20,4);  // Устанавливаем дисплей
   LiquidCrystal lcd(7, 6, 2, 3, 4, 5);// RS,E,D4,D5,D6,D7 подключение LCD
   Encoder myEnc(11, 10);// DT, CLK
      int menu,menu0,menu1,vol,bass,treb,in,balans,balans_d,vol_d,bass_d,treb_d,temp0,par,hour,minut,secon,z_old,gain0,loud;
      int att_r,att_l,gain1,gain2,gain3,gain4,brig0,brig1;
      byte w2[4],z,z0,z1,n,q,gr1,gr2,www,i,w,mute,power,in_x,save,i1,pin,pin2,hms,irr;
      unsigned long time0,times_in;
      unsigned int oldPosition  = -999,newPosition;
    const PROGMEM   byte mesto2[4]={0,11,0,11};
    const PROGMEM   byte mesto3[4]={0,0,1,1};
   unsigned long gainTimer;
   byte maxValue, maxValue_f,spek;
   int i2;
   int ek;


void setup() {
  lcd.begin(20, 4);
  //lcd.init();lcd.backlight();
  clock.begin();
  Serial.begin(9600);
  pinMode(12,INPUT);  // МЕНЮ КНОПКА SW энкодера
  pinMode(8,INPUT);   // КНОПКА IN
  pinMode(9,INPUT);   // КНОПКА STANDBY / MUTE
  pinMode(13,OUTPUT); // ВЫХОД УПРАВЛЕНИЯ STANDBY
  lcd.setCursor(1,1);lcd.print("Sound Processor");lcd.setCursor(1,2);lcd.print("PT2314"); delay(2000);lcd.clear();
  MsTimer2::set(3, to_Timer);MsTimer2::start();
  //  clock.setDateTime(__DATE__, __TIME__); // Устанавливаем время на часах, основываясь на времени компиляции скетча
  if(EEPROM.read(100)!=0){for(int i=0;i<101;i++){EEPROM.update(i,0);}}// очистка памяти при первом включении  
  vol = EEPROM.read(0);treb = EEPROM.read(1)-7;bass = EEPROM.read(2)-7;in = EEPROM.read(3);
  att_l = EEPROM.read(4);att_r = EEPROM.read(5);gain1 = EEPROM.read(6);gain2 = EEPROM.read(7);
  gain3 = EEPROM.read(8);gain4 = EEPROM.read(9);loud = EEPROM.read(10);ek = EEPROM.read(13);
  w2_arr();audio();cl();
}

void loop() {
  DateTime = clock.getDateTime();hour = DateTime.hour;minut = DateTime.minute;secon = DateTime.second;
  if (newPosition != oldPosition||digitalRead(12)==LOW) {if(spek==1){cl();spek=0;w=0;menu0=0;menu=0;w2_arr();time0=millis();w=1;}}

/////////////////////////////// УПРАВЛЕНИЕ //////////////////////////////////////////////



  if(mute==0&&power==0){ 
  if(menu0==0){menu++;gr1=0;gr2=0;cl1();time0=millis();w=1;w2_arr();if(menu>2){menu=0;}}//меню 1
  if(menu0==0){menu--;gr1=0;gr2=0;cl1();time0=millis();w=1;w2_arr();if(menu<0){menu=2;}}//меню 1
 
  if(menu0==1){menu1++;gr1=0;gr2=0;cl1();time0=millis();w=1;if(menu1>3){menu1=0;}}//меню 2
  if(menu0==1){menu1--;gr1=0;gr2=0;cl1();time0=millis();w=1;if(menu1<0){menu1=3;}}//меню 2

  if(digitalRead(12)==LOW){pin2++;}if(digitalRead(12)==HIGH){pin2=0;}
  if(digitalRead(12)==LOW&&menu0==0){menu++;delay(200);time0=millis();w=1;w2_arr();if(menu>2){menu=0;}}// меню 0
  if(digitalRead(12)==LOW&&menu0==1){menu1++;delay(200);time0=millis();w=1;if(menu1>3){menu1=0;}}// меню 1
  
  if((pin2>5)&&menu0==0){pin2=0;menu0=1;cl();time0=millis();w=1;lcd.setCursor(6,1);lcd.print("SETTING"); delay(2000);lcd.clear();}
  if((pin2>5)&&menu0==1){pin2=0;menu0=0;menu=0;cl();w2_arr();time0=millis();w=1;lcd.setCursor(8,1);lcd.print("MENU"); delay(2000);lcd.clear();}
  
  if(digitalRead(8)==HIGH){in++;cl();time0=millis();w=1;times_in=millis();in_x=1;www=1;w=1;menu0=100;if(in>3){in=0;}}// IN
  }

  if(digitalRead(9)==HIGH){delay(5);pin++;}
  if((pin>0&&pin<10&&digitalRead(9)==LOW)&&mute==0&&power==0){pin=0;mute=1;pt.setAttR(31);pt.setAttL(31);menu0=100;cl();w=1;w2_arr();lcd.setCursor(8,1);lcd.print("MUTE");delay(300);}// mute on
  if((pin>0&&pin<10&&digitalRead(9)==LOW)&&mute==1&&power==0){pin=0;mute=0;cl();time0=millis();w=1;w2_arr();menu0=0;myEnc.write(0);audio();}// mute off

  if((pin>10)&&power==0){pin=0;power=1;save=1;pt.setAttR(31);pt.setAttL(31);cl();lcd.setCursor(5,1);lcd.print("POWER  OFF");menu0=100;delay(3000);}// power off
  if((pin>0)&&power==1){pin=0;power=0;lcd.clear();lcd.setCursor(5,1);lcd.print("POWER   ON ");time0=millis();w=1;w2_arr();menu0=0;myEnc.write(0);audio();delay(3000);cl();}// power on
/////////////////////////////////////////////////////////////////////////////////////////////

if(power==0){digitalWrite(13,HIGH);
   if(spek==0){
   byte v1[8] = {0b00000,0b10101,0b10101,0b10101,0b10101,0b10101,0b10101,0b00000};
   byte v2[8] = {0b00000,0b10100,0b10100,0b10100,0b10100,0b10100,0b10100,0b00000};
   byte v3[8] = {0b00000,0b10000,0b10000,0b10000,0b10000,0b10000,0b10000,0b00000}; 
   byte v4[8] = {0b10000,0b11000,0b11100,0b11110,0b11100,0b11000,0b10000,0b00000}; //>
   byte v5[8] = {0b00000,0b00000,0b00000,0b00000,0b00000,0b00000,0b00000,0b00000};
   lcd.createChar(0,v1);lcd.createChar(1,v2);lcd.createChar(2,v3);lcd.createChar(3,v4);lcd.createChar(4,v5);}
  }
  if(power==1){digitalWrite(13,LOW);
      byte v1[8] = {7,7,7,7,7,7,7,7};
      byte v2[8] = {7,7,0, 0, 0, 0, 0, 0};      
      byte v3[8] = { 0, 0, 0, 0, 0,0,31,31};
      byte v4[8] = {31,31, 0, 0, 0, 0,31,31};
      byte v5[8] = { 28, 28, 0, 0, 0, 0, 28, 28};
      byte v6[8] = {28,28,28,28,28,28,28,28};
      byte v7[8] = { 0, 0, 0, 0, 0, 0,7,7};
      byte v8[8] = { 31, 31,0,0,0,0,0, 0};
   byte a[6];
   byte i0,d1,d2,d3,d4,d5,d6,e1,e2,e3;
  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);
  
     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(i=0;i<6;i++){
      switch(i){
        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;
        case 4: e1=14,e2=15,e3=16;break;
        case 5: e1=17,e2=18,e3=19;break;
        }
      switch(a[i]){
        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);
  }
  lcd.setCursor(6,0);lcd.print(".");lcd.setCursor(13,0);lcd.print(".");lcd.setCursor(6,1);lcd.print(".");lcd.setCursor(13,1);lcd.print(".");
  lcd.setCursor(5,3);lcd.print("POWER  OFF");
//// set time //////
  if(digitalRead(12)==LOW){hms++;cl();delay(200);if(hms>3){hms=0;}}
  switch(hms){
    case 1: lcd.setCursor(1,2);lcd.print("------");break;
    case 2: lcd.setCursor(7,2);lcd.print("------");break;
    case 3: lcd.setCursor(14,2);lcd.print("------");break;
    }
  if(digitalRead(8)==HIGH&&hms==1){hour++;if(hour>23){hour=0;} clock.setDateTime(2020, 9, 15, hour, minut, secon);delay(100);}
  if(digitalRead(8)==HIGH&&hms==2){minut++;if(minut>59){minut=0;} clock.setDateTime(2020, 9, 15, hour, minut, secon);delay(100); }
  if(digitalRead(8)==HIGH&&hms==3){secon=0; clock.setDateTime(2020, 9, 15, hour, minut, secon);hms=0; }
  } 

 /////////////////////////////// MENU0 = VOLUME TERBLE BASS BALANCE ///////////////////////////////////////////////////////////////////////
  if(menu0==0){
    switch(menu){
      case 0: temp0 = vol;q=0;break;
      case 1: temp0 = bass;q=1;break;
      case 2: temp0 = treb;q=2;break;}

 
   if (newPosition != oldPosition){oldPosition = newPosition;
     temp0=temp0+newPosition;myEnc.write(0);newPosition=0;time0=millis();w=1;w2[q]=1;www=1;} 
 
     switch(menu){
      case 0: vol = temp0;vol_func();break;
      case 1: bass = temp0;bass_func();break;
      case 2: treb = temp0;treb_func();break;}
 
   au();
   for(i=0;i<3;i++){if(menu==i){lcd.setCursor(0,i);lcd.write((uint8_t)3);}else{lcd.setCursor(0,i);lcd.print(" ");}}
   lcd.setCursor(1,0);lcd.print("VOLUME ");if(vol>=0){lcd.print(" ");}lcd.print(vol);lcd.print(" ");vol_d=map(vol,0,56,1,24);
   lcd.setCursor(1,1);lcd.print("BASS   ");if(bass>=0){lcd.print(" ");}lcd.print(bass);lcd.print(" ");bass_d=map(bass,-7,7,1,24);
   lcd.setCursor(1,2);lcd.print("TREBLE ");if(treb>=0){lcd.print(" ");}lcd.print(treb);lcd.print(" ");treb_d=map(treb,-7,7,1,24);
   lcd.setCursor(1,3);lcd.print("INPUT   ");lcd.print(in+1);lcd.print("  ");
   lcd.print(DateTime.hour/10);lcd.print(DateTime.hour%10);lcd.print(":");lcd.print(DateTime.minute/10);lcd.print(DateTime.minute%10);lcd.print(":");
   lcd.print(DateTime.second/10);lcd.print(DateTime.second%10);

   for(n=0;n<3;n++){if(w2[n]==1){
   switch(n){
    case 0: par = vol_d;break;
    case 1: par = bass_d;break;
    case 2: par = treb_d;break;} 
   
   for(z=0,z0=0,z1=0;z<=par;z++,z1++){if(z1>2){z1=0;z0++;}
   if(z1==1){lcd.setCursor(z0+12,n);lcd.write((uint8_t)0);lcd.setCursor(z0+1+12,n);Serial.println(z0);z_old=7-par/3;while(z_old>0){z_old=z_old-1;lcd.write((uint8_t)4);}}}
   if(z1==3){lcd.setCursor(z0+12,n);lcd.write((uint8_t)1);}
   if(z1==2){lcd.setCursor(z0+12,n);lcd.write((uint8_t)2);}w2[n]=0;}
   }}// menu0 = 0
///////////////////////////////////////////////////////////////////////////////////////////////

 if(menu0==1){
     switch(menu1){
      case 0: temp0 = att_l;break;
      case 1: temp0 = att_r;break;
      case 2: temp0 = loud;break;
      case 3: temp0 = ek;break;
      }
 
   if (newPosition != oldPosition){oldPosition = newPosition;
     temp0=temp0+newPosition;myEnc.write(0);newPosition=0;time0=millis();w=1;www=1;} 
 
     switch(menu1){
      case 0: att_l = temp0;att_l_func();break;
      case 1: att_r = temp0;att_r_func();break;
      case 2: loud  = temp0;loud_func();break;
      case 3: ek  = temp0;ek_func();break;
      }
 
  au();
  for(i=0;i<4;i++){if(menu1==i){lcd.setCursor(pgm_read_byte(&mesto2[i]),pgm_read_byte(&mesto3[i]));lcd.write((uint8_t)3);}else{lcd.setCursor(pgm_read_byte(&mesto2[i]),pgm_read_byte(&mesto3[i]));lcd.print(" ");}}
  
  lcd.setCursor(1,0);lcd.print("ATT_L ");lcd.print(att_l);lcd.print(" ");lcd.setCursor(12,0);lcd.print("ATT_R ");lcd.print(att_r);lcd.print(" ");
  lcd.setCursor(1,1);lcd.print("LOUD ");if(loud==0){lcd.print("OFF");}else{lcd.print("ON ");}lcd.setCursor(12,1);lcd.print("SPEK  ");lcd.print(ek);
  
 } // menu0 = 1


////////////////////////// GAIN IN /////////////////////////////////////////////////////////////////////////////////////
if(in_x==1){ menu0=100;
   switch(in){
     case 0: gain0 = gain1;break;
     case 1: gain0 = gain2;break;
     case 2: gain0 = gain3;break;
     case 3: gain0 = gain4;break;}

    if (newPosition != oldPosition) {oldPosition = newPosition;
    gain0=gain0+newPosition;myEnc.write(0);newPosition=0;time0=millis();times_in=millis();www=1;w=1;gain_func();} 
 
   switch(in){
     case 0: gain1 = gain0;break;
     case 1: gain2 = gain0;break;
     case 2: gain3 = gain0;break;
     case 3: gain4 = gain0;break;}
 
  au();
  lcd.setCursor(5,1);lcd.print("Gain IN ");lcd.print(in+1);lcd.setCursor(6,2);lcd.print(float(gain0*3.75));lcd.print(" ");lcd.print("dB ");
   }
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////   

if(millis()-time0>10000&&w==1&&mute==0&&power==0){cl();w=0;spek=0;menu0=100;}
if(millis()-times_in>3000&&in_x==1&&mute==0&&power==0){cl();in_x=0;menu0=0;menu=0;w2_arr();}

if(save==1){save=0;
     EEPROM.update(0,vol);EEPROM.update(1,treb+7);EEPROM.update(2,bass+7);EEPROM.update(3,in);
     EEPROM.update(4,att_l);EEPROM.update(5,att_r);EEPROM.update(6,gain1);EEPROM.update(7,gain2);
     EEPROM.update(8,gain3);EEPROM.update(9,gain4);EEPROM.update(10,loud);EEPROM.update(13,ek);}



     
}// loop

void ek_func(){if(ek>5){ek=5;}if(ek<0){ek=0;}}
void w2_arr(){w2[0]=1;w2[1]=1;w2[2]=1;w2[3]=1;}
void au(){if(www==1){audio();www=0;}}
void in_func(){if(in>3){in=3;}if(in<0){in=0;}}
void loud_func(){if(loud<0){loud=0;}if(loud>1){loud=1;}}
void gain_func(){if(gain0<0){gain0=0;}if(gain0>3){gain0=3;}}
void att_r_func(){if(att_r<0){att_r=0;}if(att_r>24){att_r=24;}}
void att_l_func(){if(att_l<0){att_l=0;}if(att_l>24){att_l=24;}}
void treb_func(){if(treb<-7){treb=-7;}if(treb>7){treb=7;}}
void bass_func(){if(bass<-7){bass=-7;}if(bass>7){bass=7;}}
void vol_func(){if(vol<0){vol=0;}if(vol>56){vol=56;}}
void cl(){spek=0;delay(300);lcd.clear();}
void cl1(){spek=0;delay(200);}  
void audio(){
  pt.setVolume(vol); // int 0...56 === -70...0 dB step 1.25 dB
  pt.setAttL(att_l); // int 0...24 === 0...-30 db step 1.25 dB > int 31 === mute on     
  pt.setAttR(att_r); // int 0...24 === 0...-30 dB step 1.25 dB > int 31 === mute on
  pt.setSwitch(in, loud, gain0); 
        // input      int 0..3 === IN 1...4 
        // loudness   int 0...1 === 1-on 0-off
        // input gain int 0...3 === 0...11.25dB step 3.75 dB
  pt.setBass(bass);   // int -7...+7 === -14...+14 dB step 2 dB
  pt.setTreble(treb); // int -7...+7 === -14...+14 dB step 2 dB
  }

void to_Timer(){newPosition = myEnc.read()/4;}

82

Re: PT2314

Доброе утро.

Чтобы меню работало правильно, мне пришлось установить контакт 12 как PULLUP.

У меня были проблемы с компилированием после удаления FHT самостоятельно, но ваш скетч помог.  Теперь, по прошествии некоторого времени, экран становится пустым, что заставляет меня думать, что он каким-то образом ждет ввода анализатора (если это имеет смысл).  В любом случае, теперь, когда он компилируется, я думаю, что разберусь с этим.

Еще раз спасибо и извините за переводчика.

83 (2022-07-14 00:29:21 отредактировано msanfelipe133)

Re: PT2314

Привет. Проект с PT 2314 плюс lcd 1602 плюс rtc3231 работал корректно. Я хотел бы добавить будильник, а также 10-минутное отключение. Можете ли вы отправить мне код. Спасибо . Привет. Отправить эскиз.

#define IR_1 0xFF906F//0x2FDD02F // mas BOTON ARRIBA
#define IR_2 0xFFA857//0x2FD32CD // menos BOTON ABAJO
#define IR_3 0xFF02FD//0x2FD906F // retro BOTON >
#define IR_4 0xFFC23D//0x2FDF20D // avance BOTON <
#define IR_5 0xFF22DD//0x2FD708F // pausa BOTON IN
#define IR_6 0xFF629D//0x2FD6A95 // modo BOTON SET
#define IR_7 0xFFE21D//0x2FD00FF // silencio BOTON MUTE
#define IR_8 0xFFA25D//0x2FDB24D // power BOTON STANDBY ENCENDIDO(POWER)
#define BRIG 50        // Brillo de la retroiluminación de la pantalla en modo APAGADO POWER OFF (0...255)

#include <Wire.h> 
#include <PT2314.h>            // [url]http://forum.rcl-radio.ru/misc.php?action=pan_download&item=434&download=1[/url]
#include <Wire.h> 
#include <LiquidCrystal_I2C.h> // [url]http://forum.rcl-radio.ru/misc.php?action=pan_download&item=45&download=1[/url]
#include <Encoder.h>           // [url]http://rcl-radio.ru/wp-content/uploads/2019/05/Encoder.zip[/url]       
#include <EEPROM.h>
#include <MsTimer2.h>          // [url]http://rcl-radio.ru/wp-content/uploads/2018/11/MsTimer2.zip[/url] 
#include <boarddefs.h>
#include <IRremote.h>          // [url]http://rcl-radio.ru/wp-content/uploads/2019/06/IRremote.zip[/url]
#include <DS3231.h>            // [url]https://github.com/jarzebski/Arduino-DS3231/archive/master.zip[/url]
   DS3231 clock;RTCDateTime DateTime;
   PT2314 pt;
   LiquidCrystal_I2C lcd (0x3F,16,2);//(0x27,16,2)  Instalación de la pantalla
   IRrecv irrecv(12); // especificar la salida del módulo receptor IR
   Encoder myEnc(8, 9);// DT, CLK
   decode_results ir; 
      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};
      byte a[6],d1,d2,d3,d4,d5,d6,e1,e2,e3,w,w2,i,www,power,save,gr1,gr2;
      int menu,menu0,menu1=1,menu2=0,vol,bass,treb,att_l,att_r,in,loud_on,gain0,gain1,gain2,gain3,gain4,mute,mute1,mute2,brig,hour,minut,secon;
      unsigned long times,oldPosition  = -999,newPosition;

void setup() {
  irrecv.enableIRIn();lcd.begin();lcd.clear();lcd.backlight();clock.begin();Serial.begin(9600);
  pinMode(10,INPUT);  // BOTÓN SW DEL CODIFICADOR MENÚ
  pinMode(2,INPUT);   // BOTON SET
  pinMode(3,INPUT);   // BOTON IN
  pinMode(4,INPUT);   // BOTON MUTE
  pinMode(5,INPUT);   // BOTON STANDBY
  pinMode(7,OUTPUT);  // SALIDA DE CONTROL STANDBY
  pinMode(6,OUTPUT);  // SALIDA DE CONTROL DE LUCES
  analogWrite(6, 255);
  lcd.setCursor(0,0);lcd.print("Sound Processor");lcd.setCursor(0,1);lcd.print("PT2314"); delay(2000);lcd.clear();
  MsTimer2::set(1, to_Timer);MsTimer2::start();
   //clock.setDateTime(2022, 7, 3, 13, 53, 00); // Establezca la hora del reloj en función del tiempo de compilación del boceto
  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);
  if(EEPROM.read(100)!=0){for(int i=0;i<101;i++){EEPROM.update(i,0);}}// borrar memoria en el primer arranque  
  vol = EEPROM.read(0);treb = EEPROM.read(1)-7;bass = EEPROM.read(2)-7;in = EEPROM.read(3);
  att_l = EEPROM.read(4);att_r = EEPROM.read(5);gain1 = EEPROM.read(6);gain2 = EEPROM.read(7);
  gain3 = EEPROM.read(8);gain4 = EEPROM.read(9);loud_on = EEPROM.read(10);brig = EEPROM.read(11);
  audio();
  analogWrite(6, brig);
  power=1;pt.setAttR(31);pt.setAttL(31);lcd.clear();lcd.setCursor(3,0);lcd.print("POWER  OFF");menu0=0;menu1=0;menu2=0;save=1;analogWrite(6, 50);
  //Agregado para cuando reinicie , se ponga en power off,REVISAR CON SONIDO PARA VER EL FUNCIONAMIENTO
  }
 
void loop() {
  
  DateTime = clock.getDateTime();hour = DateTime.hour;minut = DateTime.minute;secon = DateTime.second;
 
////////////////////// IR ///////////////////////////////////////////////////////////////
  if ( irrecv.decode( &ir )) {Serial.print("0x");Serial.println( ir.value,HEX);irrecv.resume();times=millis();w=1;}// Receptor IR: lectura, los códigos de los botones se muestran en el monitor del puerto
  if(ir.value==0){gr1=0;gr2=0;}// prohibición de presionar botones inactivos en el control remoto  
 
    if(mute==0&&power==0){
  if(ir.value==IR_6&&menu1==1){menu1=0;menu2=1;gr1=0;gr2=0;cl();times=millis();w=1;w2=1;lcd.setCursor(4,0);lcd.print("SETTING"); delay(2000);lcd.clear();}
  if(ir.value==IR_6&&menu2==1){menu1=1;menu2=0;menu=0;gr1=0;gr2=0;cl();times=millis();w=1;w2=1;lcd.setCursor(6,0);lcd.print("MENU"); delay(2000);lcd.clear();}
 
  if(ir.value==IR_1&&menu1==1){menu++;gr1=0;gr2=0;cl();times=millis();w=1;w2=1;if(menu>2){menu=0;}}//MENU 1
  if(ir.value==IR_2&&menu1==1){menu--;gr1=0;gr2=0;cl();times=millis();w=1;w2=1;if(menu<0){menu=2;}}//MENU 1
 
  if(ir.value==IR_1&&menu2==1){menu0++;gr1=0;gr2=0;cl();times=millis();w=1;w2=1;if(menu0>4){menu0=0;}}//MENU 2
  if(ir.value==IR_2&&menu2==1){menu0--;gr1=0;gr2=0;cl();times=millis();w=1;w2=1;if(menu0<0){menu0=4;}}//MENU 2
 
  if(ir.value==IR_5){in++;gr1=0;gr2=0;cl();times=millis();w=1;w2=1;if(in>3){in=0;}lcd.setCursor(4,0);switch(in){
  case 0: lcd.print("BT  ");break;
  case 1: lcd.print("AUX1  ");break;
  case 2: lcd.print("AUX2  ");break;
  case 3: lcd.print("MP3  ");break;
  // и так далее
  };audio();delay(2000);lcd.clear();}// IN
  }
 
  if(ir.value==IR_7&&mute==0&&power==0){mute=1;pt.setAttR(31);pt.setAttL(31);gr1=0;gr2=0;cl();lcd.setCursor(6,0);lcd.print("MUTE");menu1=100;menu2=100;delay(500);}// MUTE
  if(ir.value==IR_7&&mute==1&&power==0){mute=0;cl();menu1=1;menu=0;gr1=0;gr2=0;cl();audio();}// MUTE
 
  if(ir.value==IR_8&&power==0){power=1;pt.setAttR(31);pt.setAttL(31);audio();gr1=0;gr2=0;cl();lcd.clear();lcd.setCursor(3,0);lcd.print("POWER  OFF");menu0=0;menu1=0;menu2=0;save=1;analogWrite(6, BRIG);delay(3000);lcd.clear();}// power off
  if(ir.value==IR_8&&power==1){power=0;gr1=0;gr2=0;cl();lcd.backlight();lcd.clear();lcd.setCursor(3,0);lcd.print("POWER   ON ");menu1=1;menu=0;myEnc.write(0);audio();analogWrite(6, brig);delay(3000);lcd.clear();}// power on
///////////////////////////////////////////////////////////////////////////////////////// 
 
/////////////////////////////// CONTROL //////////////////////////////////////////////  
  if(mute==0&&power==0){
  if(digitalRead(2)==HIGH&&menu1==1){menu1=0;menu2=1;cl();times=millis();w=1;w2=1;lcd.setCursor(4,0);lcd.print("SETTING"); delay(2000);lcd.clear();}
  if(digitalRead(2)==HIGH&&menu2==1){menu1=1;menu2=0;menu=0;cl();times=millis();w=1;w2=1;lcd.setCursor(6,0);lcd.print("MENU"); delay(2000);lcd.clear();}
 
  if(digitalRead(10)==LOW&&menu1==1){menu++;cl();times=millis();w=1;w2=1;if(menu>2){menu=0;}}//MENU 1
  if(digitalRead(10)==LOW&&menu2==1){menu0++;cl();times=millis();w=1;w2=1;if(menu0>4){menu0=0;}}//MENU 2
 
  if(digitalRead(3)==HIGH){in++;cl();;times=millis();w=1;w2=1;if(in>3){in=0;}lcd.setCursor(4,0);switch(in){
  case 0: lcd.print("BT  ");break;
  case 1: lcd.print("AUX1  ");break;
  case 2: lcd.print("AUX2  ");break;
  case 3: lcd.print("MP3  ");break;
  // и так далее
  };audio();delay(2000);lcd.clear();}// IN
  }
 
  if(digitalRead(4)==HIGH&&mute==0&&power==0){mute=1;pt.setAttR(31);pt.setAttL(31);cl();lcd.setCursor(6,0);lcd.print("MUTE");menu1=100;menu2=100;delay(500);}// MUTE
  if(digitalRead(4)==HIGH&&mute==1&&power==0){mute=0;cl();menu1=1;menu=0;cl();audio();}// MUTE
 
  if(digitalRead(5)==HIGH&&power==0){power=1;pt.setAttR(31);pt.setAttL(31);lcd.clear();lcd.setCursor(3,0);lcd.print("POWER  OFF");menu0=0;menu1=0;menu2=0;save=1;analogWrite(6, 50);delay(3000);lcd.clear();}// power off
  if(digitalRead(5)==HIGH&&power==1){power=0;lcd.backlight();lcd.clear();lcd.setCursor(3,0);lcd.print("POWER   ON ");menu1=1;menu=0;myEnc.write(0);audio();analogWrite(6, brig);delay(3000);lcd.clear();}// power on
  //  if(power==0){digitalWrite(7,HIGH);}
  if(power==0){digitalWrite(7,LOW);}// inversión de salida STANDBY
 
  if(save==1&&w2==1){save=0;w2=0;
     EEPROM.update(0,vol);EEPROM.update(1,treb+7);EEPROM.update(2,bass+7);EEPROM.update(3,in);
     EEPROM.update(4,att_l);EEPROM.update(5,att_r);EEPROM.update(6,gain1);EEPROM.update(7,gain2);
     EEPROM.update(8,gain3);EEPROM.update(9,gain4);EEPROM.update(10,loud_on);EEPROM.update(11,brig);}
///////////////////////////////////////////////////////////////////////////////////////// 
 
////////////// VOLUME ///////////////////////////////////////////////////////////////////
 if(menu==0&&menu1==1){
   if(ir.value==IR_3){vol++;gr1=1;gr2=0;cl1();times=millis();w=1;w2=1;vol_func();audio();}// BOTON > 
   if(ir.value==0xFFFFFFFF and gr1==1){vol++;gr2=0;cl1();times=millis();w=1;w2=1;vol_func();audio();}// BOTON >>>>>>
   if(ir.value==IR_4){vol--;gr1=0;gr2=1;cl1();times=millis();w=1;w2=1;vol_func();audio();}// BOTON <
   if(ir.value==0xFFFFFFFF and gr2==1){vol--;gr1=0;cl1();times=millis();w=1;w2=1;vol_func();audio();}// BOTON <<<<<<
 
   if (newPosition != oldPosition){oldPosition = newPosition;vol=vol+newPosition;myEnc.write(0);newPosition=0;times=millis();w=1;w2=1;vol_func();audio();}
   a[0]= vol/10;a[1]=vol%10;
   for(i=0;i<2;i++){switch(i){case 0: e1=10,e2=11,e3=12;break;case 1: e1=13,e2=14,e3=15;break;}digit();}
 
   lcd.setCursor(0,0);switch(in){
  case 0: lcd.print("BT  ");break;
  case 1: lcd.print("AUX1 ");break;
  case 2: lcd.print("AUX2 ");break;
  case 3: lcd.print("MP3  ");break;
  // и так далее
  };lcd.print("  VOL");
   if(vol<0){lcd.setCursor(9,1);lcd.write((uint8_t)8);}else{lcd.setCursor(9,1);lcd.print(" ");}
   times_f();
   }
////////////////////////////////////////////////////////////////////////////////////////////
 
////////////// BASS ///////////////////////////////////////////////////////////////////
 if(menu==1&&menu1==1){
   if(ir.value==IR_3){bass++;gr1=1;gr2=0;cl1();times=millis();w=1;w2=1;bass_func();audio();}// BOTON > 
   if(ir.value==0xFFFFFFFF and gr1==1){bass++;gr2=0;cl1();times=millis();w=1;w2=1;bass_func();audio();}// BOTON >>>>>>
   if(ir.value==IR_4){bass--;gr1=0;gr2=1;cl1();times=millis();w=1;w2=1;bass_func();audio();}// кнопка <
   if(ir.value==0xFFFFFFFF and gr2==1){bass--;gr1=0;cl1();times=millis();w=1;w2=1;bass_func();audio();}// BOTON <<<<<<
 
   if (newPosition != oldPosition){oldPosition = newPosition;bass=bass+newPosition;myEnc.write(0);newPosition=0;times=millis();w=1;w2=1;bass_func();audio();}
   a[0]= abs(bass*2)/10;a[1]=abs(bass*2)%10;
   for(i=0;i<2;i++){switch(i){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   dB");
   if(bass<0){lcd.setCursor(9,1);lcd.write((uint8_t)8);}else{lcd.setCursor(9,1);lcd.print(" ");}
   times_f();
   }
////////////////////////////////////////////////////////////////////////////////////////////
 
////////////// TREBLE ///////////////////////////////////////////////////////////////////
 if(menu==2&&menu1==1){
   if(ir.value==IR_3){treb++;gr1=1;gr2=0;cl1();times=millis();w=1;w2=1;treb_func();audio();}// BOTON > 
   if(ir.value==0xFFFFFFFF and gr1==1){treb++;gr2=0;cl1();times=millis();w=1;w2=1;treb_func();audio();}// BOTON >>>>>>
   if(ir.value==IR_4){treb--;gr1=0;gr2=1;cl1();times=millis();w=1;w2=1;treb_func();audio();}// BOTON <
   if(ir.value==0xFFFFFFFF and gr2==1){treb--;gr1=0;cl1();times=millis();w=1;w2=1;treb_func();audio();}// BOTON <<<<<<
 
   if (newPosition != oldPosition){oldPosition = newPosition;treb=treb+newPosition;myEnc.write(0);newPosition=0;times=millis();w=1;w2=1;treb_func();audio();}
   a[0]= abs(treb*2)/10;a[1]=abs(treb*2)%10;
 
   for(i=0;i<2;i++){switch(i){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 dB");
   if(treb<0){lcd.setCursor(9,1);lcd.write((uint8_t)8);}else{lcd.setCursor(9,1);lcd.print(" ");}
   times_f();
   }
////////////////////////////////////////////////////////////////////////////////////////////
 
////////////// ATT_L ///////////////////////////////////////////////////////////////////
 if(menu0==0&&menu2==1){
   if(ir.value==IR_3){att_l++;gr1=1;gr2=0;cl1();times=millis();w=1;w2=1;att_l_func();audio();}// BOTON > 
   if(ir.value==0xFFFFFFFF and gr1==1){att_l++;gr2=0;cl1();times=millis();w=1;w2=1;att_l_func();audio();}// BOTON >>>>>>
   if(ir.value==IR_4){att_l--;gr1=0;gr2=1;cl1();times=millis();w=1;w2=1;att_l_func();audio();}// BOTON <
   if(ir.value==0xFFFFFFFF and gr2==1){att_l--;gr1=0;cl1();times=millis();w=1;w2=1;att_l_func();audio();}// BOTON <<<<<<
 
   if (newPosition != oldPosition){oldPosition = newPosition;att_l=att_l+newPosition;myEnc.write(0);newPosition=0;times=millis();w=1;w2=1;att_l_func();audio();}
   a[0]= abs(att_l)/10;a[1]=abs(att_l)%10;
   for(i=0;i<2;i++){switch(i){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_L");
   lcd.setCursor(0,1);lcd.print(-att_l*1.25,2);lcd.print(" ");lcd.setCursor(6,1);lcd.print("dB");}
////////////////////////////////////////////////////////////////////////////////////////////
 
////////////// ATT_R ///////////////////////////////////////////////////////////////////
 if(menu0==1&&menu2==1){
   if(ir.value==IR_3){att_r++;gr1=1;gr2=0;cl1();times=millis();w=1;w2=1;att_r_func();audio();}// BOTON > 
   if(ir.value==0xFFFFFFFF and gr1==1){att_r++;gr2=0;cl1();times=millis();w=1;w2=1;att_r_func();audio();}// BOTON >>>>>>
   if(ir.value==IR_4){att_r--;gr1=0;gr2=1;cl1();times=millis();w=1;w2=1;att_r_func();audio();}// кнопка <
   if(ir.value==0xFFFFFFFF and gr2==1){att_r--;gr1=0;cl1();times=millis();w=1;w2=1;att_r_func();audio();}// BOTON <<<<<<
 
   if (newPosition != oldPosition){oldPosition = newPosition;att_r=att_r+newPosition;myEnc.write(0);newPosition=0;times=millis();w=1;w2=1;att_r_func();audio();}
   a[0]= abs(att_r)/10;a[1]=abs(att_r)%10;
   for(i=0;i<2;i++){switch(i){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_R");
   lcd.setCursor(0,1);lcd.print(-att_r*1.25,2);lcd.print(" ");lcd.setCursor(6,1);lcd.print("dB");}
////////////////////////////////////////////////////////////////////////////////////////////
 
////////////// INPUT GAIN ///////////////////////////////////////////////////////////////////
 if(menu0==2&&menu2==1){
   switch(in){
     case 0: gain0 = gain1;break;
     case 1: gain0 = gain2;break;
     case 2: gain0 = gain3;break;
     case 3: gain0 = gain4;break;
     }
 
   if(ir.value==IR_3){gain0++;gr1=1;gr2=0;cl1();times=millis();w=1;w2=1;gain_func();www=1;}// BOTON > 
   if(ir.value==0xFFFFFFFF and gr1==1){gain0++;gr2=0;cl1();times=millis();w=1;w2=1;gain_func();www=1;}// BOTON >>>>>>
   if(ir.value==IR_4){gain0--;gr1=0;gr2=1;cl1();times=millis();w=1;w2=1;gain_func();www=1;}// кнопка <
   if(ir.value==0xFFFFFFFF and gr2==1){gain0--;gr1=0;cl1();times=millis();w=1;w2=1;gain_func();www=1;}// BOTON <<<<<<
 
   if (newPosition != oldPosition){oldPosition = newPosition;gain0=gain0+newPosition;myEnc.write(0);newPosition=0;times=millis();www=1;w=1;w2=1;gain_func();}
 
  switch(in){
     case 0: gain1 = gain0;break;
     case 1: gain2 = gain0;break;
     case 2: gain3 = gain0;break;
     case 3: gain4 = gain0;break;
     }  
     a[0]= abs(gain0);
 
   for(i=0;i<1;i++){switch(i){case 0: e1=13,e2=14,e3=15;break;case 1: e1=13,e2=14,e3=15;break;}digit();}
   lcd.setCursor(0,1);lcd.print("GAIN ");lcd.print(gain0*3.75,2);lcd.print(" ");lcd.setCursor(10,1);lcd.print("dB");
   if(www==1){audio();www=0;}
   lcd.setCursor(0,0);switch(in){
  case 0: lcd.print("BT  ");break;
  case 1: lcd.print("AUX1  ");break;
  case 2: lcd.print("AUX2  ");break;
  case 3: lcd.print("MP3  ");break;
  // и так далее
  };}
////////////////////////////////////////////////////////////////////////////////////////////
 
////////////// LOUDNESS ///////////////////////////////////////////////////////////////////
 if(menu0==3&&menu2==1){
   if(ir.value==IR_3){loud_on++;gr1=1;gr2=0;cl1();times=millis();w=1;w2=1;if(loud_on>1){loud_on=0;};if(loud_on<0){loud_on=1;}audio();}// BOTON > 
   if(ir.value==0xFFFFFFFF and gr1==1){loud_on++;gr2=0;cl1();times=millis();w=1;w2=1;if(loud_on>1){loud_on=0;};if(loud_on<0){loud_on=1;}audio();}// BOTON >>>>>>
   if(ir.value==IR_4){loud_on--;gr1=0;gr2=1;cl1();times=millis();w=1;w2=1;if(loud_on>1){loud_on=0;};if(loud_on<0){loud_on=1;}audio();}// кнопка <
   if(ir.value==0xFFFFFFFF and gr2==1){loud_on--;gr1=0;cl1();times=millis();w=1;w2=1;if(loud_on>1){loud_on=0;};if(loud_on<0){loud_on=1;}audio();}// BOTON <<<<<<
 
   if (newPosition != oldPosition){oldPosition = newPosition;loud_on=loud_on+newPosition;myEnc.write(0);newPosition=0;times=millis();w=1;w2=1;if(loud_on>1){loud_on=0;};if(loud_on<0){loud_on=1;};audio();}
   if(loud_on==1){lcd.setCursor(2,0);lcd.print("LOUDNESS  ON ");}
             else{lcd.setCursor(2,0);lcd.print("LOUDNESS  OFF");}}
////////////////////////////////////////////////////////////////////////////////////////////
 
////////////// BRIGHTNESS ///////////////////////////////////////////////////////////////////
 if(menu0==4&&menu2==1){
   if(ir.value==IR_3){brig++;gr1=1;gr2=0;cl1();times=millis();w=1;w2=1;brig_func();analogWrite(6,brig);}// BOTON > 
   if(ir.value==0xFFFFFFFF and gr1==1){brig++;gr2=0;cl1();times=millis();w=1;w2=1;brig_func();analogWrite(6,brig);}// BOTON >>>>>>
   if(ir.value==IR_4){brig--;gr1=0;gr2=1;cl1();times=millis();w=1;w2=1;brig_func();analogWrite(6,brig);}// BOTON <
   if(ir.value==0xFFFFFFFF and gr2==1){brig--;gr1=0;cl1();times=millis();w=1;w2=1;brig_func();analogWrite(6,brig);}// BOTON <<<<<<
 
   if (newPosition != oldPosition){oldPosition = newPosition;brig=brig+newPosition;myEnc.write(0);newPosition=0;times=millis();w=1;w2=1;brig_func();analogWrite(6,brig);}
   a[0]= abs(brig)/100;a[1]=abs(brig)/10%10;a[2]=abs(brig)%10;
   for(i=0;i<3;i++){switch(i){case 0: e1=7,e2=8,e3=9;break;
                              case 1: e1=10,e2=11,e3=12;break;
                              case 2: e1=13,e2=14,e3=15;break;
                              }digit();}
 
   lcd.setCursor(0,0);lcd.print("BRIGHT");
   lcd.setCursor(0,1);lcd.print(brig*100/255);lcd.print(" ");lcd.setCursor(4,1);lcd.print("%");}
////////////////////////////////////////////////////////////////////////////////////////////
 
if(millis()-times>10000&&w==1&&mute==0&&power==0){w=0;menu2=0;menu1=1;menu=0;cl();}
 
/////////////////// RELOJ ///////////////////////////////////////////////////////////////////
if(power==1){digitalWrite(7,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(i=0;i<4;i++){
    switch(i){
        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(2)==HIGH){hour++;if(hour>23){hour=0;} clock.setDateTime(2020, 9, 15, hour, minut, secon);delay(100);}
  if(digitalRead(10)==LOW&&digitalRead(3)==HIGH){minut++;if(minut>59){minut=0;} clock.setDateTime(2020, 9, 15, hour, minut, secon);delay(100); }
  if(digitalRead(10)==LOW&&digitalRead(4)==HIGH){secon=0; clock.setDateTime(2020, 9, 15, hour, minut, secon);delay(100); }
}





////////////////////////////////////////////////////////////////////////////////////////////
}// loop
 
 
void times_f(){lcd.setCursor(0,1);lcd.print(DateTime.hour/10);lcd.print(DateTime.hour%10);lcd.print(":");lcd.print(DateTime.minute/10);lcd.print(DateTime.minute%10);lcd.print(":");lcd.print(DateTime.second/10);lcd.print(DateTime.second%10);}
void brig_func(){if(brig<0){brig=0;}if(brig>255){brig=255;}}
void gain_func(){if(gain0<0){gain0=0;}if(gain0>3){gain0=3;}}
void att_r_func(){if(att_r<0){att_r=0;}if(att_r>24){att_r=24;}}
void att_l_func(){if(att_l<0){att_l=0;}if(att_l>24){att_l=24;}}
void treb_func(){if(treb<-7){treb=-7;}if(treb>7){treb=7;}}
void bass_func(){if(bass<-7){bass=-7;}if(bass>7){bass=7;}}
void vol_func(){if(vol<0){vol=0;}if(vol>56){vol=56;}}
void cl(){ir.value=0;delay(300);lcd.clear();}
void cl1(){ir.value=0;delay(200);}  
void audio(){
  pt.setVolume(vol); // int 0...56 === -70...0 dB step 1.25 dB
  pt.setAttL(att_l); // int 0...24 === 0...-30 db step 1.25 dB > int 31 === mute on     
  pt.setAttR(att_r); // int 0...24 === 0...-30 dB step 1.25 dB > int 31 === mute on
  pt.setSwitch(in, loud_on, gain0); 
        // input      int 0..3 === IN 1...4 
        // loudness   int 0...1 === 1-on 0-off
        // input gain int 0...3 === 0...11.25dB step 3.75 dB
  pt.setBass(bass);   // int -7...+7 === -14...+14 dB step 2 dB
  pt.setTreble(treb); // int -7...+7 === -14...+14 dB step 2 dB
  }
 
void to_Timer(){newPosition = myEnc.read()/4;}  
 
void digit(){switch(a[i]){
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);}

84 (2023-05-06 01:44:48 отредактировано яАнтон)

Re: PT2314

Помогите пожалуйста, не могу подключить пульт(разные коды).
В этом скече коды определяются

#include <IRremote.h>


const byte IR_RECEIVE_PIN = 12;



void setup() {
  Serial.begin(9600);
  IrReceiver.begin(IR_RECEIVE_PIN, ENABLE_LED_FEEDBACK);
}


void loop() {
  if (IrReceiver.decode()) {
    Serial.println(IrReceiver.decodedIRData.decodedRawData, HEX);
    IrReceiver.resume();
  }
}
В скеч других (из форума) коды разные,  помогите согласовать этот скеч. У меня не получаеться

85

Re: PT2314

liman324 пишет:

Протестировал в железе, все работает:

#define IR_1 0x807F6897 // Кнопка вверх
#define IR_2 0x807F58A7 // Кнопка вниз
#define IR_3 0x807F0AF5 // Кнопка >
#define IR_4 0x807F8A75 // Кнопка <
#define IR_5 0x807F9867 // Кнопка IN
#define IR_6 0x807FC837 // Кнопка SET
#define IR_7 0x807F827D // Кнопка MUTE
#define IR_8 0x807F02FD // Кнопка STANDBY (POWER)
#define IR_9 0x807F728D // Кнопка сон 10 минут
//#define IR_10 0x807FB04F // Кнопка сон 20 минут
//#define IR_11 0x807F30CF // Кнопка сон 30 минут
#define BRIG 100        // Яркость подсветки экрана в режиме POWER OFF (0...255)
#include <Wire.h>
#include <PT2314.h>            // http://forum.rcl-radio.ru/misc.php?action=pan_download&item=434&download=1
#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
DS3231 clock; RTCDateTime DateTime;
unsigned long times_son;
bool son_k,son;
PT2314 pt;
LiquidCrystal_I2C lcd(0x27, 16, 2); // Устанавливаем дисплей
IRrecv irrecv(12); // указываем вывод модуля IR приемника
Encoder myEnc(8, 9);// DT, CLK
decode_results ir;
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};
byte a[6], d1, d2, d3, d4, d5, d6, e1, e2, e3, w, w2, i, www, power, save, gr1, gr2;
int menu, menu0, menu1 = 1, menu2 = 0, vol, bass, treb, att_l, att_r, in, loud_on, gain0, gain1, gain2, gain3, gain4, mute, mute1, mute2, brig, hour, minut, secon;
unsigned long times, oldPosition  = -999, newPosition;
void setup() {
  irrecv.enableIRIn(); lcd.init(); lcd.backlight(); clock.begin(); Serial.begin(9600);
  pinMode(10, INPUT); // МЕНЮ КНОПКА SW энкодера
  pinMode(2, INPUT);  // КНОПКА SET
  pinMode(3, INPUT);  // КНОПКА IN
  pinMode(4, INPUT);  // КНОПКА MUTE
  pinMode(5, INPUT);  // КНОПКА STANDBY
  pinMode(7, OUTPUT); // ВЫХОД УПРАВЛЕНИЯ STANDBY
  pinMode(6, OUTPUT); // ВЫХОД УПРАВЛЕНИЯ ПОДСВЕТКОЙ
  analogWrite(6, 255);
  lcd.setCursor(0, 0); lcd.print("AmplifieR ClassA"); lcd.setCursor(0, 1); lcd.print("    JLH 1969"); delay(2000); lcd.clear();
  MsTimer2::set(1, to_Timer); MsTimer2::start();
  //  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);
  if (EEPROM.read(100) != 0) {
    for (int i = 0; i < 101; i++) {
      EEPROM.update(i, 0); // очистка памяти при первом включении
    }
  }
  vol = EEPROM.read(0); treb = EEPROM.read(1) - 7; bass = EEPROM.read(2) - 7; in = EEPROM.read(3);
  att_l = EEPROM.read(4); att_r = EEPROM.read(5); gain1 = EEPROM.read(6); gain2 = EEPROM.read(7);
  gain3 = EEPROM.read(8); gain4 = EEPROM.read(9); loud_on = EEPROM.read(10); brig = EEPROM.read(11);
  audio();
  analogWrite(6, brig);
}

void loop() {
  DateTime = clock.getDateTime(); hour = DateTime.hour; minut = DateTime.minute; secon = DateTime.second;

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

  if (mute == 0 && power == 0) {
    if (ir.value == IR_6 && menu1 == 1) {
      menu1 = 0;
      menu2 = 1;
      gr1 = 0;
      gr2 = 0;
      cl();
      times = millis();
      w = 1;
      w2 = 1;
      lcd.setCursor(3, 0);
      lcd.print("SYSTEM");
      lcd.setCursor(6, 1);
      lcd.print("SETTINGS");
      delay(1000);
      lcd.clear();
    }
    if (ir.value == IR_6 && menu2 == 1) {
      menu1 = 1;
      menu2 = 0;
      menu = 0;
      gr1 = 0;
      gr2 = 0;
      cl();
      times = millis();
      w = 1;
      w2 = 1;
      lcd.setCursor(3, 0);
      lcd.print("AUDIO");
      lcd.setCursor(6, 1);
      lcd.print("SETTINGS");
      delay(1000);
      lcd.clear();
    }

    if (ir.value == IR_1 && menu1 == 1) {
      menu++;  //меню 1
      gr1 = 0;
      gr2 = 0;
      cl();
      times = millis();
      w = 1;
      w2 = 1;
      if (menu > 2) {
        menu = 0;
      }
    }
    if (ir.value == IR_2 && menu1 == 1) {
      menu--;  //меню 1
      gr1 = 0;
      gr2 = 0;
      cl();
      times = millis();
      w = 1;
      w2 = 1;
      if (menu < 0) {
        menu = 2;
      }
    }

    if (ir.value == IR_1 && menu2 == 1) {
      menu0++;  //меню 2
      gr1 = 0;
      gr2 = 0;
      cl();
      times = millis();
      w = 1;
      w2 = 1;
      if (menu0 > 4) {
        menu0 = 0;
      }
    }
    if (ir.value == IR_2 && menu2 == 1) {
      menu0--;  //меню 2
      gr1 = 0;
      gr2 = 0;
      cl();
      times = millis();
      w = 1;
      w2 = 1;
      if (menu0 < 0) {
        menu0 = 4;
      }
    }

    if (ir.value == IR_5) {
      in++;  // IN
      gr1 = 0;
      gr2 = 0;
      cl();
      times = millis();
      w = 1;
      w2 = 1;
      if (in > 3) {
        in = 0;
      } lcd.setCursor(4, 0);
      lcd.print("INPUT ");
      lcd.print(in + 1);
      audio();
      delay(1000);
      lcd.clear();
    }
  }

  if (ir.value == IR_7 && mute == 0 && power == 0) {
    mute = 1;  // MUTE
    pt.setAttR(31);
    pt.setAttL(31);
    gr1 = 0;
    gr2 = 0;
    cl();
    lcd.setCursor(6, 0);
    lcd.print("MUTE");
    menu1 = 100;
    menu2 = 100;
    delay(500);
  }
  if (ir.value == IR_7 && mute == 1 && power == 0) {
    mute = 0;  // MUTE
    cl();
    menu1 = 1;
    menu = 0;
    gr1 = 0;
    gr2 = 0;
    cl();
    audio();
  }

  if (ir.value == IR_8 && power == 0) {
    power = 1;  // power off
    pt.setAttR(31);
    pt.setAttL(31);
    gr1 = 0;
    gr2 = 0;
    cl();
    lcd.clear();
    lcd.setCursor(3, 0);
    lcd.print("POWER  OFF");
    menu0 = 0;
    menu1 = 0;
    menu2 = 0;
    save = 1;
    analogWrite(6, BRIG);
    delay(2000);
    lcd.clear();
  }
  if (ir.value == IR_8 && power == 1) {
    gr1 = 0;
    gr2 = 0;
    cl();
    lcd.backlight();
    lcd.clear();
    lcd.setCursor(3, 0);
    lcd.print("POWER   ON ");
    menu1 = 1;
    menu = 0;
    myEnc.write(0);
    audio();
    analogWrite(6, brig);
    delay(2000);
    power = 0;  // power on
    lcd.clear();
  }
  
  if (ir.value == IR_9) {cl();son_k = 1;
    lcd.clear();
    lcd.setCursor(3, 0);
    lcd.print("POWER  OFF");
    lcd.setCursor(5, 1);
    lcd.print("10 MIN"); 
    delay(2000);
    lcd.clear();   
    }
  if (son_k == 0) {times_son = millis();}
  if (millis() - times_son > 600000) {                //Время таймера в милисек
    son = 1;
  }
  
  if ((ir.value == IR_8 && power == 0) || son == 1) {
    power = 1;  // power off
    son = 0;  // power on
    son_k = 0;
    times_son = millis();
    pt.setAttR(31);
    pt.setAttL(31);
    audio();
    gr1 = 0;
    gr2 = 0;
    cl();
    lcd.clear();
    lcd.setCursor(3, 0);
    lcd.print("POWER  OFF");
    menu0 = 0;
    menu1 = 0;
    menu2 = 0;
    save = 1;
    analogWrite(6, BRIG);
    delay(3000);
    lcd.clear();
  }
  if (ir.value == IR_8 && power == 1) {
    power = 0;
    gr1 = 0;
    gr2 = 0;
    cl();
    lcd.backlight();
    lcd.clear();
    lcd.setCursor(3, 0);
    lcd.print("POWER   ON ");
    menu1 = 1;
    menu = 0;
    myEnc.write(0);
    audio();
    analogWrite(6, brig);
    delay(3000);
    lcd.clear();
  }
  /////////////////////////////////////////////////////////////////////////////////////////

  /////////////////////////////// УПРАВЛЕНИЕ //////////////////////////////////////////////
  if (mute == 0 && power == 0) {
    if (digitalRead(2) == HIGH && menu1 == 1) {
      menu1 = 0;
      menu2 = 1;
      cl();
      times = millis();
      w = 1;
      w2 = 1;
      lcd.setCursor(3, 0);
      lcd.print("SYSTEM");
      lcd.setCursor(6, 1);
      lcd.print("SETTINGS");
      delay(1000);
      lcd.clear();
    }
    if (digitalRead(2) == HIGH && menu2 == 1) {
      menu1 = 1;
      menu2 = 0;
      menu = 0;
      cl();
      times = millis();
      w = 1;
      w2 = 1;
      lcd.setCursor(3, 0);
      lcd.print("AUDIO");
      lcd.setCursor(6, 1);
      lcd.print("SETTINGS");
      delay(1000);
      lcd.clear();
    }

    if (digitalRead(10) == LOW && menu1 == 1) {
      menu++;  //меню 1
      cl();
      times = millis();
      w = 1;
      w2 = 1;
      if (menu > 2) {
        menu = 0;
      }
    }
    if (digitalRead(10) == LOW && menu2 == 1) {
      menu0++;  //меню 2
      cl();
      times = millis();
      w = 1;
      w2 = 1;
      if (menu0 > 4) {
        menu0 = 0;
      }
    }

    if (digitalRead(3) == HIGH) {
      in++;  // IN
      cl();;
      times = millis();
      w = 1;
      w2 = 1;
      if (in > 3) {
        in = 0;
      } lcd.setCursor(4, 0);
      lcd.print("INPUT ");
      lcd.print(in + 1);
      audio();
      delay(1000);
      lcd.clear();
    }
  }

  if (digitalRead(4) == HIGH && mute == 0 && power == 0) {
    mute = 1;  // MUTE
    pt.setAttR(31);
    pt.setAttL(31);
    cl();
    lcd.setCursor(6, 0);
    lcd.print("MUTE");
    menu1 = 100;
    menu2 = 100;
    delay(500);
  }
  if (digitalRead(4) == HIGH && mute == 1 && power == 0) {
    mute = 0;  // MUTE
    cl();
    menu1 = 1;
    menu = 0;
    cl();
    audio();
  }

  if (digitalRead(5) == HIGH && power == 0) {
    power = 1;  // power off
    pt.setAttR(31);
    pt.setAttL(31);
    lcd.clear();
    lcd.setCursor(3, 0);
    lcd.print("POWER  OFF");
    menu0 = 0;
    menu1 = 0;
    menu2 = 0;
    save = 1;
    analogWrite(6, BRIG);
    delay(3000);
    lcd.clear();
  }
  if (digitalRead(5) == HIGH && power == 1) {
    power = 0;  // power on
    lcd.backlight();
    lcd.clear();
    lcd.setCursor(3, 0);
    lcd.print("POWER   ON ");
    menu1 = 1;
    menu = 0;
    myEnc.write(0);
    audio();
    analogWrite(6, brig);
    delay(3000);
    lcd.clear();
  }
  if (power == 0) {
    digitalWrite(7, HIGH);
  }
  //if(power==0){digitalWrite(7,LOW);}// инверсия выхода STANDBY

  if (save == 1 && w2 == 1) {
    save = 0; w2 = 0;
    EEPROM.update(0, vol); EEPROM.update(1, treb + 7); EEPROM.update(2, bass + 7); EEPROM.update(3, in);
    EEPROM.update(4, att_l); EEPROM.update(5, att_r); EEPROM.update(6, gain1); EEPROM.update(7, gain2);
    EEPROM.update(8, gain3); EEPROM.update(9, gain4); EEPROM.update(10, loud_on); EEPROM.update(11, brig);
  }
  /////////////////////////////////////////////////////////////////////////////////////////

  ////////////// VOLUME ///////////////////////////////////////////////////////////////////
  if (menu == 0 && menu1 == 1) {
    if (ir.value == IR_3) {
      vol++;  // кнопка >
      gr1 = 1;
      gr2 = 0;
      cl1();
      times = millis();
      w = 1;
      w2 = 1;
      vol_func();
      audio();
    }
    if (ir.value == 0xFFFFFFFF and gr1 == 1) {
      vol++;  // кнопка >>>>>>
      gr2 = 0;
      cl1();
      times = millis();
      w = 1;
      w2 = 1;
      vol_func();
      audio();
    }
    if (ir.value == IR_4) {
      vol--;  // кнопка <
      gr1 = 0;
      gr2 = 1;
      cl1();
      times = millis();
      w = 1;
      w2 = 1;
      vol_func();
      audio();
    }
    if (ir.value == 0xFFFFFFFF and gr2 == 1) {
      vol--;  // кнопка <<<<<<
      gr1 = 0;
      cl1();
      times = millis();
      w = 1;
      w2 = 1;
      vol_func();
      audio();
    }

    if (newPosition != oldPosition) {
      oldPosition = newPosition;
      vol = vol + newPosition;
      myEnc.write(0);
      newPosition = 0;
      times = millis();
      w = 1;
      w2 = 1;
      vol_func();
      audio();
    }
    a[0] = vol / 10; a[1] = vol % 10;
    for (i = 0; i < 2; i++) {
      switch (i) {
        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("IN"); lcd.print(in + 1); lcd.print("  VOL");
    if (vol < 0) {
      lcd.setCursor(9, 1);
      lcd.write((uint8_t)8);
    } else {
      lcd.setCursor(9, 1);
      lcd.print(" ");
    }
    times_f();
  }
  ////////////////////////////////////////////////////////////////////////////////////////////

  ////////////// BASS ///////////////////////////////////////////////////////////////////
  if (menu == 1 && menu1 == 1) {
    if (ir.value == IR_3) {
      bass++;  // кнопка >
      gr1 = 1;
      gr2 = 0;
      cl1();
      times = millis();
      w = 1;
      w2 = 1;
      bass_func();
      audio();
    }
    if (ir.value == 0xFFFFFFFF and gr1 == 1) {
      bass++;  // кнопка >>>>>>
      gr2 = 0;
      cl1();
      times = millis();
      w = 1;
      w2 = 1;
      bass_func();
      audio();
    }
    if (ir.value == IR_4) {
      bass--;  // кнопка <
      gr1 = 0;
      gr2 = 1;
      cl1();
      times = millis();
      w = 1;
      w2 = 1;
      bass_func();
      audio();
    }
    if (ir.value == 0xFFFFFFFF and gr2 == 1) {
      bass--;  // кнопка <<<<<<
      gr1 = 0;
      cl1();
      times = millis();
      w = 1;
      w2 = 1;
      bass_func();
      audio();
    }

    if (newPosition != oldPosition) {
      oldPosition = newPosition;
      bass = bass + newPosition;
      myEnc.write(0);
      newPosition = 0;
      times = millis();
      w = 1;
      w2 = 1;
      bass_func();
      audio();
    }
    a[0] = abs(bass * 2) / 10; a[1] = abs(bass * 2) % 10;
    for (i = 0; i < 2; i++) {
      switch (i) {
        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   dB");
    if (bass < 0) {
      lcd.setCursor(9, 1);
      lcd.write((uint8_t)8);
    } else {
      lcd.setCursor(9, 1);
      lcd.print(" ");
    }
    times_f();
  }
  ////////////////////////////////////////////////////////////////////////////////////////////

  ////////////// TREBLE ///////////////////////////////////////////////////////////////////
  if (menu == 2 && menu1 == 1) {
    if (ir.value == IR_3) {
      treb++;  // кнопка >
      gr1 = 1;
      gr2 = 0;
      cl1();
      times = millis();
      w = 1;
      w2 = 1;
      treb_func();
      audio();
    }
    if (ir.value == 0xFFFFFFFF and gr1 == 1) {
      treb++;  // кнопка >>>>>>
      gr2 = 0;
      cl1();
      times = millis();
      w = 1;
      w2 = 1;
      treb_func();
      audio();
    }
    if (ir.value == IR_4) {
      treb--;  // кнопка <
      gr1 = 0;
      gr2 = 1;
      cl1();
      times = millis();
      w = 1;
      w2 = 1;
      treb_func();
      audio();
    }
    if (ir.value == 0xFFFFFFFF and gr2 == 1) {
      treb--;  // кнопка <<<<<<
      gr1 = 0;
      cl1();
      times = millis();
      w = 1;
      w2 = 1;
      treb_func();
      audio();
    }

    if (newPosition != oldPosition) {
      oldPosition = newPosition;
      treb = treb + newPosition;
      myEnc.write(0);
      newPosition = 0;
      times = millis();
      w = 1;
      w2 = 1;
      treb_func();
      audio();
    }
    a[0] = abs(treb * 2) / 10; a[1] = abs(treb * 2) % 10;

    for (i = 0; i < 2; i++) {
      switch (i) {
        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 dB");
    if (treb < 0) {
      lcd.setCursor(9, 1);
      lcd.write((uint8_t)8);
    } else {
      lcd.setCursor(9, 1);
      lcd.print(" ");
    }
    times_f();
  }
  ////////////////////////////////////////////////////////////////////////////////////////////

  ////////////// ATT_L ///////////////////////////////////////////////////////////////////
  if (menu0 == 0 && menu2 == 1) {
    if (ir.value == IR_3) {
      att_l++;  // кнопка >
      gr1 = 1;
      gr2 = 0;
      cl1();
      times = millis();
      w = 1;
      w2 = 1;
      att_l_func();
      audio();
    }
    if (ir.value == 0xFFFFFFFF and gr1 == 1) {
      att_l++;  // кнопка >>>>>>
      gr2 = 0;
      cl1();
      times = millis();
      w = 1;
      w2 = 1;
      att_l_func();
      audio();
    }
    if (ir.value == IR_4) {
      att_l--;  // кнопка <
      gr1 = 0;
      gr2 = 1;
      cl1();
      times = millis();
      w = 1;
      w2 = 1;
      att_l_func();
      audio();
    }
    if (ir.value == 0xFFFFFFFF and gr2 == 1) {
      att_l--;  // кнопка <<<<<<
      gr1 = 0;
      cl1();
      times = millis();
      w = 1;
      w2 = 1;
      att_l_func();
      audio();
    }

    if (newPosition != oldPosition) {
      oldPosition = newPosition;
      att_l = att_l + newPosition;
      myEnc.write(0);
      newPosition = 0;
      times = millis();
      w = 1;
      w2 = 1;
      att_l_func();
      audio();
    }
    a[0] = abs(att_l) / 10; a[1] = abs(att_l) % 10;
    for (i = 0; i < 2; i++) {
      switch (i) {
        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_L");
    lcd.setCursor(0, 1); lcd.print(-att_l * 1.25, 2); lcd.print(" "); lcd.setCursor(6, 1); lcd.print("dB");
  }
  ////////////////////////////////////////////////////////////////////////////////////////////

  ////////////// ATT_R ///////////////////////////////////////////////////////////////////
  if (menu0 == 1 && menu2 == 1) {
    if (ir.value == IR_3) {
      att_r++;  // кнопка >
      gr1 = 1;
      gr2 = 0;
      cl1();
      times = millis();
      w = 1;
      w2 = 1;
      att_r_func();
      audio();
    }
    if (ir.value == 0xFFFFFFFF and gr1 == 1) {
      att_r++;  // кнопка >>>>>>
      gr2 = 0;
      cl1();
      times = millis();
      w = 1;
      w2 = 1;
      att_r_func();
      audio();
    }
    if (ir.value == IR_4) {
      att_r--;  // кнопка <
      gr1 = 0;
      gr2 = 1;
      cl1();
      times = millis();
      w = 1;
      w2 = 1;
      att_r_func();
      audio();
    }
    if (ir.value == 0xFFFFFFFF and gr2 == 1) {
      att_r--;  // кнопка <<<<<<
      gr1 = 0;
      cl1();
      times = millis();
      w = 1;
      w2 = 1;
      att_r_func();
      audio();
    }

    if (newPosition != oldPosition) {
      oldPosition = newPosition;
      att_r = att_r + newPosition;
      myEnc.write(0);
      newPosition = 0;
      times = millis();
      w = 1;
      w2 = 1;
      att_r_func();
      audio();
    }
    a[0] = abs(att_r) / 10; a[1] = abs(att_r) % 10;
    for (i = 0; i < 2; i++) {
      switch (i) {
        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_R");
    lcd.setCursor(0, 1); lcd.print(-att_r * 1.25, 2); lcd.print(" "); lcd.setCursor(6, 1); lcd.print("dB");
  }
  ////////////////////////////////////////////////////////////////////////////////////////////

  ////////////// INPUT GAIN ///////////////////////////////////////////////////////////////////
  if (menu0 == 2 && menu2 == 1) {
    switch (in) {
      case 0: gain0 = gain1; break;
      case 1: gain0 = gain2; break;
      case 2: gain0 = gain3; break;
      case 3: gain0 = gain4; break;
    }

    if (ir.value == IR_3) {
      gain0++;  // кнопка >
      gr1 = 1;
      gr2 = 0;
      cl1();
      times = millis();
      w = 1;
      w2 = 1;
      gain_func();
      www = 1;
    }
    if (ir.value == 0xFFFFFFFF and gr1 == 1) {
      gain0++;  // кнопка >>>>>>
      gr2 = 0;
      cl1();
      times = millis();
      w = 1;
      w2 = 1;
      gain_func();
      www = 1;
    }
    if (ir.value == IR_4) {
      gain0--;  // кнопка <
      gr1 = 0;
      gr2 = 1;
      cl1();
      times = millis();
      w = 1;
      w2 = 1;
      gain_func();
      www = 1;
    }
    if (ir.value == 0xFFFFFFFF and gr2 == 1) {
      gain0--;  // кнопка <<<<<<
      gr1 = 0;
      cl1();
      times = millis();
      w = 1;
      w2 = 1;
      gain_func();
      www = 1;
    }

    if (newPosition != oldPosition) {
      oldPosition = newPosition;
      gain0 = gain0 + newPosition;
      myEnc.write(0);
      newPosition = 0;
      times = millis();
      www = 1;
      w = 1;
      w2 = 1;
      gain_func();
    }

    switch (in) {
      case 0: gain1 = gain0; break;
      case 1: gain2 = gain0; break;
      case 2: gain3 = gain0; break;
      case 3: gain4 = gain0; break;
    }
    a[0] = abs(gain0);

    for (i = 0; i < 1; i++) {
      switch (i) {
        case 0: e1 = 13, e2 = 14, e3 = 15;
          break;
        case 1: e1 = 13, e2 = 14, e3 = 15;
          break;
      } digit();
    }
    lcd.setCursor(0, 1); lcd.print("GAIN "); lcd.print(gain0 * 3.75, 2); lcd.print(" "); lcd.setCursor(10, 1); lcd.print("dB");
    if (www == 1) {
      audio();
      www = 0;
    }
    lcd.setCursor(0, 0); lcd.print("INPUT "); lcd.print(in + 1);
  }
  ////////////////////////////////////////////////////////////////////////////////////////////

  ////////////// LOUDNESS ///////////////////////////////////////////////////////////////////
  if (menu0 == 3 && menu2 == 1) {
    if (ir.value == IR_3) {
      loud_on++;  // кнопка >
      gr1 = 1;
      gr2 = 0;
      cl1();
      times = millis();
      w = 1;
      w2 = 1;
      if (loud_on > 1) {
        loud_on = 0;
      };
      if (loud_on < 0) {
        loud_on = 1;
      } audio();
    }
    if (ir.value == 0xFFFFFFFF and gr1 == 1) {
      loud_on++;  // кнопка >>>>>>
      gr2 = 0;
      cl1();
      times = millis();
      w = 1;
      w2 = 1;
      if (loud_on > 1) {
        loud_on = 0;
      };
      if (loud_on < 0) {
        loud_on = 1;
      } audio();
    }
    if (ir.value == IR_4) {
      loud_on--;  // кнопка <
      gr1 = 0;
      gr2 = 1;
      cl1();
      times = millis();
      w = 1;
      w2 = 1;
      if (loud_on > 1) {
        loud_on = 0;
      };
      if (loud_on < 0) {
        loud_on = 1;
      } audio();
    }
    if (ir.value == 0xFFFFFFFF and gr2 == 1) {
      loud_on--;  // кнопка <<<<<<
      gr1 = 0;
      cl1();
      times = millis();
      w = 1;
      w2 = 1;
      if (loud_on > 1) {
        loud_on = 0;
      };
      if (loud_on < 0) {
        loud_on = 1;
      } audio();
    }

    if (newPosition != oldPosition) {
      oldPosition = newPosition;
      loud_on = loud_on + newPosition;
      myEnc.write(0);
      newPosition = 0;
      times = millis();
      w = 1;
      w2 = 1;
      if (loud_on > 1) {
        loud_on = 0;
      };
      if (loud_on < 0) {
        loud_on = 1;
      };
      audio();
    }
    if (loud_on == 1) {
      lcd.setCursor(2, 0);
      lcd.print("LOUDNESS  ON ");
    }
    else {
      lcd.setCursor(2, 0);
      lcd.print("LOUDNESS  OFF");
    }
  }
  ////////////////////////////////////////////////////////////////////////////////////////////

  ////////////// BRIGHTNESS ///////////////////////////////////////////////////////////////////
  if (menu0 == 4 && menu2 == 1) {
    if (ir.value == IR_3) {
      brig++;  // кнопка >
      gr1 = 1;
      gr2 = 0;
      cl1();
      times = millis();
      w = 1;
      w2 = 1;
      brig_func();
      analogWrite(6, brig);
    }
    if (ir.value == 0xFFFFFFFF and gr1 == 1) {
      brig++;  // кнопка >>>>>>
      gr2 = 0;
      cl1();
      times = millis();
      w = 1;
      w2 = 1;
      brig_func();
      analogWrite(6, brig);
    }
    if (ir.value == IR_4) {
      brig--;  // кнопка <
      gr1 = 0;
      gr2 = 1;
      cl1();
      times = millis();
      w = 1;
      w2 = 1;
      brig_func();
      analogWrite(6, brig);
    }
    if (ir.value == 0xFFFFFFFF and gr2 == 1) {
      brig--;  // кнопка <<<<<<
      gr1 = 0;
      cl1();
      times = millis();
      w = 1;
      w2 = 1;
      brig_func();
      analogWrite(6, brig);
    }

    if (newPosition != oldPosition) {
      oldPosition = newPosition;
      brig = brig + newPosition;
      myEnc.write(0);
      newPosition = 0;
      times = millis();
      w = 1;
      w2 = 1;
      brig_func();
      analogWrite(6, brig);
    }
    a[0] = abs(brig) / 100; a[1] = abs(brig) / 10 % 10; a[2] = abs(brig) % 10;
    for (i = 0; i < 3; i++) {
      switch (i) {
        case 0: e1 = 7, e2 = 8, e3 = 9; break;
        case 1: e1 = 10, e2 = 11, e3 = 12; break;
        case 2: e1 = 13, e2 = 14, e3 = 15; break;
      } digit();
    }

    lcd.setCursor(0, 0); lcd.print("BRIGHT");
    lcd.setCursor(0, 1); lcd.print(brig * 100 / 255); lcd.print(" "); lcd.setCursor(4, 1); lcd.print("%");
  }
  ////////////////////////////////////////////////////////////////////////////////////////////

  if (millis() - times > 10000 && w == 1 && mute == 0 && power == 0) {
    w = 0;
    menu2 = 0;
    menu1 = 1;
    menu = 0;
    cl();
  }

  /////////////////// ЧАСЫ ///////////////////////////////////////////////////////////////////
  if (power == 1) {
    digitalWrite(7, LOW);
    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 (i = 0; i < 4; i++) {
      switch (i) {
        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(2) == HIGH) {
      hour++;
      if (hour > 23) {
        hour = 0;
      } clock.setDateTime(2020, 9, 15, hour, minut, secon);
      delay(100);
    }
    if (digitalRead(10) == LOW && digitalRead(3) == HIGH) {
      minut++;
      if (minut > 59) {
        minut = 0;
      } clock.setDateTime(2020, 9, 15, hour, minut, secon);
      delay(100);
    }
    if (digitalRead(10) == LOW && digitalRead(4) == HIGH) {
      secon = 0;
      clock.setDateTime(2020, 9, 15, hour, minut, secon);
      delay(100);
    }
  }
  ////////////////////////////////////////////////////////////////////////////////////////////
}// loop


void times_f() {
  lcd.setCursor(0, 1);
  lcd.print(DateTime.hour / 10);
  lcd.print(DateTime.hour % 10);
  lcd.print(":");
  lcd.print(DateTime.minute / 10);
  lcd.print(DateTime.minute % 10);
  lcd.print(":");
  lcd.print(DateTime.second / 10);
  lcd.print(DateTime.second % 10);
}
void brig_func() {
  if (brig < 0) {
    brig = 0;
  } if (brig > 255) {
    brig = 255;
  }
}
void gain_func() {
  if (gain0 < 0) {
    gain0 = 0;
  } if (gain0 > 3) {
    gain0 = 3;
  }
}
void att_r_func() {
  if (att_r < 0) {
    att_r = 0;
  } if (att_r > 24) {
    att_r = 24;
  }
}
void att_l_func() {
  if (att_l < 0) {
    att_l = 0;
  } if (att_l > 24) {
    att_l = 24;
  }
}
void treb_func() {
  if (treb < -7) {
    treb = -7;
  } if (treb > 7) {
    treb = 7;
  }
}
void bass_func() {
  if (bass < -7) {
    bass = -7;
  } if (bass > 7) {
    bass = 7;
  }
}
void vol_func() {
  if (vol < 0) {
    vol = 0;
  } if (vol > 56) {
    vol = 56;
  }
}
void cl() {
  ir.value = 0;
  delay(300);
  lcd.clear();
}
void cl1() {
  ir.value = 0;
  delay(200);
}
void audio() {
  pt.setVolume(vol); // int 0...56 === -70...0 dB step 1.25 dB
  pt.setAttL(att_l); // int 0...24 === 0...-30 db step 1.25 dB > int 31 === mute on
  pt.setAttR(att_r); // int 0...24 === 0...-30 dB step 1.25 dB > int 31 === mute on
  pt.setSwitch(in, loud_on, gain0);
  // input      int 0..3 === IN 1...4
  // loudness   int 0...1 === 1-on 0-off
  // input gain int 0...3 === 0...11.25dB step 3.75 dB
  pt.setBass(bass);   // int -7...+7 === -14...+14 dB step 2 dB
  pt.setTreble(treb); // int -7...+7 === -14...+14 dB step 2 dB
}

void to_Timer() {
  newPosition = myEnc.read() / 4;
}

void digit() {
  switch (a[i]) {
    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);
}

86

Re: PT2314

#include <boarddefs.h>
#include <IRremote.h>          // http://rcl-radio.ru/wp-content/uploads/ … remote.zip

IRrecv irrecv(12); // указываем вывод модуля IR приемника
decode_results ir;

void setup() {
  irrecv.enableIRIn();  Serial.begin(9600);
}

void loop(){
////////////////////// IR ///////////////////////////////////////////////////////////////
  if ( irrecv.decode( &ir )) {
    Serial.print("0x");  // IR приемник - чтение, в мониторе порта отображаются коды кнопок
    Serial.println( ir.value, HEX);
    irrecv.resume();
  }
}

87 (2023-05-06 17:31:55 отредактировано яАнтон)

Re: PT2314

liman324 спасибо за помощь , но правка скеча не помогла. Вопрос решился удалением папки IRremote.h последней версии и добавлением ее из ссылки :
#include <IRremote.h>  // http://rcl-radio.ru/wp-content/uploads/ … remote.zip Пульт заработал, коды стабильные.

ВСЕ РАБОТАЕТ ,СПАСИБО!!!!

88

Re: PT2314

Добрый вечер. Спасибо за Вашу работу. При подачи питания включается  режим POWER ON, можно подправить на POWER OFF. Спасибо.

89

Re: PT2314

Опубликуйте скетч который используете.

90

Re: PT2314

 скетча для сайта

#define IR_1 0x2FDD02F // Кнопка вверх
#define IR_2 0x2FD32CD // Кнопка вниз
#define IR_3 0x2FD906F // Кнопка >
#define IR_4 0x2FDF20D // Кнопка <
#define IR_5 0x2FD708F // Кнопка IN
#define IR_6 0x2FD6A95 // Кнопка SET
#define IR_7 0x2FD00FF // Кнопка MUTE
#define IR_8 0x2FDB24D // Кнопка STANDBY (POWER)
#define BRIG 50        // Яркость подсветки экрана в режиме POWER OFF (0...255)
#include <Wire.h> 
#include <PT2314.h>            // http://forum.rcl-radio.ru/misc.php?action=pan_download&item=434&download=1
#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
   DS3231 clock;RTCDateTime DateTime;
   PT2314 pt;
   LiquidCrystal_I2C lcd(0x27,16,2);  // Устанавливаем дисплей
   IRrecv irrecv(12); // указываем вывод модуля IR приемника
   Encoder myEnc(8, 9);// DT, CLK
   decode_results ir; 
      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};
      byte a[6],d1,d2,d3,d4,d5,d6,e1,e2,e3,w,w2,i,www,power,save,gr1,gr2;
      int menu,menu0,menu1=1,menu2=0,vol,bass,treb,att_l,att_r,in,loud_on,gain0,gain1,gain2,gain3,gain4,mute,mute1,mute2,brig,hour,minut,secon;
      unsigned long times,oldPosition  = -999,newPosition;

void setup() {
  irrecv.enableIRIn();lcd.init();lcd.backlight();clock.begin();Serial.begin(9600);
  pinMode(10,INPUT);  // МЕНЮ КНОПКА SW энкодера
  pinMode(2,INPUT);   // КНОПКА SET
  pinMode(3,INPUT);   // КНОПКА IN
  pinMode(4,INPUT);   // КНОПКА MUTE
  pinMode(5,INPUT);   // КНОПКА STANDBY
  pinMode(7,OUTPUT);  // ВЫХОД УПРАВЛЕНИЯ STANDBY
  pinMode(6,OUTPUT);  // ВЫХОД УПРАВЛЕНИЯ ПОДСВЕТКОЙ
  analogWrite(6, 255);
  lcd.setCursor(0,0);lcd.print("Sound Processor");lcd.setCursor(0,1);lcd.print("PT2314"); delay(2000);lcd.clear();
  MsTimer2::set(1, to_Timer);MsTimer2::start();
  //  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);
  if(EEPROM.read(100)!=0){for(int i=0;i<101;i++){EEPROM.update(i,0);}}// очистка памяти при первом включении  
  vol = EEPROM.read(0);treb = EEPROM.read(1)-7;bass = EEPROM.read(2)-7;in = EEPROM.read(3);
  att_l = EEPROM.read(4);att_r = EEPROM.read(5);gain1 = EEPROM.read(6);gain2 = EEPROM.read(7);
  gain3 = EEPROM.read(8);gain4 = EEPROM.read(9);loud_on = EEPROM.read(10);brig = EEPROM.read(11);
  audio();
  analogWrite(6, brig);
}

void loop() {
  DateTime = clock.getDateTime();hour = DateTime.hour;minut = DateTime.minute;secon = DateTime.second;

////////////////////// 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;}// запрет нажатий не активных кнопок пульта  

    if(mute==0&&power==0){
  if(ir.value==IR_6&&menu1==1){menu1=0;menu2=1;gr1=0;gr2=0;cl();times=millis();w=1;w2=1;lcd.setCursor(4,0);lcd.print("SETTING"); delay(2000);lcd.clear();}
  if(ir.value==IR_6&&menu2==1){menu1=1;menu2=0;menu=0;gr1=0;gr2=0;cl();times=millis();w=1;w2=1;lcd.setCursor(6,0);lcd.print("MENU"); delay(2000);lcd.clear();}
  
  if(ir.value==IR_1&&menu1==1){menu++;gr1=0;gr2=0;cl();times=millis();w=1;w2=1;if(menu>2){menu=0;}}//меню 1
  if(ir.value==IR_2&&menu1==1){menu--;gr1=0;gr2=0;cl();times=millis();w=1;w2=1;if(menu<0){menu=2;}}//меню 1
  
  if(ir.value==IR_1&&menu2==1){menu0++;gr1=0;gr2=0;cl();times=millis();w=1;w2=1;if(menu0>4){menu0=0;}}//меню 2
  if(ir.value==IR_2&&menu2==1){menu0--;gr1=0;gr2=0;cl();times=millis();w=1;w2=1;if(menu0<0){menu0=4;}}//меню 2

  if(ir.value==IR_5){in++;gr1=0;gr2=0;cl();times=millis();w=1;w2=1;if(in>3){in=0;}lcd.setCursor(4,0);lcd.print("INPUT ");lcd.print(in+1);audio();delay(2000);lcd.clear();}// IN
  }
  
  if(ir.value==IR_7&&mute==0&&power==0){mute=1;pt.setAttR(31);pt.setAttL(31);gr1=0;gr2=0;cl();lcd.setCursor(6,0);lcd.print("MUTE");menu1=100;menu2=100;delay(500);}// MUTE
  if(ir.value==IR_7&&mute==1&&power==0){mute=0;cl();menu1=1;menu=0;gr1=0;gr2=0;cl();audio();}// MUTE

  if(ir.value==IR_8&&power==0){power=1;pt.setAttR(31);pt.setAttL(31);audio();gr1=0;gr2=0;cl();lcd.clear();lcd.setCursor(3,0);lcd.print("POWER  OFF");menu0=0;menu1=0;menu2=0;save=1;analogWrite(6, BRIG);delay(3000);lcd.clear();}// power off
  if(ir.value==IR_8&&power==1){power=0;gr1=0;gr2=0;cl();lcd.backlight();lcd.clear();lcd.setCursor(3,0);lcd.print("POWER   ON ");menu1=1;menu=0;myEnc.write(0);audio();analogWrite(6, brig);delay(3000);lcd.clear();}// power on
///////////////////////////////////////////////////////////////////////////////////////// 

/////////////////////////////// УПРАВЛЕНИЕ //////////////////////////////////////////////  
  if(mute==0&&power==0){
  if(digitalRead(2)==HIGH&&menu1==1){menu1=0;menu2=1;cl();times=millis();w=1;w2=1;lcd.setCursor(4,0);lcd.print("SETTING"); delay(2000);lcd.clear();}
  if(digitalRead(2)==HIGH&&menu2==1){menu1=1;menu2=0;menu=0;cl();times=millis();w=1;w2=1;lcd.setCursor(6,0);lcd.print("MENU"); delay(2000);lcd.clear();}
  
  if(digitalRead(10)==LOW&&menu1==1){menu++;cl();times=millis();w=1;w2=1;if(menu>2){menu=0;}}//меню 1
  if(digitalRead(10)==LOW&&menu2==1){menu0++;cl();times=millis();w=1;w2=1;if(menu0>4){menu0=0;}}//меню 2

  if(digitalRead(3)==HIGH){in++;cl();;times=millis();w=1;w2=1;if(in>3){in=0;}lcd.setCursor(4,0);lcd.print("INPUT ");lcd.print(in+1);audio();delay(2000);lcd.clear();}// IN
  }
  
  if(digitalRead(4)==HIGH&&mute==0&&power==0){mute=1;pt.setAttR(31);pt.setAttL(31);cl();lcd.setCursor(6,0);lcd.print("MUTE");menu1=100;menu2=100;delay(500);}// MUTE
  if(digitalRead(4)==HIGH&&mute==1&&power==0){mute=0;cl();menu1=1;menu=0;cl();audio();}// MUTE

  if(digitalRead(5)==HIGH&&power==0){power=1;pt.setAttR(31);pt.setAttL(31);lcd.clear();lcd.setCursor(3,0);lcd.print("POWER  OFF");menu0=0;menu1=0;menu2=0;save=1;analogWrite(6, 50);delay(3000);lcd.clear();}// power off
  if(digitalRead(5)==HIGH&&power==1){power=0;lcd.backlight();lcd.clear();lcd.setCursor(3,0);lcd.print("POWER   ON ");menu1=1;menu=0;myEnc.write(0);audio();analogWrite(6, brig);delay(3000);lcd.clear();}// power on
    if(power==0){digitalWrite(7,HIGH);}
  //if(power==0){digitalWrite(7,LOW);}// инверсия выхода STANDBY

  if(save==1&&w2==1){save=0;w2=0;
     EEPROM.update(0,vol);EEPROM.update(1,treb+7);EEPROM.update(2,bass+7);EEPROM.update(3,in);
     EEPROM.update(4,att_l);EEPROM.update(5,att_r);EEPROM.update(6,gain1);EEPROM.update(7,gain2);
     EEPROM.update(8,gain3);EEPROM.update(9,gain4);EEPROM.update(10,loud_on);EEPROM.update(11,brig);}
///////////////////////////////////////////////////////////////////////////////////////// 

////////////// VOLUME ///////////////////////////////////////////////////////////////////
 if(menu==0&&menu1==1){
   if(ir.value==IR_3){vol++;gr1=1;gr2=0;cl1();times=millis();w=1;w2=1;vol_func();audio();}// кнопка > 
   if(ir.value==0xFFFFFFFF and gr1==1){vol++;gr2=0;cl1();times=millis();w=1;w2=1;vol_func();audio();}// кнопка >>>>>>
   if(ir.value==IR_4){vol--;gr1=0;gr2=1;cl1();times=millis();w=1;w2=1;vol_func();audio();}// кнопка <
   if(ir.value==0xFFFFFFFF and gr2==1){vol--;gr1=0;cl1();times=millis();w=1;w2=1;vol_func();audio();}// кнопка <<<<<<
  
   if (newPosition != oldPosition){oldPosition = newPosition;vol=vol+newPosition;myEnc.write(0);newPosition=0;times=millis();w=1;w2=1;vol_func();audio();}
   a[0]= vol/10;a[1]=vol%10;
   for(i=0;i<2;i++){switch(i){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("IN");lcd.print(in+1);lcd.print("  VOL");
   if(vol<0){lcd.setCursor(9,1);lcd.write((uint8_t)8);}else{lcd.setCursor(9,1);lcd.print(" ");}
   times_f();
   }
////////////////////////////////////////////////////////////////////////////////////////////

////////////// BASS ///////////////////////////////////////////////////////////////////
 if(menu==1&&menu1==1){
   if(ir.value==IR_3){bass++;gr1=1;gr2=0;cl1();times=millis();w=1;w2=1;bass_func();audio();}// кнопка > 
   if(ir.value==0xFFFFFFFF and gr1==1){bass++;gr2=0;cl1();times=millis();w=1;w2=1;bass_func();audio();}// кнопка >>>>>>
   if(ir.value==IR_4){bass--;gr1=0;gr2=1;cl1();times=millis();w=1;w2=1;bass_func();audio();}// кнопка <
   if(ir.value==0xFFFFFFFF and gr2==1){bass--;gr1=0;cl1();times=millis();w=1;w2=1;bass_func();audio();}// кнопка <<<<<<
  
   if (newPosition != oldPosition){oldPosition = newPosition;bass=bass+newPosition;myEnc.write(0);newPosition=0;times=millis();w=1;w2=1;bass_func();audio();}
   a[0]= abs(bass*2)/10;a[1]=abs(bass*2)%10;
   for(i=0;i<2;i++){switch(i){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   dB");
   if(bass<0){lcd.setCursor(9,1);lcd.write((uint8_t)8);}else{lcd.setCursor(9,1);lcd.print(" ");}
   times_f();
   }
////////////////////////////////////////////////////////////////////////////////////////////

////////////// TREBLE ///////////////////////////////////////////////////////////////////
 if(menu==2&&menu1==1){
   if(ir.value==IR_3){treb++;gr1=1;gr2=0;cl1();times=millis();w=1;w2=1;treb_func();audio();}// кнопка > 
   if(ir.value==0xFFFFFFFF and gr1==1){treb++;gr2=0;cl1();times=millis();w=1;w2=1;treb_func();audio();}// кнопка >>>>>>
   if(ir.value==IR_4){treb--;gr1=0;gr2=1;cl1();times=millis();w=1;w2=1;treb_func();audio();}// кнопка <
   if(ir.value==0xFFFFFFFF and gr2==1){treb--;gr1=0;cl1();times=millis();w=1;w2=1;treb_func();audio();}// кнопка <<<<<<
   
   if (newPosition != oldPosition){oldPosition = newPosition;treb=treb+newPosition;myEnc.write(0);newPosition=0;times=millis();w=1;w2=1;treb_func();audio();}
   a[0]= abs(treb*2)/10;a[1]=abs(treb*2)%10;
  
   for(i=0;i<2;i++){switch(i){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 dB");
   if(treb<0){lcd.setCursor(9,1);lcd.write((uint8_t)8);}else{lcd.setCursor(9,1);lcd.print(" ");}
   times_f();
   }
////////////////////////////////////////////////////////////////////////////////////////////

////////////// ATT_L ///////////////////////////////////////////////////////////////////
 if(menu0==0&&menu2==1){
   if(ir.value==IR_3){att_l++;gr1=1;gr2=0;cl1();times=millis();w=1;w2=1;att_l_func();audio();}// кнопка > 
   if(ir.value==0xFFFFFFFF and gr1==1){att_l++;gr2=0;cl1();times=millis();w=1;w2=1;att_l_func();audio();}// кнопка >>>>>>
   if(ir.value==IR_4){att_l--;gr1=0;gr2=1;cl1();times=millis();w=1;w2=1;att_l_func();audio();}// кнопка <
   if(ir.value==0xFFFFFFFF and gr2==1){att_l--;gr1=0;cl1();times=millis();w=1;w2=1;att_l_func();audio();}// кнопка <<<<<<
  
   if (newPosition != oldPosition){oldPosition = newPosition;att_l=att_l+newPosition;myEnc.write(0);newPosition=0;times=millis();w=1;w2=1;att_l_func();audio();}
   a[0]= abs(att_l)/10;a[1]=abs(att_l)%10;
   for(i=0;i<2;i++){switch(i){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_L");
   lcd.setCursor(0,1);lcd.print(-att_l*1.25,2);lcd.print(" ");lcd.setCursor(6,1);lcd.print("dB");}
////////////////////////////////////////////////////////////////////////////////////////////

////////////// ATT_R ///////////////////////////////////////////////////////////////////
 if(menu0==1&&menu2==1){
   if(ir.value==IR_3){att_r++;gr1=1;gr2=0;cl1();times=millis();w=1;w2=1;att_r_func();audio();}// кнопка > 
   if(ir.value==0xFFFFFFFF and gr1==1){att_r++;gr2=0;cl1();times=millis();w=1;w2=1;att_r_func();audio();}// кнопка >>>>>>
   if(ir.value==IR_4){att_r--;gr1=0;gr2=1;cl1();times=millis();w=1;w2=1;att_r_func();audio();}// кнопка <
   if(ir.value==0xFFFFFFFF and gr2==1){att_r--;gr1=0;cl1();times=millis();w=1;w2=1;att_r_func();audio();}// кнопка <<<<<<
  
   if (newPosition != oldPosition){oldPosition = newPosition;att_r=att_r+newPosition;myEnc.write(0);newPosition=0;times=millis();w=1;w2=1;att_r_func();audio();}
   a[0]= abs(att_r)/10;a[1]=abs(att_r)%10;
   for(i=0;i<2;i++){switch(i){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_R");
   lcd.setCursor(0,1);lcd.print(-att_r*1.25,2);lcd.print(" ");lcd.setCursor(6,1);lcd.print("dB");}
////////////////////////////////////////////////////////////////////////////////////////////

////////////// INPUT GAIN ///////////////////////////////////////////////////////////////////
 if(menu0==2&&menu2==1){
   switch(in){
     case 0: gain0 = gain1;break;
     case 1: gain0 = gain2;break;
     case 2: gain0 = gain3;break;
     case 3: gain0 = gain4;break;
     }

   if(ir.value==IR_3){gain0++;gr1=1;gr2=0;cl1();times=millis();w=1;w2=1;gain_func();www=1;}// кнопка > 
   if(ir.value==0xFFFFFFFF and gr1==1){gain0++;gr2=0;cl1();times=millis();w=1;w2=1;gain_func();www=1;}// кнопка >>>>>>
   if(ir.value==IR_4){gain0--;gr1=0;gr2=1;cl1();times=millis();w=1;w2=1;gain_func();www=1;}// кнопка <
   if(ir.value==0xFFFFFFFF and gr2==1){gain0--;gr1=0;cl1();times=millis();w=1;w2=1;gain_func();www=1;}// кнопка <<<<<<
     
   if (newPosition != oldPosition){oldPosition = newPosition;gain0=gain0+newPosition;myEnc.write(0);newPosition=0;times=millis();www=1;w=1;w2=1;gain_func();}
 
  switch(in){
     case 0: gain1 = gain0;break;
     case 1: gain2 = gain0;break;
     case 2: gain3 = gain0;break;
     case 3: gain4 = gain0;break;
     }  
     a[0]= abs(gain0);
   
   for(i=0;i<1;i++){switch(i){case 0: e1=13,e2=14,e3=15;break;case 1: e1=13,e2=14,e3=15;break;}digit();}
   lcd.setCursor(0,1);lcd.print("GAIN ");lcd.print(gain0*3.75,2);lcd.print(" ");lcd.setCursor(10,1);lcd.print("dB");
   if(www==1){audio();www=0;}
   lcd.setCursor(0,0);lcd.print("INPUT ");lcd.print(in+1);}
////////////////////////////////////////////////////////////////////////////////////////////

////////////// LOUDNESS ///////////////////////////////////////////////////////////////////
 if(menu0==3&&menu2==1){
   if(ir.value==IR_3){loud_on++;gr1=1;gr2=0;cl1();times=millis();w=1;w2=1;if(loud_on>1){loud_on=0;};if(loud_on<0){loud_on=1;}audio();}// кнопка > 
   if(ir.value==0xFFFFFFFF and gr1==1){loud_on++;gr2=0;cl1();times=millis();w=1;w2=1;if(loud_on>1){loud_on=0;};if(loud_on<0){loud_on=1;}audio();}// кнопка >>>>>>
   if(ir.value==IR_4){loud_on--;gr1=0;gr2=1;cl1();times=millis();w=1;w2=1;if(loud_on>1){loud_on=0;};if(loud_on<0){loud_on=1;}audio();}// кнопка <
   if(ir.value==0xFFFFFFFF and gr2==1){loud_on--;gr1=0;cl1();times=millis();w=1;w2=1;if(loud_on>1){loud_on=0;};if(loud_on<0){loud_on=1;}audio();}// кнопка <<<<<<
  
   if (newPosition != oldPosition){oldPosition = newPosition;loud_on=loud_on+newPosition;myEnc.write(0);newPosition=0;times=millis();w=1;w2=1;if(loud_on>1){loud_on=0;};if(loud_on<0){loud_on=1;};audio();}
   if(loud_on==1){lcd.setCursor(2,0);lcd.print("LOUDNESS  ON ");}
             else{lcd.setCursor(2,0);lcd.print("LOUDNESS  OFF");}}
////////////////////////////////////////////////////////////////////////////////////////////

////////////// BRIGHTNESS ///////////////////////////////////////////////////////////////////
 if(menu0==4&&menu2==1){
   if(ir.value==IR_3){brig++;gr1=1;gr2=0;cl1();times=millis();w=1;w2=1;brig_func();analogWrite(6,brig);}// кнопка > 
   if(ir.value==0xFFFFFFFF and gr1==1){brig++;gr2=0;cl1();times=millis();w=1;w2=1;brig_func();analogWrite(6,brig);}// кнопка >>>>>>
   if(ir.value==IR_4){brig--;gr1=0;gr2=1;cl1();times=millis();w=1;w2=1;brig_func();analogWrite(6,brig);}// кнопка <
   if(ir.value==0xFFFFFFFF and gr2==1){brig--;gr1=0;cl1();times=millis();w=1;w2=1;brig_func();analogWrite(6,brig);}// кнопка <<<<<<
     
   if (newPosition != oldPosition){oldPosition = newPosition;brig=brig+newPosition;myEnc.write(0);newPosition=0;times=millis();w=1;w2=1;brig_func();analogWrite(6,brig);}
   a[0]= abs(brig)/100;a[1]=abs(brig)/10%10;a[2]=abs(brig)%10;
   for(i=0;i<3;i++){switch(i){case 0: e1=7,e2=8,e3=9;break;
                              case 1: e1=10,e2=11,e3=12;break;
                              case 2: e1=13,e2=14,e3=15;break;
                              }digit();}
   
   lcd.setCursor(0,0);lcd.print("BRIGHT");
   lcd.setCursor(0,1);lcd.print(brig*100/255);lcd.print(" ");lcd.setCursor(4,1);lcd.print("%");}
////////////////////////////////////////////////////////////////////////////////////////////

if(millis()-times>10000&&w==1&&mute==0&&power==0){w=0;menu2=0;menu1=1;menu=0;cl();}

/////////////////// ЧАСЫ ///////////////////////////////////////////////////////////////////
if(power==1){digitalWrite(7,LOW);
     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(i=0;i<4;i++){
    switch(i){
        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(2)==HIGH){hour++;if(hour>23){hour=0;} clock.setDateTime(2020, 9, 15, hour, minut, secon);delay(100);}
  if(digitalRead(10)==LOW&&digitalRead(3)==HIGH){minut++;if(minut>59){minut=0;} clock.setDateTime(2020, 9, 15, hour, minut, secon);delay(100); }
  if(digitalRead(10)==LOW&&digitalRead(4)==HIGH){secon=0; clock.setDateTime(2020, 9, 15, hour, minut, secon);delay(100); }
}
////////////////////////////////////////////////////////////////////////////////////////////
}// loop


void times_f(){lcd.setCursor(0,1);lcd.print(DateTime.hour/10);lcd.print(DateTime.hour%10);lcd.print(":");lcd.print(DateTime.minute/10);lcd.print(DateTime.minute%10);lcd.print(":");lcd.print(DateTime.second/10);lcd.print(DateTime.second%10);}
void brig_func(){if(brig<0){brig=0;}if(brig>255){brig=255;}}
void gain_func(){if(gain0<0){gain0=0;}if(gain0>3){gain0=3;}}
void att_r_func(){if(att_r<0){att_r=0;}if(att_r>24){att_r=24;}}
void att_l_func(){if(att_l<0){att_l=0;}if(att_l>24){att_l=24;}}
void treb_func(){if(treb<-7){treb=-7;}if(treb>7){treb=7;}}
void bass_func(){if(bass<-7){bass=-7;}if(bass>7){bass=7;}}
void vol_func(){if(vol<0){vol=0;}if(vol>56){vol=56;}}
void cl(){ir.value=0;delay(300);lcd.clear();}
void cl1(){ir.value=0;delay(200);}  
void audio(){
  pt.setVolume(vol); // int 0...56 === -70...0 dB step 1.25 dB
  pt.setAttL(att_l); // int 0...24 === 0...-30 db step 1.25 dB > int 31 === mute on     
  pt.setAttR(att_r); // int 0...24 === 0...-30 dB step 1.25 dB > int 31 === mute on
  pt.setSwitch(in, loud_on, gain0); 
        // input      int 0..3 === IN 1...4 
        // loudness   int 0...1 === 1-on 0-off
        // input gain int 0...3 === 0...11.25dB step 3.75 dB
  pt.setBass(bass);   // int -7...+7 === -14...+14 dB step 2 dB
  pt.setTreble(treb); // int -7...+7 === -14...+14 dB step 2 dB
  }

void to_Timer(){newPosition = myEnc.read()/4;}  

void digit(){switch(a[i]){
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);}

91

Re: PT2314

В железе не проверял, после подачи питания регулятор должен переходить в режим POWER OFF

#define IR_1 0x2FDD02F // Кнопка вверх
#define IR_2 0x2FD32CD // Кнопка вниз
#define IR_3 0x2FD906F // Кнопка >
#define IR_4 0x2FDF20D // Кнопка <
#define IR_5 0x2FD708F // Кнопка IN
#define IR_6 0x2FD6A95 // Кнопка SET
#define IR_7 0x2FD00FF // Кнопка MUTE
#define IR_8 0x2FDB24D // Кнопка STANDBY (POWER)
#define BRIG 50        // Яркость подсветки экрана в режиме POWER OFF (0...255)
#include <Wire.h> 
#include <PT2314.h>            // http://forum.rcl-radio.ru/misc.php?action=pan_download&item=434&download=1
#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
   DS3231 clock;RTCDateTime DateTime;
   PT2314 pt;
   LiquidCrystal_I2C lcd(0x27,16,2);  // Устанавливаем дисплей
   IRrecv irrecv(12); // указываем вывод модуля IR приемника
   Encoder myEnc(8, 9);// DT, CLK
   decode_results ir; 
      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};
      byte a[6],d1,d2,d3,d4,d5,d6,e1,e2,e3,w,w2,i,www,power,save,gr1,gr2,poww=1;;
      int menu,menu0,menu1=1,menu2=0,vol,bass,treb,att_l,att_r,in,loud_on,gain0,gain1,gain2,gain3,gain4,mute,mute1,mute2,brig,hour,minut,secon;
      unsigned long times,oldPosition  = -999,newPosition;

void setup() {
  irrecv.enableIRIn();lcd.init();lcd.backlight();clock.begin();Serial.begin(9600);
  pinMode(10,INPUT);  // МЕНЮ КНОПКА SW энкодера
  pinMode(2,INPUT);   // КНОПКА SET
  pinMode(3,INPUT);   // КНОПКА IN
  pinMode(4,INPUT);   // КНОПКА MUTE
  pinMode(5,INPUT);   // КНОПКА STANDBY
  pinMode(7,OUTPUT);  // ВЫХОД УПРАВЛЕНИЯ STANDBY
  pinMode(6,OUTPUT);  // ВЫХОД УПРАВЛЕНИЯ ПОДСВЕТКОЙ
  analogWrite(6, 255);
  lcd.setCursor(0,0);lcd.print("Sound Processor");lcd.setCursor(0,1);lcd.print("PT2314"); delay(2000);lcd.clear();
  MsTimer2::set(1, to_Timer);MsTimer2::start();
  //  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);
  if(EEPROM.read(100)!=0){for(int i=0;i<101;i++){EEPROM.update(i,0);}}// очистка памяти при первом включении  
  vol = EEPROM.read(0);treb = EEPROM.read(1)-7;bass = EEPROM.read(2)-7;in = EEPROM.read(3);
  att_l = EEPROM.read(4);att_r = EEPROM.read(5);gain1 = EEPROM.read(6);gain2 = EEPROM.read(7);
  gain3 = EEPROM.read(8);gain4 = EEPROM.read(9);loud_on = EEPROM.read(10);brig = EEPROM.read(11);
  audio();
  analogWrite(6, brig);
}

void loop() {
  DateTime = clock.getDateTime();hour = DateTime.hour;minut = DateTime.minute;secon = DateTime.second;

////////////////////// 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;}// запрет нажатий не активных кнопок пульта  

    if(mute==0&&power==0){
  if(ir.value==IR_6&&menu1==1){menu1=0;menu2=1;gr1=0;gr2=0;cl();times=millis();w=1;w2=1;lcd.setCursor(4,0);lcd.print("SETTING"); delay(2000);lcd.clear();}
  if(ir.value==IR_6&&menu2==1){menu1=1;menu2=0;menu=0;gr1=0;gr2=0;cl();times=millis();w=1;w2=1;lcd.setCursor(6,0);lcd.print("MENU"); delay(2000);lcd.clear();}
  
  if(ir.value==IR_1&&menu1==1){menu++;gr1=0;gr2=0;cl();times=millis();w=1;w2=1;if(menu>2){menu=0;}}//меню 1
  if(ir.value==IR_2&&menu1==1){menu--;gr1=0;gr2=0;cl();times=millis();w=1;w2=1;if(menu<0){menu=2;}}//меню 1
  
  if(ir.value==IR_1&&menu2==1){menu0++;gr1=0;gr2=0;cl();times=millis();w=1;w2=1;if(menu0>4){menu0=0;}}//меню 2
  if(ir.value==IR_2&&menu2==1){menu0--;gr1=0;gr2=0;cl();times=millis();w=1;w2=1;if(menu0<0){menu0=4;}}//меню 2

  if(ir.value==IR_5){in++;gr1=0;gr2=0;cl();times=millis();w=1;w2=1;if(in>3){in=0;}lcd.setCursor(4,0);lcd.print("INPUT ");lcd.print(in+1);audio();delay(2000);lcd.clear();}// IN
  }
  
  if(ir.value==IR_7&&mute==0&&power==0){mute=1;pt.setAttR(31);pt.setAttL(31);gr1=0;gr2=0;cl();lcd.setCursor(6,0);lcd.print("MUTE");menu1=100;menu2=100;delay(500);}// MUTE
  if(ir.value==IR_7&&mute==1&&power==0){mute=0;cl();menu1=1;menu=0;gr1=0;gr2=0;cl();audio();}// MUTE

  if((ir.value==IR_8&&power==0)||poww==1){poww=0;power=1;pt.setAttR(31);pt.setAttL(31);audio();gr1=0;gr2=0;cl();lcd.clear();lcd.setCursor(3,0);lcd.print("POWER  OFF");menu0=0;menu1=0;menu2=0;save=1;analogWrite(6, BRIG);delay(3000);lcd.clear();}// power off
  if(ir.value==IR_8&&power==1){power=0;gr1=0;gr2=0;cl();lcd.backlight();lcd.clear();lcd.setCursor(3,0);lcd.print("POWER   ON ");menu1=1;menu=0;myEnc.write(0);audio();analogWrite(6, brig);delay(3000);lcd.clear();}// power on
///////////////////////////////////////////////////////////////////////////////////////// 

/////////////////////////////// УПРАВЛЕНИЕ //////////////////////////////////////////////  
  if(mute==0&&power==0){
  if(digitalRead(2)==HIGH&&menu1==1){menu1=0;menu2=1;cl();times=millis();w=1;w2=1;lcd.setCursor(4,0);lcd.print("SETTING"); delay(2000);lcd.clear();}
  if(digitalRead(2)==HIGH&&menu2==1){menu1=1;menu2=0;menu=0;cl();times=millis();w=1;w2=1;lcd.setCursor(6,0);lcd.print("MENU"); delay(2000);lcd.clear();}
  
  if(digitalRead(10)==LOW&&menu1==1){menu++;cl();times=millis();w=1;w2=1;if(menu>2){menu=0;}}//меню 1
  if(digitalRead(10)==LOW&&menu2==1){menu0++;cl();times=millis();w=1;w2=1;if(menu0>4){menu0=0;}}//меню 2

  if(digitalRead(3)==HIGH){in++;cl();;times=millis();w=1;w2=1;if(in>3){in=0;}lcd.setCursor(4,0);lcd.print("INPUT ");lcd.print(in+1);audio();delay(2000);lcd.clear();}// IN
  }
  
  if(digitalRead(4)==HIGH&&mute==0&&power==0){mute=1;pt.setAttR(31);pt.setAttL(31);cl();lcd.setCursor(6,0);lcd.print("MUTE");menu1=100;menu2=100;delay(500);}// MUTE
  if(digitalRead(4)==HIGH&&mute==1&&power==0){mute=0;cl();menu1=1;menu=0;cl();audio();}// MUTE

  if(digitalRead(5)==HIGH&&power==0){power=1;pt.setAttR(31);pt.setAttL(31);lcd.clear();lcd.setCursor(3,0);lcd.print("POWER  OFF");menu0=0;menu1=0;menu2=0;save=1;analogWrite(6, 50);delay(3000);lcd.clear();}// power off
  if(digitalRead(5)==HIGH&&power==1){power=0;lcd.backlight();lcd.clear();lcd.setCursor(3,0);lcd.print("POWER   ON ");menu1=1;menu=0;myEnc.write(0);audio();analogWrite(6, brig);delay(3000);lcd.clear();}// power on
    if(power==0){digitalWrite(7,HIGH);}
  //if(power==0){digitalWrite(7,LOW);}// инверсия выхода STANDBY

  if(save==1&&w2==1){save=0;w2=0;
     EEPROM.update(0,vol);EEPROM.update(1,treb+7);EEPROM.update(2,bass+7);EEPROM.update(3,in);
     EEPROM.update(4,att_l);EEPROM.update(5,att_r);EEPROM.update(6,gain1);EEPROM.update(7,gain2);
     EEPROM.update(8,gain3);EEPROM.update(9,gain4);EEPROM.update(10,loud_on);EEPROM.update(11,brig);}
///////////////////////////////////////////////////////////////////////////////////////// 

////////////// VOLUME ///////////////////////////////////////////////////////////////////
 if(menu==0&&menu1==1){
   if(ir.value==IR_3){vol++;gr1=1;gr2=0;cl1();times=millis();w=1;w2=1;vol_func();audio();}// кнопка > 
   if(ir.value==0xFFFFFFFF and gr1==1){vol++;gr2=0;cl1();times=millis();w=1;w2=1;vol_func();audio();}// кнопка >>>>>>
   if(ir.value==IR_4){vol--;gr1=0;gr2=1;cl1();times=millis();w=1;w2=1;vol_func();audio();}// кнопка <
   if(ir.value==0xFFFFFFFF and gr2==1){vol--;gr1=0;cl1();times=millis();w=1;w2=1;vol_func();audio();}// кнопка <<<<<<
  
   if (newPosition != oldPosition){oldPosition = newPosition;vol=vol+newPosition;myEnc.write(0);newPosition=0;times=millis();w=1;w2=1;vol_func();audio();}
   a[0]= vol/10;a[1]=vol%10;
   for(i=0;i<2;i++){switch(i){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("IN");lcd.print(in+1);lcd.print("  VOL");
   if(vol<0){lcd.setCursor(9,1);lcd.write((uint8_t)8);}else{lcd.setCursor(9,1);lcd.print(" ");}
   times_f();
   }
////////////////////////////////////////////////////////////////////////////////////////////

////////////// BASS ///////////////////////////////////////////////////////////////////
 if(menu==1&&menu1==1){
   if(ir.value==IR_3){bass++;gr1=1;gr2=0;cl1();times=millis();w=1;w2=1;bass_func();audio();}// кнопка > 
   if(ir.value==0xFFFFFFFF and gr1==1){bass++;gr2=0;cl1();times=millis();w=1;w2=1;bass_func();audio();}// кнопка >>>>>>
   if(ir.value==IR_4){bass--;gr1=0;gr2=1;cl1();times=millis();w=1;w2=1;bass_func();audio();}// кнопка <
   if(ir.value==0xFFFFFFFF and gr2==1){bass--;gr1=0;cl1();times=millis();w=1;w2=1;bass_func();audio();}// кнопка <<<<<<
  
   if (newPosition != oldPosition){oldPosition = newPosition;bass=bass+newPosition;myEnc.write(0);newPosition=0;times=millis();w=1;w2=1;bass_func();audio();}
   a[0]= abs(bass*2)/10;a[1]=abs(bass*2)%10;
   for(i=0;i<2;i++){switch(i){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   dB");
   if(bass<0){lcd.setCursor(9,1);lcd.write((uint8_t)8);}else{lcd.setCursor(9,1);lcd.print(" ");}
   times_f();
   }
////////////////////////////////////////////////////////////////////////////////////////////

////////////// TREBLE ///////////////////////////////////////////////////////////////////
 if(menu==2&&menu1==1){
   if(ir.value==IR_3){treb++;gr1=1;gr2=0;cl1();times=millis();w=1;w2=1;treb_func();audio();}// кнопка > 
   if(ir.value==0xFFFFFFFF and gr1==1){treb++;gr2=0;cl1();times=millis();w=1;w2=1;treb_func();audio();}// кнопка >>>>>>
   if(ir.value==IR_4){treb--;gr1=0;gr2=1;cl1();times=millis();w=1;w2=1;treb_func();audio();}// кнопка <
   if(ir.value==0xFFFFFFFF and gr2==1){treb--;gr1=0;cl1();times=millis();w=1;w2=1;treb_func();audio();}// кнопка <<<<<<
   
   if (newPosition != oldPosition){oldPosition = newPosition;treb=treb+newPosition;myEnc.write(0);newPosition=0;times=millis();w=1;w2=1;treb_func();audio();}
   a[0]= abs(treb*2)/10;a[1]=abs(treb*2)%10;
  
   for(i=0;i<2;i++){switch(i){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 dB");
   if(treb<0){lcd.setCursor(9,1);lcd.write((uint8_t)8);}else{lcd.setCursor(9,1);lcd.print(" ");}
   times_f();
   }
////////////////////////////////////////////////////////////////////////////////////////////

////////////// ATT_L ///////////////////////////////////////////////////////////////////
 if(menu0==0&&menu2==1){
   if(ir.value==IR_3){att_l++;gr1=1;gr2=0;cl1();times=millis();w=1;w2=1;att_l_func();audio();}// кнопка > 
   if(ir.value==0xFFFFFFFF and gr1==1){att_l++;gr2=0;cl1();times=millis();w=1;w2=1;att_l_func();audio();}// кнопка >>>>>>
   if(ir.value==IR_4){att_l--;gr1=0;gr2=1;cl1();times=millis();w=1;w2=1;att_l_func();audio();}// кнопка <
   if(ir.value==0xFFFFFFFF and gr2==1){att_l--;gr1=0;cl1();times=millis();w=1;w2=1;att_l_func();audio();}// кнопка <<<<<<
  
   if (newPosition != oldPosition){oldPosition = newPosition;att_l=att_l+newPosition;myEnc.write(0);newPosition=0;times=millis();w=1;w2=1;att_l_func();audio();}
   a[0]= abs(att_l)/10;a[1]=abs(att_l)%10;
   for(i=0;i<2;i++){switch(i){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_L");
   lcd.setCursor(0,1);lcd.print(-att_l*1.25,2);lcd.print(" ");lcd.setCursor(6,1);lcd.print("dB");}
////////////////////////////////////////////////////////////////////////////////////////////

////////////// ATT_R ///////////////////////////////////////////////////////////////////
 if(menu0==1&&menu2==1){
   if(ir.value==IR_3){att_r++;gr1=1;gr2=0;cl1();times=millis();w=1;w2=1;att_r_func();audio();}// кнопка > 
   if(ir.value==0xFFFFFFFF and gr1==1){att_r++;gr2=0;cl1();times=millis();w=1;w2=1;att_r_func();audio();}// кнопка >>>>>>
   if(ir.value==IR_4){att_r--;gr1=0;gr2=1;cl1();times=millis();w=1;w2=1;att_r_func();audio();}// кнопка <
   if(ir.value==0xFFFFFFFF and gr2==1){att_r--;gr1=0;cl1();times=millis();w=1;w2=1;att_r_func();audio();}// кнопка <<<<<<
  
   if (newPosition != oldPosition){oldPosition = newPosition;att_r=att_r+newPosition;myEnc.write(0);newPosition=0;times=millis();w=1;w2=1;att_r_func();audio();}
   a[0]= abs(att_r)/10;a[1]=abs(att_r)%10;
   for(i=0;i<2;i++){switch(i){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_R");
   lcd.setCursor(0,1);lcd.print(-att_r*1.25,2);lcd.print(" ");lcd.setCursor(6,1);lcd.print("dB");}
////////////////////////////////////////////////////////////////////////////////////////////

////////////// INPUT GAIN ///////////////////////////////////////////////////////////////////
 if(menu0==2&&menu2==1){
   switch(in){
     case 0: gain0 = gain1;break;
     case 1: gain0 = gain2;break;
     case 2: gain0 = gain3;break;
     case 3: gain0 = gain4;break;
     }

   if(ir.value==IR_3){gain0++;gr1=1;gr2=0;cl1();times=millis();w=1;w2=1;gain_func();www=1;}// кнопка > 
   if(ir.value==0xFFFFFFFF and gr1==1){gain0++;gr2=0;cl1();times=millis();w=1;w2=1;gain_func();www=1;}// кнопка >>>>>>
   if(ir.value==IR_4){gain0--;gr1=0;gr2=1;cl1();times=millis();w=1;w2=1;gain_func();www=1;}// кнопка <
   if(ir.value==0xFFFFFFFF and gr2==1){gain0--;gr1=0;cl1();times=millis();w=1;w2=1;gain_func();www=1;}// кнопка <<<<<<
     
   if (newPosition != oldPosition){oldPosition = newPosition;gain0=gain0+newPosition;myEnc.write(0);newPosition=0;times=millis();www=1;w=1;w2=1;gain_func();}
 
  switch(in){
     case 0: gain1 = gain0;break;
     case 1: gain2 = gain0;break;
     case 2: gain3 = gain0;break;
     case 3: gain4 = gain0;break;
     }  
     a[0]= abs(gain0);
   
   for(i=0;i<1;i++){switch(i){case 0: e1=13,e2=14,e3=15;break;case 1: e1=13,e2=14,e3=15;break;}digit();}
   lcd.setCursor(0,1);lcd.print("GAIN ");lcd.print(gain0*3.75,2);lcd.print(" ");lcd.setCursor(10,1);lcd.print("dB");
   if(www==1){audio();www=0;}
   lcd.setCursor(0,0);lcd.print("INPUT ");lcd.print(in+1);}
////////////////////////////////////////////////////////////////////////////////////////////

////////////// LOUDNESS ///////////////////////////////////////////////////////////////////
 if(menu0==3&&menu2==1){
   if(ir.value==IR_3){loud_on++;gr1=1;gr2=0;cl1();times=millis();w=1;w2=1;if(loud_on>1){loud_on=0;};if(loud_on<0){loud_on=1;}audio();}// кнопка > 
   if(ir.value==0xFFFFFFFF and gr1==1){loud_on++;gr2=0;cl1();times=millis();w=1;w2=1;if(loud_on>1){loud_on=0;};if(loud_on<0){loud_on=1;}audio();}// кнопка >>>>>>
   if(ir.value==IR_4){loud_on--;gr1=0;gr2=1;cl1();times=millis();w=1;w2=1;if(loud_on>1){loud_on=0;};if(loud_on<0){loud_on=1;}audio();}// кнопка <
   if(ir.value==0xFFFFFFFF and gr2==1){loud_on--;gr1=0;cl1();times=millis();w=1;w2=1;if(loud_on>1){loud_on=0;};if(loud_on<0){loud_on=1;}audio();}// кнопка <<<<<<
  
   if (newPosition != oldPosition){oldPosition = newPosition;loud_on=loud_on+newPosition;myEnc.write(0);newPosition=0;times=millis();w=1;w2=1;if(loud_on>1){loud_on=0;};if(loud_on<0){loud_on=1;};audio();}
   if(loud_on==1){lcd.setCursor(2,0);lcd.print("LOUDNESS  ON ");}
             else{lcd.setCursor(2,0);lcd.print("LOUDNESS  OFF");}}
////////////////////////////////////////////////////////////////////////////////////////////

////////////// BRIGHTNESS ///////////////////////////////////////////////////////////////////
 if(menu0==4&&menu2==1){
   if(ir.value==IR_3){brig++;gr1=1;gr2=0;cl1();times=millis();w=1;w2=1;brig_func();analogWrite(6,brig);}// кнопка > 
   if(ir.value==0xFFFFFFFF and gr1==1){brig++;gr2=0;cl1();times=millis();w=1;w2=1;brig_func();analogWrite(6,brig);}// кнопка >>>>>>
   if(ir.value==IR_4){brig--;gr1=0;gr2=1;cl1();times=millis();w=1;w2=1;brig_func();analogWrite(6,brig);}// кнопка <
   if(ir.value==0xFFFFFFFF and gr2==1){brig--;gr1=0;cl1();times=millis();w=1;w2=1;brig_func();analogWrite(6,brig);}// кнопка <<<<<<
     
   if (newPosition != oldPosition){oldPosition = newPosition;brig=brig+newPosition;myEnc.write(0);newPosition=0;times=millis();w=1;w2=1;brig_func();analogWrite(6,brig);}
   a[0]= abs(brig)/100;a[1]=abs(brig)/10%10;a[2]=abs(brig)%10;
   for(i=0;i<3;i++){switch(i){case 0: e1=7,e2=8,e3=9;break;
                              case 1: e1=10,e2=11,e3=12;break;
                              case 2: e1=13,e2=14,e3=15;break;
                              }digit();}
   
   lcd.setCursor(0,0);lcd.print("BRIGHT");
   lcd.setCursor(0,1);lcd.print(brig*100/255);lcd.print(" ");lcd.setCursor(4,1);lcd.print("%");}
////////////////////////////////////////////////////////////////////////////////////////////

if(millis()-times>10000&&w==1&&mute==0&&power==0){w=0;menu2=0;menu1=1;menu=0;cl();}

/////////////////// ЧАСЫ ///////////////////////////////////////////////////////////////////
if(power==1){digitalWrite(7,LOW);
     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(i=0;i<4;i++){
    switch(i){
        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(2)==HIGH){hour++;if(hour>23){hour=0;} clock.setDateTime(2020, 9, 15, hour, minut, secon);delay(100);}
  if(digitalRead(10)==LOW&&digitalRead(3)==HIGH){minut++;if(minut>59){minut=0;} clock.setDateTime(2020, 9, 15, hour, minut, secon);delay(100); }
  if(digitalRead(10)==LOW&&digitalRead(4)==HIGH){secon=0; clock.setDateTime(2020, 9, 15, hour, minut, secon);delay(100); }
}
////////////////////////////////////////////////////////////////////////////////////////////
}// loop


void times_f(){lcd.setCursor(0,1);lcd.print(DateTime.hour/10);lcd.print(DateTime.hour%10);lcd.print(":");lcd.print(DateTime.minute/10);lcd.print(DateTime.minute%10);lcd.print(":");lcd.print(DateTime.second/10);lcd.print(DateTime.second%10);}
void brig_func(){if(brig<0){brig=0;}if(brig>255){brig=255;}}
void gain_func(){if(gain0<0){gain0=0;}if(gain0>3){gain0=3;}}
void att_r_func(){if(att_r<0){att_r=0;}if(att_r>24){att_r=24;}}
void att_l_func(){if(att_l<0){att_l=0;}if(att_l>24){att_l=24;}}
void treb_func(){if(treb<-7){treb=-7;}if(treb>7){treb=7;}}
void bass_func(){if(bass<-7){bass=-7;}if(bass>7){bass=7;}}
void vol_func(){if(vol<0){vol=0;}if(vol>56){vol=56;}}
void cl(){ir.value=0;delay(300);lcd.clear();}
void cl1(){ir.value=0;delay(200);}  
void audio(){
  pt.setVolume(vol); // int 0...56 === -70...0 dB step 1.25 dB
  pt.setAttL(att_l); // int 0...24 === 0...-30 db step 1.25 dB > int 31 === mute on     
  pt.setAttR(att_r); // int 0...24 === 0...-30 dB step 1.25 dB > int 31 === mute on
  pt.setSwitch(in, loud_on, gain0); 
        // input      int 0..3 === IN 1...4 
        // loudness   int 0...1 === 1-on 0-off
        // input gain int 0...3 === 0...11.25dB step 3.75 dB
  pt.setBass(bass);   // int -7...+7 === -14...+14 dB step 2 dB
  pt.setTreble(treb); // int -7...+7 === -14...+14 dB step 2 dB
  }

void to_Timer(){newPosition = myEnc.read()/4;}  

void digit(){switch(a[i]){
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);}

92

Re: PT2314

Спасибо. Все работает

93 (2023-12-20 01:47:49 отредактировано z_phantom)

Re: PT2314

доброе время суток. помогите пожалуйста! у меня проблема чтото с моей программой не так вроде все работает только включаю IN0 и сразу наченается бред кнопка SW переберает все действия как будто залипла но это тока на IN0. немогу понять вчом дело.

#define IR_1 0xFFA05F // Кнопка вверх
#define IR_2 0xFF40BF // Кнопка вниз
#define IR_3 0xFF7887 // Кнопка >
#define IR_4 0xFF50AF // Кнопка <
#define IR_5 0xFF02FD // Кнопка IN
#define IR_6 0xFF2AD5 // Кнопка SET
#define IR_7 0xFF6897 // Кнопка MUTE
#define IR_8 0xFFB24D // Кнопка STANDBY (POWER)// ПУЛЬТ ДНС

#define IR_9 0xFF906F    //IN0
#define IR_10 0xFFB847   //IN1
#define IR_11 0xFFF807   //IN2
#define IR_12 0xFFB04F   //IN3

#define BRIG 50       // Яркость подсветки экрана в режиме POWER OFF (0...255)
#include <Wire.h> 
#include <PT2314.h>            // http://forum.rcl-radio.ru/misc.php?action=pan_download&item=434&download=1
#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
   DS3231 clock;RTCDateTime DateTime;
   PT2314 pt;
   LiquidCrystal_I2C lcd(0x27,20,2);  // Устанавливаем дисплей
   IRrecv irrecv(12); // указываем вывод модуля IR приемника
   Encoder myEnc(8, 9);// DT, CLK
   decode_results ir; 
      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};
      byte a[6],d1,d2,d3,d4,d5,d6,e1,e2,e3,w,w2,i,www,power,save,gr1,gr2,poww=1;
      int menu,menu0,menu1=1,menu2=0,vol,bass,treb,att_l,att_r,in,loud_on,gain0,gain1,gain2,gain3,gain4,mute,mute1,mute2,brig,hour,minut,secon;
      unsigned long times,oldPosition  = -999,newPosition;
 
void setup() {
  irrecv.enableIRIn();lcd.init();lcd.backlight();clock.begin();Serial.begin(9600);
  pinMode(10,INPUT);  // МЕНЮ КНОПКА SW энкодера
  pinMode(2,INPUT);   // КНОПКА SET
  pinMode(3,INPUT);   // КНОПКА IN
  pinMode(4,INPUT);   // КНОПКА MUTE
  pinMode(5,INPUT);   // КНОПКА STANDBY
  pinMode(7,OUTPUT);  // ВЫХОД УПРАВЛЕНИЯ STANDBY
  pinMode(6,OUTPUT);  // ВЫХОД УПРАВЛЕНИЯ ПОДСВЕТКОЙ
  pinMode(11,OUTPUT);  //ВЫХОД УПРАВЛЕНИЯ ПИТАНИЯ ВХОДА 1
  pinMode(13,OUTPUT);  //ВЫХОД УПРАВЛЕНИЯ ПИТАНИЯ ВХОДА 2
  pinMode(A0,OUTPUT);  //ВЫХОД УПРАВЛЕНИЯ ПИТАНИЯ ВХОДА 3
  pinMode(A1,OUTPUT);  //ВЫХОД УПРАВЛЕНИЯ ПИТАНИЯ ВХОДА 4
  analogWrite(6, 255);
  lcd.setCursor(2,0);lcd.print("Sound Processor");lcd.setCursor(2,1);lcd.print("Z_Phantom v01.1"); delay(2000);lcd.clear();
  MsTimer2::set(1, to_Timer);MsTimer2::start();
  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);
  if(EEPROM.read(100)!=0){for(int i=0;i<101;i++){EEPROM.update(i,0);}}// очистка памяти при первом включении  
  vol = EEPROM.read(0);treb = EEPROM.read(1)-7;bass = EEPROM.read(2)-7;in = EEPROM.read(3);
  att_l = EEPROM.read(4);att_r = EEPROM.read(5);gain1 = EEPROM.read(6);gain2 = EEPROM.read(7);
  gain3 = EEPROM.read(8);gain4 = EEPROM.read(9);loud_on = EEPROM.read(10);brig = EEPROM.read(11);
  audio();
  analogWrite(6, brig);
}
 
void loop() {

  DateTime = clock.getDateTime();hour = DateTime.hour;minut = DateTime.minute;secon = DateTime.second;
 
////////////////////// 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;}// запрет нажатий не активных кнопок пульта  
 
    if(mute==0&&power==0){
  if(ir.value==IR_6&&menu1==1){menu1=0;menu2=1;gr1=0;gr2=0;cl();times=millis();w=1;w2=1;lcd.setCursor(4,0);lcd.print("SETTING"); delay(2000);lcd.clear();}
  if(ir.value==IR_6&&menu2==1){menu1=1;menu2=0;menu=0;gr1=0;gr2=0;cl();times=millis();w=1;w2=1;lcd.setCursor(6,0);lcd.print("MENU"); delay(2000);lcd.clear();}
 
  if(ir.value==IR_1&&menu1==1){menu++;gr1=0;gr2=0;cl();times=millis();w=1;w2=1;if(menu>2){menu=0;}}//меню 1
  if(ir.value==IR_2&&menu1==1){menu--;gr1=0;gr2=0;cl();times=millis();w=1;w2=1;if(menu<0){menu=2;}}//меню 1
 
  if(ir.value==IR_1&&menu2==1){menu0++;gr1=0;gr2=0;cl();times=millis();w=1;w2=1;if(menu0>4){menu0=0;}}//меню 2
  if(ir.value==IR_2&&menu2==1){menu0--;gr1=0;gr2=0;cl();times=millis();w=1;w2=1;if(menu0<0){menu0=4;}}//меню 2
 
  if(ir.value==IR_5){in++;gr1=0;gr2=0;cl();times=millis();w=1;w2=1;if(in>3){in=0;}lcd.setCursor(4,0);lcd.print("INPUT ");lcd.print(in+1);audio();delay(2000);lcd.clear();}// IN
  }
        if (ir.value == IR_9)  {in = 0;gr1 = 0;gr2 = 0;cl();times = millis();w = 1;w2 = 1;audio();lcd.setCursor(3, 0);lcd.print("  RADIO");delay(1500);}
        if (ir.value == IR_10) {in = 1;gr1 = 0;gr2 = 0;cl();times = millis();w = 1;w2 = 1;audio();lcd.setCursor(3, 0);lcd.print("Bluetooth");delay(1500);}
        if (ir.value == IR_11) {in = 2;gr1 = 0;gr2 = 0;cl();times = millis();w = 1;w2 = 1;audio();lcd.setCursor(3, 0);lcd.print(" SPDiff");delay(1500);}
        if (ir.value == IR_12) {in = 3;gr1 = 0;gr2 = 0;cl();times = millis();w = 1;w2 = 1;audio();lcd.setCursor(3, 0);lcd.print("  AUX");delay(1500);lcd.clear();}
 
  if(ir.value==IR_7&&mute==0&&power==0){mute=1;pt.setAttR(31);pt.setAttL(31);gr1=0;gr2=0;cl();lcd.setCursor(6,0);lcd.print("MUTE");menu1=100;menu2=100;delay(500);}// MUTE
  if(ir.value==IR_7&&mute==1&&power==0){mute=0;cl();menu1=1;menu=0;gr1=0;gr2=0;cl();audio();}// MUTE
 
  if((ir.value==IR_8&&power==0)||poww==1){poww=0;power=1;pt.setAttR(31);pt.setAttL(31);audio();gr1=0;gr2=0;cl();lcd.clear();lcd.setCursor(3,0);lcd.print("POWER  OFF");menu0=0;menu1=0;menu2=0;save=1;analogWrite(6, BRIG);delay(3000);lcd.clear();}// power off
  if(ir.value==IR_8&&power==1){power=0;gr1=0;gr2=0;cl();lcd.backlight();lcd.clear();lcd.setCursor(3,0);lcd.print("POWER   ON ");menu1=1;menu=0;myEnc.write(0);audio();analogWrite(6, brig);delay(3000);lcd.clear();}// power on
///////////////////////////////////////////////////////////////////////////////////////// 
 
/////////////////////////////// УПРАВЛЕНИЕ //////////////////////////////////////////////  
  if(mute==0&&power==0){
  if(digitalRead(2)==HIGH&&menu1==1){menu1=0;menu2=1;cl();times=millis();w=1;w2=1;lcd.setCursor(4,0);lcd.print("SETTING"); delay(2000);lcd.clear();}
  if(digitalRead(2)==HIGH&&menu2==1){menu1=1;menu2=0;menu=0;cl();times=millis();w=1;w2=1;lcd.setCursor(6,0);lcd.print("MENU"); delay(2000);lcd.clear();}
 
  if(digitalRead(10)==LOW&&menu1==1){menu++;cl();times=millis();w=1;w2=1;if(menu>2){menu=0;}}//меню 1
  if(digitalRead(10)==LOW&&menu2==1){menu0++;cl();times=millis();w=1;w2=1;if(menu0>4){menu0=0;}}//меню 2
 
  if(digitalRead(3)==HIGH){in++;cl();;times=millis();w=1;w2=1;if(in>3){in=0;}lcd.setCursor(4,0);lcd.print("INPUT ");lcd.print(in+1);audio();delay(2000);lcd.clear();}// IN
  }
 
  if(digitalRead(4)==HIGH&&mute==0&&power==0){mute=1;pt.setAttR(31);pt.setAttL(31);cl();lcd.setCursor(6,0);lcd.print("MUTE");menu1=100;menu2=100;delay(500);}// MUTE
  if(digitalRead(4)==HIGH&&mute==1&&power==0){mute=0;cl();menu1=1;menu=0;cl();audio();}// MUTE
 
  if(digitalRead(5)==HIGH&&power==0){power=1;pt.setAttR(31);pt.setAttL(31);lcd.clear();lcd.setCursor(4,0);lcd.print("POWER  OFF");menu0=0;menu1=0;menu2=0;save=1;analogWrite(6, 50);delay(3000);lcd.clear();}// power off
  if(digitalRead(5)==HIGH&&power==1){power=0;lcd.backlight();lcd.clear();lcd.setCursor(4,0);lcd.print("POWER   ON ");menu1=1;menu=0;myEnc.write(0);audio();analogWrite(6, brig);delay(3000);lcd.clear();}// power on
  if(power==0){digitalWrite(7,HIGH);}
   // if(power==0){digitalWrite(7,LOW);}// инверсия выхода STANDBY
   if(in==0){digitalWrite(11,LOW);}else{digitalWrite(11,HIGH);}  // УПРАВЛЕНИЕ РЕЛЕ ПИТАНИЯ ВХОДА 1____________________________
   if(in==1){digitalWrite(13,LOW);}else{digitalWrite(13,HIGH);}   // УПРАВЛЕНИЕ РЕЛЕ ПИТАНИЯ ВХОДА 2_____________________________
   if(in==2){digitalWrite(A0,LOW);}else{digitalWrite(A0,HIGH);}   // УПРАВЛЕНИЕ РЕЛЕ ПИТАНИЯ ВХОДА 3_____________________________
   if(in==3){digitalWrite(A1,LOW);}else{digitalWrite(A1,HIGH);}   // УПРАВЛЕНИЕ РЕЛЕ ПИТАНИЯ ВХОДА 4_____________________________
   if(power==1){digitalWrite(11,HIGH);digitalWrite(13,HIGH);digitalWrite(A0,HIGH);digitalWrite(A1,HIGH);}
  if(save==1&&w2==1){save=0;w2=0;
     EEPROM.update(0,vol);EEPROM.update(1,treb+7);EEPROM.update(2,bass+7);EEPROM.update(3,in);
     EEPROM.update(4,att_l);EEPROM.update(5,att_r);EEPROM.update(6,gain1);EEPROM.update(7,gain2);
     EEPROM.update(8,gain3);EEPROM.update(9,gain4);EEPROM.update(10,loud_on);EEPROM.update(11,brig);}
///////////////////////////////////////////////////////////////////////////////////////// 
 
////////////// VOLUME ///////////////////////////////////////////////////////////////////
 if(menu==0&&menu1==1){
   if(ir.value==IR_3){vol++;gr1=1;gr2=0;cl1();times=millis();w=1;w2=1;vol_func();audio();}// кнопка > 
//   if(ir.value==0xFFFFFFFF and gr1==1){vol++;gr2=0;cl1();times=millis();w=1;w2=1;vol_func();audio();}// кнопка >>>>>>
   if(ir.value==IR_4){vol--;gr1=0;gr2=1;cl1();times=millis();w=1;w2=1;vol_func();audio();}// кнопка <
//   if(ir.value==0xFFFFFFFF and gr2==1){vol--;gr1=0;cl1();times=millis();w=1;w2=1;vol_func();audio();}// кнопка <<<<<<
 
   if (newPosition != oldPosition){oldPosition = newPosition;vol=vol+newPosition;myEnc.write(0);newPosition=0;times=millis();w=1;w2=1;vol_func();audio();}
   a[0]= vol/10;a[1]=vol%10;
   for(i=0;i<2;i++){switch(i){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("IN");lcd.print(in+1);lcd.print(" VOLUME");
   if(vol<0){lcd.setCursor(9,1);lcd.write((uint8_t)8);}else{lcd.setCursor(9,1);lcd.print(" ");}
   times_f();
   }
////////////////////////////////////////////////////////////////////////////////////////////
 
////////////// BASS ///////////////////////////////////////////////////////////////////
 if(menu==1&&menu1==1){
   if(ir.value==IR_3){bass++;gr1=1;gr2=0;cl1();times=millis();w=1;w2=1;bass_func();audio();}// кнопка > 
//   if(ir.value==0xFFFFFFFF and gr1==1){bass++;gr2=0;cl1();times=millis();w=1;w2=1;bass_func();audio();}// кнопка >>>>>>
   if(ir.value==IR_4){bass--;gr1=0;gr2=1;cl1();times=millis();w=1;w2=1;bass_func();audio();}// кнопка <
//   if(ir.value==0xFFFFFFFF and gr2==1){bass--;gr1=0;cl1();times=millis();w=1;w2=1;bass_func();audio();}// кнопка <<<<<<
 
   if (newPosition != oldPosition){oldPosition = newPosition;bass=bass+newPosition;myEnc.write(0);newPosition=0;times=millis();w=1;w2=1;bass_func();audio();}
   a[0]= abs(bass*2)/10;a[1]=abs(bass*2)%10;
   for(i=0;i<2;i++){switch(i){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   dB");
   if(bass<0){lcd.setCursor(9,1);lcd.write((uint8_t)8);}else{lcd.setCursor(9,1);lcd.print(" ");}
   times_f();
   }
////////////////////////////////////////////////////////////////////////////////////////////
 
////////////// TREBLE ///////////////////////////////////////////////////////////////////
 if(menu==2&&menu1==1){
   if(ir.value==IR_3){treb++;gr1=1;gr2=0;cl1();times=millis();w=1;w2=1;treb_func();audio();}// кнопка > 
//   if(ir.value==0xFFFFFFFF and gr1==1){treb++;gr2=0;cl1();times=millis();w=1;w2=1;treb_func();audio();}// кнопка >>>>>>
   if(ir.value==IR_4){treb--;gr1=0;gr2=1;cl1();times=millis();w=1;w2=1;treb_func();audio();}// кнопка <
//   if(ir.value==0xFFFFFFFF and gr2==1){treb--;gr1=0;cl1();times=millis();w=1;w2=1;treb_func();audio();}// кнопка <<<<<<
 
   if (newPosition != oldPosition){oldPosition = newPosition;treb=treb+newPosition;myEnc.write(0);newPosition=0;times=millis();w=1;w2=1;treb_func();audio();}
   a[0]= abs(treb*2)/10;a[1]=abs(treb*2)%10;
 
   for(i=0;i<2;i++){switch(i){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 dB");
   if(treb<0){lcd.setCursor(9,1);lcd.write((uint8_t)8);}else{lcd.setCursor(9,1);lcd.print(" ");}
   times_f();
   }
////////////////////////////////////////////////////////////////////////////////////////////
 
////////////// ATT_L ///////////////////////////////////////////////////////////////////
 if(menu0==0&&menu2==1){
   if(ir.value==IR_3){att_l++;gr1=1;gr2=0;cl1();times=millis();w=1;w2=1;att_l_func();audio();}// кнопка > 
//   if(ir.value==0xFFFFFFFF and gr1==1){att_l++;gr2=0;cl1();times=millis();w=1;w2=1;att_l_func();audio();}// кнопка >>>>>>
   if(ir.value==IR_4){att_l--;gr1=0;gr2=1;cl1();times=millis();w=1;w2=1;att_l_func();audio();}// кнопка <
//   if(ir.value==0xFFFFFFFF and gr2==1){att_l--;gr1=0;cl1();times=millis();w=1;w2=1;att_l_func();audio();}// кнопка <<<<<<
 
   if (newPosition != oldPosition){oldPosition = newPosition;att_l=att_l+newPosition;myEnc.write(0);newPosition=0;times=millis();w=1;w2=1;att_l_func();audio();}
   a[0]= abs(att_l)/10;a[1]=abs(att_l)%10;
   for(i=0;i<2;i++){switch(i){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_L");
   lcd.setCursor(0,1);lcd.print(-att_l*1.25,2);lcd.print(" ");lcd.setCursor(6,1);lcd.print("dB");}
////////////////////////////////////////////////////////////////////////////////////////////
 
////////////// ATT_R ///////////////////////////////////////////////////////////////////
 if(menu0==1&&menu2==1){
   if(ir.value==IR_3){att_r++;gr1=1;gr2=0;cl1();times=millis();w=1;w2=1;att_r_func();audio();}// кнопка > 
//   if(ir.value==0xFFFFFFFF and gr1==1){att_r++;gr2=0;cl1();times=millis();w=1;w2=1;att_r_func();audio();}// кнопка >>>>>>
   if(ir.value==IR_4){att_r--;gr1=0;gr2=1;cl1();times=millis();w=1;w2=1;att_r_func();audio();}// кнопка <
//   if(ir.value==0xFFFFFFFF and gr2==1){att_r--;gr1=0;cl1();times=millis();w=1;w2=1;att_r_func();audio();}// кнопка <<<<<<
 
   if (newPosition != oldPosition){oldPosition = newPosition;att_r=att_r+newPosition;myEnc.write(0);newPosition=0;times=millis();w=1;w2=1;att_r_func();audio();}
   a[0]= abs(att_r)/10;a[1]=abs(att_r)%10;
   for(i=0;i<2;i++){switch(i){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_R");
   lcd.setCursor(0,1);lcd.print(-att_r*1.25,2);lcd.print(" ");lcd.setCursor(6,1);lcd.print("dB");}
////////////////////////////////////////////////////////////////////////////////////////////
 
////////////// INPUT GAIN ///////////////////////////////////////////////////////////////////
 if(menu0==2&&menu2==1){
   switch(in){
     case 0: gain0 = gain1;break;
     case 1: gain0 = gain2;break;
     case 2: gain0 = gain3;break;
     case 3: gain0 = gain4;break;
     }
 
   if(ir.value==IR_3){gain0++;gr1=1;gr2=0;cl1();times=millis();w=1;w2=1;gain_func();www=1;}// кнопка > 
//   if(ir.value==0xFFFFFFFF and gr1==1){gain0++;gr2=0;cl1();times=millis();w=1;w2=1;gain_func();www=1;}// кнопка >>>>>>
   if(ir.value==IR_4){gain0--;gr1=0;gr2=1;cl1();times=millis();w=1;w2=1;gain_func();www=1;}// кнопка <
//   if(ir.value==0xFFFFFFFF and gr2==1){gain0--;gr1=0;cl1();times=millis();w=1;w2=1;gain_func();www=1;}// кнопка <<<<<<
 
   if (newPosition != oldPosition){oldPosition = newPosition;gain0=gain0+newPosition;myEnc.write(0);newPosition=0;times=millis();www=1;w=1;w2=1;gain_func();}
 
  switch(in){
     case 0: gain1 = gain0;break;
     case 1: gain2 = gain0;break;
     case 2: gain3 = gain0;break;
     case 3: gain4 = gain0;break;
     }  
     a[0]= abs(gain0);
 
   for(i=0;i<1;i++){switch(i){case 0: e1=13,e2=14,e3=15;break;case 1: e1=13,e2=14,e3=15;break;}digit();}
   lcd.setCursor(0,1);lcd.print("GAIN ");lcd.print(gain0*3.75,2);lcd.print(" ");lcd.setCursor(10,1);lcd.print("dB");
   if(www==1){audio();www=0;}
   lcd.setCursor(0,0);lcd.print("INPUT ");lcd.print(in+1);}
////////////////////////////////////////////////////////////////////////////////////////////
 
////////////// LOUDNESS ///////////////////////////////////////////////////////////////////
 if(menu0==3&&menu2==1){
   if(ir.value==IR_3){loud_on++;gr1=1;gr2=0;cl1();times=millis();w=1;w2=1;if(loud_on>1){loud_on=0;};if(loud_on<0){loud_on=1;}audio();}// кнопка > 
//   if(ir.value==0xFFFFFFFF and gr1==1){loud_on++;gr2=0;cl1();times=millis();w=1;w2=1;if(loud_on>1){loud_on=0;};if(loud_on<0){loud_on=1;}audio();}// кнопка >>>>>>
   if(ir.value==IR_4){loud_on--;gr1=0;gr2=1;cl1();times=millis();w=1;w2=1;if(loud_on>1){loud_on=0;};if(loud_on<0){loud_on=1;}audio();}// кнопка <
//   if(ir.value==0xFFFFFFFF and gr2==1){loud_on--;gr1=0;cl1();times=millis();w=1;w2=1;if(loud_on>1){loud_on=0;};if(loud_on<0){loud_on=1;}audio();}// кнопка <<<<<<
 
   if (newPosition != oldPosition){oldPosition = newPosition;loud_on=loud_on+newPosition;myEnc.write(0);newPosition=0;times=millis();w=1;w2=1;if(loud_on>1){loud_on=0;};if(loud_on<0){loud_on=1;};audio();}
   if(loud_on==1){lcd.setCursor(2,0);lcd.print("LOUDNESS  ON ");}
             else{lcd.setCursor(2,0);lcd.print("LOUDNESS  OFF");}}
////////////////////////////////////////////////////////////////////////////////////////////
 
////////////// BRIGHTNESS ///////////////////////////////////////////////////////////////////
 if(menu0==4&&menu2==1){
   if(ir.value==IR_3){brig++;gr1=1;gr2=0;cl1();times=millis();w=1;w2=1;brig_func();analogWrite(6,brig);}// кнопка > 
//   if(ir.value==0xFFFFFFFF and gr1==1){brig++;gr2=0;cl1();times=millis();w=1;w2=1;brig_func();analogWrite(6,brig);}// кнопка >>>>>>
   if(ir.value==IR_4){brig--;gr1=0;gr2=1;cl1();times=millis();w=1;w2=1;brig_func();analogWrite(6,brig);}// кнопка <
//   if(ir.value==0xFFFFFFFF and gr2==1){brig--;gr1=0;cl1();times=millis();w=1;w2=1;brig_func();analogWrite(6,brig);}// кнопка <<<<<<
 
   if (newPosition != oldPosition){oldPosition = newPosition;brig=brig+newPosition;myEnc.write(0);newPosition=0;times=millis();w=1;w2=1;brig_func();analogWrite(6,brig);}
   a[0]= abs(brig)/100;a[1]=abs(brig)/10%10;a[2]=abs(brig)%10;
   for(i=0;i<3;i++){switch(i){case 0: e1=7,e2=8,e3=9;break;
                              case 1: e1=10,e2=11,e3=12;break;
                              case 2: e1=13,e2=14,e3=15;break;
                              }digit();}
 
   lcd.setCursor(0,0);lcd.print("BRIGHT");
   lcd.setCursor(0,1);lcd.print(brig*100/255);lcd.print(" ");lcd.setCursor(4,1);lcd.print("%");}
////////////////////////////////////////////////////////////////////////////////////////////
 
if(millis()-times>10000&&w==1&&mute==0&&power==0){w=0;menu2=0;menu1=1;menu=0;cl();}
 
/////////////////// ЧАСЫ ///////////////////////////////////////////////////////////////////
if(power==1){digitalWrite(7,LOW);
     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(i=0;i<4;i++){
    switch(i){
        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(2)==HIGH){hour++;if(hour>23){hour=0;} clock.setDateTime(2020, 9, 15, hour, minut, secon);delay(100);}
  if(digitalRead(10)==LOW&&digitalRead(3)==HIGH){minut++;if(minut>59){minut=0;} clock.setDateTime(2020, 9, 15, hour, minut, secon);delay(100); }
  if(digitalRead(10)==LOW&&digitalRead(4)==HIGH){secon=0; clock.setDateTime(2020, 9, 15, hour, minut, secon);delay(100); }
}
////////////////////////////////////////////////////////////////////////////////////////////
}// loop
 
 
void times_f(){lcd.setCursor(1,1);lcd.print(DateTime.hour/10);lcd.print(DateTime.hour%10);lcd.print(":");lcd.print(DateTime.minute/10);lcd.print(DateTime.minute%10);lcd.print(":");lcd.print(DateTime.second/10);lcd.print(DateTime.second%10);}
void brig_func(){if(brig<0){brig=0;}if(brig>255){brig=255;}}
void gain_func(){if(gain0<0){gain0=0;}if(gain0>3){gain0=3;}}
void att_r_func(){if(att_r<0){att_r=0;}if(att_r>24){att_r=24;}}
void att_l_func(){if(att_l<0){att_l=0;}if(att_l>24){att_l=24;}}
void treb_func(){if(treb<-7){treb=-7;}if(treb>7){treb=7;}}
void bass_func(){if(bass<-7){bass=-7;}if(bass>7){bass=7;}}
void vol_func(){if(vol<0){vol=0;}if(vol>56){vol=56;}}
void cl(){ir.value=0;delay(300);lcd.clear();}
void cl1(){ir.value=0;delay(200);}  
void audio(){
  pt.setVolume(vol); // int 0...56 === -70...0 dB step 1.25 dB
  pt.setAttL(att_l); // int 0...24 === 0...-30 db step 1.25 dB > int 31 === mute on     
  pt.setAttR(att_r); // int 0...24 === 0...-30 dB step 1.25 dB > int 31 === mute on
  pt.setSwitch(in, loud_on, gain0); 
        // input      int 0..3 === IN 1...4 
        // loudness   int 0...1 === 1-on 0-off
        // input gain int 0...3 === 0...11.25dB step 3.75 dB
  pt.setBass(bass);   // int -7...+7 === -14...+14 dB step 2 dB
  pt.setTreble(treb); // int -7...+7 === -14...+14 dB step 2 dB
  }
 
void to_Timer(){newPosition = myEnc.read()/4;}  
 
void digit(){switch(a[i]){
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);}

94

Re: PT2314

На платке энкодера все 3 резистора установлены?

95 (2023-12-20 13:33:12 отредактировано z_phantom)

Re: PT2314

Да энкодер точно впорядке. Это происходит только на in0 на всех остольных все норм. Пробовал менять платку и компоненты, и даже без энкодера ,вместо него ставил резисторы, непомогает.

96

Re: PT2314

Я изменил кнопки, на внутренние подтягивающие резисторы, кнопка срабатывает на замыкание gnd, внешние подтягивающие резисторы не нужны. Просто у меня нет возможности собирать схему с внешними подтягивающими резисторами. Далее подключил кнопки, дисплей.
Загрузил скетч, при переходе на IN1 происходит перебор параметров, как будто нажата кнопка SW, подключаю энкодер, проблема уходит, при переходе на IN1 , перебора параметров нет.

Такое впечатление что у Вас нет подтягивающего резистора к +5В вывода WS энкодера.

Вы сделали активным вывод D11 , а он отвечает за питание уст-ва IN1, расположен он рядом с D10 SW, наводка приводит к активации нажатии кнопки SW.

#define IR_1 0xFFA05F // Кнопка вверх
#define IR_2 0xFF40BF // Кнопка вниз
#define IR_3 0xFF7887 // Кнопка >
#define IR_4 0xFF50AF // Кнопка <
#define IR_5 0xFF02FD // Кнопка IN
#define IR_6 0xFF2AD5 // Кнопка SET
#define IR_7 0xFF6897 // Кнопка MUTE
#define IR_8 0xFFB24D // Кнопка STANDBY (POWER)// ПУЛЬТ ДНС

#define IR_9 0xFF906F    //IN0
#define IR_10 0xFFB847   //IN1
#define IR_11 0xFFF807   //IN2
#define IR_12 0xFFB04F   //IN3

#define BRIG 50       // Яркость подсветки экрана в режиме POWER OFF (0...255)
#include <Wire.h> 
#include <PT2314.h>            // http://forum.rcl-radio.ru/misc.php?action=pan_download&item=434&download=1
#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
   DS3231 clock;RTCDateTime DateTime;
   PT2314 pt;
   LiquidCrystal_I2C lcd(0x27,16,2);  // Устанавливаем дисплей
   IRrecv irrecv(12); // указываем вывод модуля IR приемника
   Encoder myEnc(8, 9);// DT, CLK
   decode_results ir; 
      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};
      byte a[6],d1,d2,d3,d4,d5,d6,e1,e2,e3,w,w2,i,www,power,save,gr1,gr2,poww=1;
      int menu,menu0,menu1=1,menu2=0,vol,bass,treb,att_l,att_r,in,loud_on,gain0,gain1,gain2,gain3,gain4,mute,mute1,mute2,brig,hour,minut,secon;
      unsigned long times,oldPosition  = -999,newPosition;
 
void setup() {
  irrecv.enableIRIn();lcd.init();lcd.backlight();clock.begin();Serial.begin(9600);
  pinMode(10,INPUT);  // МЕНЮ КНОПКА SW энкодера
  pinMode(2,INPUT_PULLUP);   // КНОПКА SET
  pinMode(3,INPUT_PULLUP);   // КНОПКА IN
  pinMode(4,INPUT_PULLUP);   // КНОПКА MUTE
  pinMode(5,INPUT_PULLUP);   // КНОПКА STANDBY
  pinMode(7,OUTPUT);  // ВЫХОД УПРАВЛЕНИЯ STANDBY
  pinMode(6,OUTPUT);  // ВЫХОД УПРАВЛЕНИЯ ПОДСВЕТКОЙ
  pinMode(11,OUTPUT);  //ВЫХОД УПРАВЛЕНИЯ ПИТАНИЯ ВХОДА 1
  pinMode(13,OUTPUT);  //ВЫХОД УПРАВЛЕНИЯ ПИТАНИЯ ВХОДА 2
  pinMode(A0,OUTPUT);  //ВЫХОД УПРАВЛЕНИЯ ПИТАНИЯ ВХОДА 3
  pinMode(A1,OUTPUT);  //ВЫХОД УПРАВЛЕНИЯ ПИТАНИЯ ВХОДА 4
  analogWrite(6, 255);
  lcd.setCursor(2,0);lcd.print("Sound Processor");lcd.setCursor(2,1);lcd.print("Z_Phantom v01.1"); delay(2000);lcd.clear();
  MsTimer2::set(1, to_Timer);MsTimer2::start();
  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);
  if(EEPROM.read(100)!=0){for(int i=0;i<101;i++){EEPROM.update(i,0);}}// очистка памяти при первом включении  
  vol = EEPROM.read(0);treb = EEPROM.read(1)-7;bass = EEPROM.read(2)-7;in = EEPROM.read(3);
  att_l = EEPROM.read(4);att_r = EEPROM.read(5);gain1 = EEPROM.read(6);gain2 = EEPROM.read(7);
  gain3 = EEPROM.read(8);gain4 = EEPROM.read(9);loud_on = EEPROM.read(10);brig = EEPROM.read(11);
  audio();
  analogWrite(6, brig);
}
 
void loop() {

  DateTime = clock.getDateTime();hour = DateTime.hour;minut = DateTime.minute;secon = DateTime.second;
 
////////////////////// 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;}// запрет нажатий не активных кнопок пульта  
 
    if(mute==0&&power==0){
  if(ir.value==IR_6&&menu1==1){menu1=0;menu2=1;gr1=0;gr2=0;cl();times=millis();w=1;w2=1;lcd.setCursor(4,0);lcd.print("SETTING"); delay(2000);lcd.clear();}
  if(ir.value==IR_6&&menu2==1){menu1=1;menu2=0;menu=0;gr1=0;gr2=0;cl();times=millis();w=1;w2=1;lcd.setCursor(6,0);lcd.print("MENU"); delay(2000);lcd.clear();}
 
  if(ir.value==IR_1&&menu1==1){menu++;gr1=0;gr2=0;cl();times=millis();w=1;w2=1;if(menu>2){menu=0;}}//меню 1
  if(ir.value==IR_2&&menu1==1){menu--;gr1=0;gr2=0;cl();times=millis();w=1;w2=1;if(menu<0){menu=2;}}//меню 1
 
  if(ir.value==IR_1&&menu2==1){menu0++;gr1=0;gr2=0;cl();times=millis();w=1;w2=1;if(menu0>4){menu0=0;}}//меню 2
  if(ir.value==IR_2&&menu2==1){menu0--;gr1=0;gr2=0;cl();times=millis();w=1;w2=1;if(menu0<0){menu0=4;}}//меню 2
 
  if(ir.value==IR_5){in++;gr1=0;gr2=0;cl();times=millis();w=1;w2=1;if(in>3){in=0;}lcd.setCursor(4,0);lcd.print("INPUT ");lcd.print(in+1);audio();delay(2000);lcd.clear();}// IN
  }
        if (ir.value == IR_9)  {in = 0;gr1 = 0;gr2 = 0;cl();times = millis();w = 1;w2 = 1;audio();lcd.setCursor(3, 0);lcd.print("  RADIO");delay(1500);}
        if (ir.value == IR_10) {in = 1;gr1 = 0;gr2 = 0;cl();times = millis();w = 1;w2 = 1;audio();lcd.setCursor(3, 0);lcd.print("Bluetooth");delay(1500);}
        if (ir.value == IR_11) {in = 2;gr1 = 0;gr2 = 0;cl();times = millis();w = 1;w2 = 1;audio();lcd.setCursor(3, 0);lcd.print(" SPDiff");delay(1500);}
        if (ir.value == IR_12) {in = 3;gr1 = 0;gr2 = 0;cl();times = millis();w = 1;w2 = 1;audio();lcd.setCursor(3, 0);lcd.print("  AUX");delay(1500);lcd.clear();}
 
  if(ir.value==IR_7&&mute==0&&power==0){mute=1;pt.setAttR(31);pt.setAttL(31);gr1=0;gr2=0;cl();lcd.setCursor(6,0);lcd.print("MUTE");menu1=100;menu2=100;delay(500);}// MUTE
  if(ir.value==IR_7&&mute==1&&power==0){mute=0;cl();menu1=1;menu=0;gr1=0;gr2=0;cl();audio();}// MUTE
 
  if((ir.value==IR_8&&power==0)||poww==1){poww=0;power=1;pt.setAttR(31);pt.setAttL(31);audio();gr1=0;gr2=0;cl();lcd.clear();lcd.setCursor(3,0);lcd.print("POWER  OFF");menu0=0;menu1=0;menu2=0;save=1;analogWrite(6, BRIG);delay(3000);lcd.clear();}// power off
  if(ir.value==IR_8&&power==1){power=0;gr1=0;gr2=0;cl();lcd.backlight();lcd.clear();lcd.setCursor(3,0);lcd.print("POWER   ON ");menu1=1;menu=0;myEnc.write(0);audio();analogWrite(6, brig);delay(3000);lcd.clear();}// power on
///////////////////////////////////////////////////////////////////////////////////////// 
 
/////////////////////////////// УПРАВЛЕНИЕ //////////////////////////////////////////////  
  if(mute==0&&power==0){
  if(digitalRead(2)==LOW&&menu1==1){menu1=0;menu2=1;cl();times=millis();w=1;w2=1;lcd.setCursor(4,0);lcd.print("SETTING"); delay(2000);lcd.clear();}
  if(digitalRead(2)==LOW&&menu2==1){menu1=1;menu2=0;menu=0;cl();times=millis();w=1;w2=1;lcd.setCursor(6,0);lcd.print("MENU"); delay(2000);lcd.clear();}
 
  if(digitalRead(10)==LOW&&menu1==1){menu++;cl();times=millis();w=1;w2=1;if(menu>2){menu=0;}}//меню 1
  if(digitalRead(10)==LOW&&menu2==1){menu0++;cl();times=millis();w=1;w2=1;if(menu0>4){menu0=0;}}//меню 2
 
  if(digitalRead(3)==LOW){in++;cl();;times=millis();w=1;w2=1;if(in>3){in=0;}lcd.setCursor(4,0);lcd.print("INPUT ");lcd.print(in+1);audio();delay(2000);lcd.clear();}// IN
  }
 
  if(digitalRead(4)==LOW&&mute==0&&power==0){mute=1;pt.setAttR(31);pt.setAttL(31);cl();lcd.setCursor(6,0);lcd.print("MUTE");menu1=100;menu2=100;delay(500);}// MUTE
  if(digitalRead(4)==LOW&&mute==1&&power==0){mute=0;cl();menu1=1;menu=0;cl();audio();}// MUTE
 
  if(digitalRead(5)==LOW&&power==0){power=1;pt.setAttR(31);pt.setAttL(31);lcd.clear();lcd.setCursor(4,0);lcd.print("POWER  OFF");menu0=0;menu1=0;menu2=0;save=1;analogWrite(6, 50);delay(3000);lcd.clear();}// power off
  if(digitalRead(5)==LOW&&power==1){power=0;lcd.backlight();lcd.clear();lcd.setCursor(4,0);lcd.print("POWER   ON ");menu1=1;menu=0;myEnc.write(0);audio();analogWrite(6, brig);delay(3000);lcd.clear();}// power on
  if(power==0){digitalWrite(7,HIGH);}
   // if(power==0){digitalWrite(7,LOW);}// инверсия выхода STANDBY
   if(in==0){digitalWrite(11,LOW);}else{digitalWrite(11,HIGH);}  // УПРАВЛЕНИЕ РЕЛЕ ПИТАНИЯ ВХОДА 1____________________________
   if(in==1){digitalWrite(13,LOW);}else{digitalWrite(13,HIGH);}   // УПРАВЛЕНИЕ РЕЛЕ ПИТАНИЯ ВХОДА 2_____________________________
   if(in==2){digitalWrite(A0,LOW);}else{digitalWrite(A0,HIGH);}   // УПРАВЛЕНИЕ РЕЛЕ ПИТАНИЯ ВХОДА 3_____________________________
   if(in==3){digitalWrite(A1,LOW);}else{digitalWrite(A1,HIGH);}   // УПРАВЛЕНИЕ РЕЛЕ ПИТАНИЯ ВХОДА 4_____________________________
   if(power==1){digitalWrite(11,HIGH);digitalWrite(13,HIGH);digitalWrite(A0,HIGH);digitalWrite(A1,HIGH);}
  if(save==1&&w2==1){save=0;w2=0;
     EEPROM.update(0,vol);EEPROM.update(1,treb+7);EEPROM.update(2,bass+7);EEPROM.update(3,in);
     EEPROM.update(4,att_l);EEPROM.update(5,att_r);EEPROM.update(6,gain1);EEPROM.update(7,gain2);
     EEPROM.update(8,gain3);EEPROM.update(9,gain4);EEPROM.update(10,loud_on);EEPROM.update(11,brig);}
///////////////////////////////////////////////////////////////////////////////////////// 
 
////////////// VOLUME ///////////////////////////////////////////////////////////////////
 if(menu==0&&menu1==1){
   if(ir.value==IR_3){vol++;gr1=1;gr2=0;cl1();times=millis();w=1;w2=1;vol_func();audio();}// кнопка > 
//   if(ir.value==0xFFFFFFFF and gr1==1){vol++;gr2=0;cl1();times=millis();w=1;w2=1;vol_func();audio();}// кнопка >>>>>>
   if(ir.value==IR_4){vol--;gr1=0;gr2=1;cl1();times=millis();w=1;w2=1;vol_func();audio();}// кнопка <
//   if(ir.value==0xFFFFFFFF and gr2==1){vol--;gr1=0;cl1();times=millis();w=1;w2=1;vol_func();audio();}// кнопка <<<<<<
 
   if (newPosition != oldPosition){oldPosition = newPosition;vol=vol+newPosition;myEnc.write(0);newPosition=0;times=millis();w=1;w2=1;vol_func();audio();}
   a[0]= vol/10;a[1]=vol%10;
   for(i=0;i<2;i++){switch(i){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("IN");lcd.print(in+1);lcd.print(" VOLUME");
   if(vol<0){lcd.setCursor(9,1);lcd.write((uint8_t)8);}else{lcd.setCursor(9,1);lcd.print(" ");}
   times_f();
   }
////////////////////////////////////////////////////////////////////////////////////////////
 
////////////// BASS ///////////////////////////////////////////////////////////////////
 if(menu==1&&menu1==1){
   if(ir.value==IR_3){bass++;gr1=1;gr2=0;cl1();times=millis();w=1;w2=1;bass_func();audio();}// кнопка > 
//   if(ir.value==0xFFFFFFFF and gr1==1){bass++;gr2=0;cl1();times=millis();w=1;w2=1;bass_func();audio();}// кнопка >>>>>>
   if(ir.value==IR_4){bass--;gr1=0;gr2=1;cl1();times=millis();w=1;w2=1;bass_func();audio();}// кнопка <
//   if(ir.value==0xFFFFFFFF and gr2==1){bass--;gr1=0;cl1();times=millis();w=1;w2=1;bass_func();audio();}// кнопка <<<<<<
 
   if (newPosition != oldPosition){oldPosition = newPosition;bass=bass+newPosition;myEnc.write(0);newPosition=0;times=millis();w=1;w2=1;bass_func();audio();}
   a[0]= abs(bass*2)/10;a[1]=abs(bass*2)%10;
   for(i=0;i<2;i++){switch(i){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   dB");
   if(bass<0){lcd.setCursor(9,1);lcd.write((uint8_t)8);}else{lcd.setCursor(9,1);lcd.print(" ");}
   times_f();
   }
////////////////////////////////////////////////////////////////////////////////////////////
 
////////////// TREBLE ///////////////////////////////////////////////////////////////////
 if(menu==2&&menu1==1){
   if(ir.value==IR_3){treb++;gr1=1;gr2=0;cl1();times=millis();w=1;w2=1;treb_func();audio();}// кнопка > 
//   if(ir.value==0xFFFFFFFF and gr1==1){treb++;gr2=0;cl1();times=millis();w=1;w2=1;treb_func();audio();}// кнопка >>>>>>
   if(ir.value==IR_4){treb--;gr1=0;gr2=1;cl1();times=millis();w=1;w2=1;treb_func();audio();}// кнопка <
//   if(ir.value==0xFFFFFFFF and gr2==1){treb--;gr1=0;cl1();times=millis();w=1;w2=1;treb_func();audio();}// кнопка <<<<<<
 
   if (newPosition != oldPosition){oldPosition = newPosition;treb=treb+newPosition;myEnc.write(0);newPosition=0;times=millis();w=1;w2=1;treb_func();audio();}
   a[0]= abs(treb*2)/10;a[1]=abs(treb*2)%10;
 
   for(i=0;i<2;i++){switch(i){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 dB");
   if(treb<0){lcd.setCursor(9,1);lcd.write((uint8_t)8);}else{lcd.setCursor(9,1);lcd.print(" ");}
   times_f();
   }
////////////////////////////////////////////////////////////////////////////////////////////
 
////////////// ATT_L ///////////////////////////////////////////////////////////////////
 if(menu0==0&&menu2==1){
   if(ir.value==IR_3){att_l++;gr1=1;gr2=0;cl1();times=millis();w=1;w2=1;att_l_func();audio();}// кнопка > 
//   if(ir.value==0xFFFFFFFF and gr1==1){att_l++;gr2=0;cl1();times=millis();w=1;w2=1;att_l_func();audio();}// кнопка >>>>>>
   if(ir.value==IR_4){att_l--;gr1=0;gr2=1;cl1();times=millis();w=1;w2=1;att_l_func();audio();}// кнопка <
//   if(ir.value==0xFFFFFFFF and gr2==1){att_l--;gr1=0;cl1();times=millis();w=1;w2=1;att_l_func();audio();}// кнопка <<<<<<
 
   if (newPosition != oldPosition){oldPosition = newPosition;att_l=att_l+newPosition;myEnc.write(0);newPosition=0;times=millis();w=1;w2=1;att_l_func();audio();}
   a[0]= abs(att_l)/10;a[1]=abs(att_l)%10;
   for(i=0;i<2;i++){switch(i){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_L");
   lcd.setCursor(0,1);lcd.print(-att_l*1.25,2);lcd.print(" ");lcd.setCursor(6,1);lcd.print("dB");}
////////////////////////////////////////////////////////////////////////////////////////////
 
////////////// ATT_R ///////////////////////////////////////////////////////////////////
 if(menu0==1&&menu2==1){
   if(ir.value==IR_3){att_r++;gr1=1;gr2=0;cl1();times=millis();w=1;w2=1;att_r_func();audio();}// кнопка > 
//   if(ir.value==0xFFFFFFFF and gr1==1){att_r++;gr2=0;cl1();times=millis();w=1;w2=1;att_r_func();audio();}// кнопка >>>>>>
   if(ir.value==IR_4){att_r--;gr1=0;gr2=1;cl1();times=millis();w=1;w2=1;att_r_func();audio();}// кнопка <
//   if(ir.value==0xFFFFFFFF and gr2==1){att_r--;gr1=0;cl1();times=millis();w=1;w2=1;att_r_func();audio();}// кнопка <<<<<<
 
   if (newPosition != oldPosition){oldPosition = newPosition;att_r=att_r+newPosition;myEnc.write(0);newPosition=0;times=millis();w=1;w2=1;att_r_func();audio();}
   a[0]= abs(att_r)/10;a[1]=abs(att_r)%10;
   for(i=0;i<2;i++){switch(i){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_R");
   lcd.setCursor(0,1);lcd.print(-att_r*1.25,2);lcd.print(" ");lcd.setCursor(6,1);lcd.print("dB");}
////////////////////////////////////////////////////////////////////////////////////////////
 
////////////// INPUT GAIN ///////////////////////////////////////////////////////////////////
 if(menu0==2&&menu2==1){
   switch(in){
     case 0: gain0 = gain1;break;
     case 1: gain0 = gain2;break;
     case 2: gain0 = gain3;break;
     case 3: gain0 = gain4;break;
     }
 
   if(ir.value==IR_3){gain0++;gr1=1;gr2=0;cl1();times=millis();w=1;w2=1;gain_func();www=1;}// кнопка > 
//   if(ir.value==0xFFFFFFFF and gr1==1){gain0++;gr2=0;cl1();times=millis();w=1;w2=1;gain_func();www=1;}// кнопка >>>>>>
   if(ir.value==IR_4){gain0--;gr1=0;gr2=1;cl1();times=millis();w=1;w2=1;gain_func();www=1;}// кнопка <
//   if(ir.value==0xFFFFFFFF and gr2==1){gain0--;gr1=0;cl1();times=millis();w=1;w2=1;gain_func();www=1;}// кнопка <<<<<<
 
   if (newPosition != oldPosition){oldPosition = newPosition;gain0=gain0+newPosition;myEnc.write(0);newPosition=0;times=millis();www=1;w=1;w2=1;gain_func();}
 
  switch(in){
     case 0: gain1 = gain0;break;
     case 1: gain2 = gain0;break;
     case 2: gain3 = gain0;break;
     case 3: gain4 = gain0;break;
     }  
     a[0]= abs(gain0);
 
   for(i=0;i<1;i++){switch(i){case 0: e1=13,e2=14,e3=15;break;case 1: e1=13,e2=14,e3=15;break;}digit();}
   lcd.setCursor(0,1);lcd.print("GAIN ");lcd.print(gain0*3.75,2);lcd.print(" ");lcd.setCursor(10,1);lcd.print("dB");
   if(www==1){audio();www=0;}
   lcd.setCursor(0,0);lcd.print("INPUT ");lcd.print(in+1);}
////////////////////////////////////////////////////////////////////////////////////////////
 
////////////// LOUDNESS ///////////////////////////////////////////////////////////////////
 if(menu0==3&&menu2==1){
   if(ir.value==IR_3){loud_on++;gr1=1;gr2=0;cl1();times=millis();w=1;w2=1;if(loud_on>1){loud_on=0;};if(loud_on<0){loud_on=1;}audio();}// кнопка > 
//   if(ir.value==0xFFFFFFFF and gr1==1){loud_on++;gr2=0;cl1();times=millis();w=1;w2=1;if(loud_on>1){loud_on=0;};if(loud_on<0){loud_on=1;}audio();}// кнопка >>>>>>
   if(ir.value==IR_4){loud_on--;gr1=0;gr2=1;cl1();times=millis();w=1;w2=1;if(loud_on>1){loud_on=0;};if(loud_on<0){loud_on=1;}audio();}// кнопка <
//   if(ir.value==0xFFFFFFFF and gr2==1){loud_on--;gr1=0;cl1();times=millis();w=1;w2=1;if(loud_on>1){loud_on=0;};if(loud_on<0){loud_on=1;}audio();}// кнопка <<<<<<
 
   if (newPosition != oldPosition){oldPosition = newPosition;loud_on=loud_on+newPosition;myEnc.write(0);newPosition=0;times=millis();w=1;w2=1;if(loud_on>1){loud_on=0;};if(loud_on<0){loud_on=1;};audio();}
   if(loud_on==1){lcd.setCursor(2,0);lcd.print("LOUDNESS  ON ");}
             else{lcd.setCursor(2,0);lcd.print("LOUDNESS  OFF");}}
////////////////////////////////////////////////////////////////////////////////////////////
 
////////////// BRIGHTNESS ///////////////////////////////////////////////////////////////////
 if(menu0==4&&menu2==1){
   if(ir.value==IR_3){brig++;gr1=1;gr2=0;cl1();times=millis();w=1;w2=1;brig_func();analogWrite(6,brig);}// кнопка > 
//   if(ir.value==0xFFFFFFFF and gr1==1){brig++;gr2=0;cl1();times=millis();w=1;w2=1;brig_func();analogWrite(6,brig);}// кнопка >>>>>>
   if(ir.value==IR_4){brig--;gr1=0;gr2=1;cl1();times=millis();w=1;w2=1;brig_func();analogWrite(6,brig);}// кнопка <
//   if(ir.value==0xFFFFFFFF and gr2==1){brig--;gr1=0;cl1();times=millis();w=1;w2=1;brig_func();analogWrite(6,brig);}// кнопка <<<<<<
 
   if (newPosition != oldPosition){oldPosition = newPosition;brig=brig+newPosition;myEnc.write(0);newPosition=0;times=millis();w=1;w2=1;brig_func();analogWrite(6,brig);}
   a[0]= abs(brig)/100;a[1]=abs(brig)/10%10;a[2]=abs(brig)%10;
   for(i=0;i<3;i++){switch(i){case 0: e1=7,e2=8,e3=9;break;
                              case 1: e1=10,e2=11,e3=12;break;
                              case 2: e1=13,e2=14,e3=15;break;
                              }digit();}
 
   lcd.setCursor(0,0);lcd.print("BRIGHT");
   lcd.setCursor(0,1);lcd.print(brig*100/255);lcd.print(" ");lcd.setCursor(4,1);lcd.print("%");}
////////////////////////////////////////////////////////////////////////////////////////////
 
if(millis()-times>10000&&w==1&&mute==0&&power==0){w=0;menu2=0;menu1=1;menu=0;cl();}
 
/////////////////// ЧАСЫ ///////////////////////////////////////////////////////////////////
if(power==1){digitalWrite(7,LOW);
     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(i=0;i<4;i++){
    switch(i){
        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(2)==HIGH){hour++;if(hour>23){hour=0;} clock.setDateTime(2020, 9, 15, hour, minut, secon);delay(100);}
  if(digitalRead(10)==LOW&&digitalRead(3)==HIGH){minut++;if(minut>59){minut=0;} clock.setDateTime(2020, 9, 15, hour, minut, secon);delay(100); }
  if(digitalRead(10)==LOW&&digitalRead(4)==HIGH){secon=0; clock.setDateTime(2020, 9, 15, hour, minut, secon);delay(100); }
}
////////////////////////////////////////////////////////////////////////////////////////////
}// loop
 
 
void times_f(){lcd.setCursor(1,1);lcd.print(DateTime.hour/10);lcd.print(DateTime.hour%10);lcd.print(":");lcd.print(DateTime.minute/10);lcd.print(DateTime.minute%10);lcd.print(":");lcd.print(DateTime.second/10);lcd.print(DateTime.second%10);}
void brig_func(){if(brig<0){brig=0;}if(brig>255){brig=255;}}
void gain_func(){if(gain0<0){gain0=0;}if(gain0>3){gain0=3;}}
void att_r_func(){if(att_r<0){att_r=0;}if(att_r>24){att_r=24;}}
void att_l_func(){if(att_l<0){att_l=0;}if(att_l>24){att_l=24;}}
void treb_func(){if(treb<-7){treb=-7;}if(treb>7){treb=7;}}
void bass_func(){if(bass<-7){bass=-7;}if(bass>7){bass=7;}}
void vol_func(){if(vol<0){vol=0;}if(vol>56){vol=56;}}
void cl(){ir.value=0;delay(300);lcd.clear();}
void cl1(){ir.value=0;delay(200);}  
void audio(){
  pt.setVolume(vol); // int 0...56 === -70...0 dB step 1.25 dB
  pt.setAttL(att_l); // int 0...24 === 0...-30 db step 1.25 dB > int 31 === mute on     
  pt.setAttR(att_r); // int 0...24 === 0...-30 dB step 1.25 dB > int 31 === mute on
  pt.setSwitch(in, loud_on, gain0); 
        // input      int 0..3 === IN 1...4 
        // loudness   int 0...1 === 1-on 0-off
        // input gain int 0...3 === 0...11.25dB step 3.75 dB
  pt.setBass(bass);   // int -7...+7 === -14...+14 dB step 2 dB
  pt.setTreble(treb); // int -7...+7 === -14...+14 dB step 2 dB
  }
 
void to_Timer(){newPosition = myEnc.read()/4;}  
 
void digit(){switch(a[i]){
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);}

97

Re: PT2314

liman324 спасибо большое. все заработало, поменял D11 на A2 и проблема исчезла))))

98

Re: PT2314

Основной скетч - http://rcl-radio.ru/?p=76005

С кнопками без резисторов, кнопка нажатие === GND

Исправлено меню селектора входа, устранен дефект дребезга контактов энкодера

#define IR_1 0x2FDD02F // Кнопка вверх
#define IR_2 0x2FD32CD // Кнопка вниз
#define IR_3 0x2FD906F // Кнопка >
#define IR_4 0x2FDF20D // Кнопка <
#define IR_5 0x2FD708F // Кнопка IN
#define IR_6 0x2FD6A95 // Кнопка SET
#define IR_7 0x2FD00FF // Кнопка MUTE
#define IR_8 0x2FDB24D // Кнопка STANDBY (POWER)
#define BRIG 50        // Яркость подсветки экрана в режиме POWER OFF (0...255)
#include <Wire.h> 
#include <PT2314.h>            // http://forum.rcl-radio.ru/misc.php?action=pan_download&item=434&download=1
#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>            // http://rcl-radio.ru/wp-content/uploads/2022/08/DS3231.zip
   DS3231 clock;RTCDateTime DateTime;
   PT2314 pt;
   LiquidCrystal_I2C lcd(0x27,16,2);  // Устанавливаем дисплей
   IRrecv irrecv(12); // указываем вывод модуля IR приемника
   Encoder myEnc(8, 9);// DT, CLK
   decode_results ir; 
      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};
      byte a[6],d1,d2,d3,d4,d5,d6,e1,e2,e3,w,w2,i,www,power,save,gr1,gr2;
      int menu,menu0,menu1=1,menu2=0,vol,bass,treb,att_l,att_r,in,loud_on,gain0,gain1,gain2,gain3,gain4,mute,mute1,mute2,brig,hour,minut,secon;
      long times,oldPosition  = -999,newPosition;
 
 
void setup() {
  delay(200);
  irrecv.enableIRIn();lcd.init();lcd.backlight();clock.begin();Serial.begin(9600);
  pinMode(10,INPUT);  // МЕНЮ КНОПКА SW энкодера
  pinMode(2,INPUT_PULLUP);   // КНОПКА SET
  pinMode(3,INPUT_PULLUP);   // КНОПКА IN
  pinMode(4,INPUT_PULLUP);   // КНОПКА MUTE
  pinMode(5,INPUT_PULLUP);   // КНОПКА STANDBY
  pinMode(7,OUTPUT);  // ВЫХОД УПРАВЛЕНИЯ STANDBY
  pinMode(6,OUTPUT);  // ВЫХОД УПРАВЛЕНИЯ ПОДСВЕТКОЙ
  analogWrite(6, 255);
  lcd.setCursor(0,0);lcd.print("Sound Processor");lcd.setCursor(0,1);lcd.print("PT2314"); delay(2000);lcd.clear();
  MsTimer2::set(1, to_Timer);MsTimer2::start();
  //  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);
  if(EEPROM.read(100)!=0){for(int i=0;i<101;i++){EEPROM.update(i,0);}}// очистка памяти при первом включении  
  vol = EEPROM.read(0);treb = EEPROM.read(1)-7;bass = EEPROM.read(2)-7;in = EEPROM.read(3);
  att_l = EEPROM.read(4);att_r = EEPROM.read(5);gain1 = EEPROM.read(6);gain2 = EEPROM.read(7);
  gain3 = EEPROM.read(8);gain4 = EEPROM.read(9);loud_on = EEPROM.read(10);brig = EEPROM.read(11);
  audio();
  analogWrite(6, brig);
}
 
void loop() {
  DateTime = clock.getDateTime();hour = DateTime.hour;minut = DateTime.minute;secon = DateTime.second;
 
////////////////////// 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;}// запрет нажатий не активных кнопок пульта  
 
    if(mute==0&&power==0){
  if(ir.value==IR_6&&menu1==1){menu1=0;menu2=1;gr1=0;gr2=0;cl();times=millis();w=1;w2=1;lcd.setCursor(4,0);lcd.print("SETTING"); delay(2000);lcd.clear();}
  if(ir.value==IR_6&&menu2==1){menu1=1;menu2=0;menu=0;gr1=0;gr2=0;cl();times=millis();w=1;w2=1;lcd.setCursor(6,0);lcd.print("MENU"); delay(2000);lcd.clear();}
 
  if(ir.value==IR_1&&menu1==1){menu++;gr1=0;gr2=0;cl();times=millis();w=1;w2=1;if(menu>2){menu=0;}}//меню 1
  if(ir.value==IR_2&&menu1==1){menu--;gr1=0;gr2=0;cl();times=millis();w=1;w2=1;if(menu<0){menu=2;}}//меню 1
 
  if(ir.value==IR_1&&menu2==1){menu0++;gr1=0;gr2=0;cl();times=millis();w=1;w2=1;if(menu0>4){menu0=0;}}//меню 2
  if(ir.value==IR_2&&menu2==1){menu0--;gr1=0;gr2=0;cl();times=millis();w=1;w2=1;if(menu0<0){menu0=4;}}//меню 2
 
  if(ir.value==IR_5){in++;gr1=0;gr2=0;cl();times=millis()-8000;w=1;w2=1;if(in>3){in=0;}lcd.setCursor(4,0);lcd.print("INPUT ");lcd.print(in+1);audio();delay(200);}// IN
  }
 
  if(ir.value==IR_7&&mute==0&&power==0){mute=1;pt.setAttR(31);pt.setAttL(31);gr1=0;gr2=0;cl();lcd.setCursor(6,0);lcd.print("MUTE");menu1=100;menu2=100;delay(500);}// MUTE
  if(ir.value==IR_7&&mute==1&&power==0){mute=0;cl();menu1=1;menu=0;gr1=0;gr2=0;cl();audio();}// MUTE
 
  if(ir.value==IR_8&&power==0){power=1;pt.setAttR(31);pt.setAttL(31);audio();gr1=0;gr2=0;cl();lcd.clear();lcd.setCursor(3,0);lcd.print("POWER  OFF");menu0=0;menu1=0;menu2=0;save=1;analogWrite(6, BRIG);delay(3000);lcd.clear();}// power off
  if(ir.value==IR_8&&power==1){power=0;gr1=0;gr2=0;cl();lcd.backlight();lcd.clear();lcd.setCursor(3,0);lcd.print("POWER   ON ");menu1=1;menu=0;myEnc.write(0);audio();analogWrite(6, brig);delay(3000);lcd.clear();}// power on
///////////////////////////////////////////////////////////////////////////////////////// 
 
/////////////////////////////// УПРАВЛЕНИЕ //////////////////////////////////////////////  
  if(mute==0&&power==0){
  if(digitalRead(2)==LOW&&menu1==1){menu1=0;menu2=1;cl();times=millis();w=1;w2=1;lcd.setCursor(4,0);lcd.print("SETTING"); delay(2000);lcd.clear();}
  if(digitalRead(2)==LOW&&menu2==1){menu1=1;menu2=0;menu=0;cl();times=millis();w=1;w2=1;lcd.setCursor(6,0);lcd.print("MENU"); delay(2000);lcd.clear();}
 
  if(digitalRead(10)==LOW&&menu1==1){menu++;cl();times=millis();w=1;w2=1;if(menu>2){menu=0;}}//меню 1
  if(digitalRead(10)==LOW&&menu2==1){menu0++;cl();times=millis();w=1;w2=1;if(menu0>4){menu0=0;}}//меню 2
 
  if(digitalRead(3)==LOW){in++;cl();menu=100;times=millis()-8000;w=1;w2=1;if(in>3){in=0;}lcd.setCursor(4,0);lcd.print("INPUT ");lcd.print(in+1);audio();delay(200);}// IN
  }
 
  if(digitalRead(4)==LOW&&mute==0&&power==0){mute=1;pt.setAttR(31);pt.setAttL(31);cl();lcd.setCursor(6,0);lcd.print("MUTE");menu1=100;menu2=100;delay(500);}// MUTE
  if(digitalRead(4)==LOW&&mute==1&&power==0){mute=0;cl();menu1=1;menu=0;cl();audio();}// MUTE
 
  if(digitalRead(5)==LOW&&power==0){power=1;pt.setAttR(31);pt.setAttL(31);lcd.clear();lcd.setCursor(3,0);lcd.print("POWER  OFF");menu0=0;menu1=0;menu2=0;save=1;analogWrite(6, 50);delay(3000);lcd.clear();}// power off
  if(digitalRead(5)==LOW&&power==1){power=0;lcd.backlight();lcd.clear();lcd.setCursor(3,0);lcd.print("POWER   ON ");menu1=1;menu=0;myEnc.write(0);audio();analogWrite(6, brig);delay(3000);lcd.clear();}// power on
    if(power==0){digitalWrite(7,HIGH);}
  //if(power==0){digitalWrite(7,LOW);}// инверсия выхода STANDBY


  
 
  if(save==1&&w2==1){save=0;w2=0;
     EEPROM.update(0,vol);EEPROM.update(1,treb+7);EEPROM.update(2,bass+7);EEPROM.update(3,in);
     EEPROM.update(4,att_l);EEPROM.update(5,att_r);EEPROM.update(6,gain1);EEPROM.update(7,gain2);
     EEPROM.update(8,gain3);EEPROM.update(9,gain4);EEPROM.update(10,loud_on);EEPROM.update(11,brig);}
///////////////////////////////////////////////////////////////////////////////////////// 
 
////////////// VOLUME ///////////////////////////////////////////////////////////////////
 if(menu==0&&menu1==1){
   if(ir.value==IR_3){vol++;gr1=1;gr2=0;cl1();times=millis();w=1;w2=1;vol_func();audio();}// кнопка > 
   if(ir.value==0xFFFFFFFF and gr1==1){vol++;gr2=0;cl1();times=millis();w=1;w2=1;vol_func();audio();}// кнопка >>>>>>
   if(ir.value==IR_4){vol--;gr1=0;gr2=1;cl1();times=millis();w=1;w2=1;vol_func();audio();}// кнопка <
   if(ir.value==0xFFFFFFFF and gr2==1){vol--;gr1=0;cl1();times=millis();w=1;w2=1;vol_func();audio();}// кнопка <<<<<<
 
   if (newPosition != oldPosition){oldPosition = newPosition;if(newPosition>1){newPosition=1;}if(newPosition<-1){newPosition=-1;}
   vol=vol+newPosition;myEnc.write(0);newPosition=0;times=millis();w=1;w2=1;vol_func();audio();}
   a[0]= vol/10;a[1]=vol%10;
   for(i=0;i<2;i++){switch(i){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("IN");lcd.print(in+1);lcd.print("  VOL");
   if(vol<0){lcd.setCursor(9,1);lcd.write((uint8_t)8);}else{lcd.setCursor(9,1);lcd.print(" ");}
   times_f();
   }
////////////////////////////////////////////////////////////////////////////////////////////
 
////////////// BASS ///////////////////////////////////////////////////////////////////
 if(menu==1&&menu1==1){
   if(ir.value==IR_3){bass++;gr1=1;gr2=0;cl1();times=millis();w=1;w2=1;bass_func();audio();}// кнопка > 
   if(ir.value==0xFFFFFFFF and gr1==1){bass++;gr2=0;cl1();times=millis();w=1;w2=1;bass_func();audio();}// кнопка >>>>>>
   if(ir.value==IR_4){bass--;gr1=0;gr2=1;cl1();times=millis();w=1;w2=1;bass_func();audio();}// кнопка <
   if(ir.value==0xFFFFFFFF and gr2==1){bass--;gr1=0;cl1();times=millis();w=1;w2=1;bass_func();audio();}// кнопка <<<<<<
 
   if (newPosition != oldPosition){oldPosition = newPosition;if(newPosition>1){newPosition=1;}if(newPosition<-1){newPosition=-1;}
   bass=bass+newPosition;myEnc.write(0);newPosition=0;times=millis();w=1;w2=1;bass_func();audio();}
   a[0]= abs(bass*2)/10;a[1]=abs(bass*2)%10;
   for(i=0;i<2;i++){switch(i){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   dB");
   if(bass<0){lcd.setCursor(9,1);lcd.write((uint8_t)8);}else{lcd.setCursor(9,1);lcd.print(" ");}
   times_f();
   }
////////////////////////////////////////////////////////////////////////////////////////////
 
////////////// TREBLE ///////////////////////////////////////////////////////////////////
 if(menu==2&&menu1==1){
   if(ir.value==IR_3){treb++;gr1=1;gr2=0;cl1();times=millis();w=1;w2=1;treb_func();audio();}// кнопка > 
   if(ir.value==0xFFFFFFFF and gr1==1){treb++;gr2=0;cl1();times=millis();w=1;w2=1;treb_func();audio();}// кнопка >>>>>>
   if(ir.value==IR_4){treb--;gr1=0;gr2=1;cl1();times=millis();w=1;w2=1;treb_func();audio();}// кнопка <
   if(ir.value==0xFFFFFFFF and gr2==1){treb--;gr1=0;cl1();times=millis();w=1;w2=1;treb_func();audio();}// кнопка <<<<<<
 
   if (newPosition != oldPosition){oldPosition = newPosition;if(newPosition>1){newPosition=1;}if(newPosition<-1){newPosition=-1;}
   treb=treb+newPosition;myEnc.write(0);newPosition=0;times=millis();w=1;w2=1;treb_func();audio();}
   a[0]= abs(treb*2)/10;a[1]=abs(treb*2)%10;
 
   for(i=0;i<2;i++){switch(i){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 dB");
   if(treb<0){lcd.setCursor(9,1);lcd.write((uint8_t)8);}else{lcd.setCursor(9,1);lcd.print(" ");}
   times_f();
   }
////////////////////////////////////////////////////////////////////////////////////////////
 
////////////// ATT_L ///////////////////////////////////////////////////////////////////
 if(menu0==0&&menu2==1){
   if(ir.value==IR_3){att_l++;gr1=1;gr2=0;cl1();times=millis();w=1;w2=1;att_l_func();audio();}// кнопка > 
   if(ir.value==0xFFFFFFFF and gr1==1){att_l++;gr2=0;cl1();times=millis();w=1;w2=1;att_l_func();audio();}// кнопка >>>>>>
   if(ir.value==IR_4){att_l--;gr1=0;gr2=1;cl1();times=millis();w=1;w2=1;att_l_func();audio();}// кнопка <
   if(ir.value==0xFFFFFFFF and gr2==1){att_l--;gr1=0;cl1();times=millis();w=1;w2=1;att_l_func();audio();}// кнопка <<<<<<
 
   if (newPosition != oldPosition){oldPosition = newPosition;if(newPosition>1){newPosition=1;}if(newPosition<-1){newPosition=-1;}
   att_l=att_l+newPosition;myEnc.write(0);newPosition=0;times=millis();w=1;w2=1;att_l_func();audio();}
   a[0]= abs(att_l)/10;a[1]=abs(att_l)%10;
   for(i=0;i<2;i++){switch(i){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_L");
   lcd.setCursor(0,1);lcd.print(-att_l*1.25,2);lcd.print(" ");lcd.setCursor(6,1);lcd.print("dB");}
////////////////////////////////////////////////////////////////////////////////////////////
 
////////////// ATT_R ///////////////////////////////////////////////////////////////////
 if(menu0==1&&menu2==1){
   if(ir.value==IR_3){att_r++;gr1=1;gr2=0;cl1();times=millis();w=1;w2=1;att_r_func();audio();}// кнопка > 
   if(ir.value==0xFFFFFFFF and gr1==1){att_r++;gr2=0;cl1();times=millis();w=1;w2=1;att_r_func();audio();}// кнопка >>>>>>
   if(ir.value==IR_4){att_r--;gr1=0;gr2=1;cl1();times=millis();w=1;w2=1;att_r_func();audio();}// кнопка <
   if(ir.value==0xFFFFFFFF and gr2==1){att_r--;gr1=0;cl1();times=millis();w=1;w2=1;att_r_func();audio();}// кнопка <<<<<<
 
   if (newPosition != oldPosition){oldPosition = newPosition;if(newPosition>1){newPosition=1;}if(newPosition<-1){newPosition=-1;}
   att_r=att_r+newPosition;myEnc.write(0);newPosition=0;times=millis();w=1;w2=1;att_r_func();audio();}
   a[0]= abs(att_r)/10;a[1]=abs(att_r)%10;
   for(i=0;i<2;i++){switch(i){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_R");
   lcd.setCursor(0,1);lcd.print(-att_r*1.25,2);lcd.print(" ");lcd.setCursor(6,1);lcd.print("dB");}
////////////////////////////////////////////////////////////////////////////////////////////
 
////////////// INPUT GAIN ///////////////////////////////////////////////////////////////////
 if(menu0==2&&menu2==1){
   switch(in){
     case 0: gain0 = gain1;break;
     case 1: gain0 = gain2;break;
     case 2: gain0 = gain3;break;
     case 3: gain0 = gain4;break;
     }
 
   if(ir.value==IR_3){gain0++;gr1=1;gr2=0;cl1();times=millis();w=1;w2=1;gain_func();www=1;}// кнопка > 
   if(ir.value==0xFFFFFFFF and gr1==1){gain0++;gr2=0;cl1();times=millis();w=1;w2=1;gain_func();www=1;}// кнопка >>>>>>
   if(ir.value==IR_4){gain0--;gr1=0;gr2=1;cl1();times=millis();w=1;w2=1;gain_func();www=1;}// кнопка <
   if(ir.value==0xFFFFFFFF and gr2==1){gain0--;gr1=0;cl1();times=millis();w=1;w2=1;gain_func();www=1;}// кнопка <<<<<<
 
   if (newPosition != oldPosition){oldPosition = newPosition;if(newPosition>1){newPosition=1;}if(newPosition<-1){newPosition=-1;}
   gain0=gain0+newPosition;myEnc.write(0);newPosition=0;times=millis();www=1;w=1;w2=1;gain_func();}
 
  switch(in){
     case 0: gain1 = gain0;break;
     case 1: gain2 = gain0;break;
     case 2: gain3 = gain0;break;
     case 3: gain4 = gain0;break;
     }  
     a[0]= abs(gain0);
 
   for(i=0;i<1;i++){switch(i){case 0: e1=13,e2=14,e3=15;break;case 1: e1=13,e2=14,e3=15;break;}digit();}
   lcd.setCursor(0,1);lcd.print("GAIN ");lcd.print(gain0*3.75,2);lcd.print(" ");lcd.setCursor(10,1);lcd.print("dB");
   if(www==1){audio();www=0;}
   lcd.setCursor(0,0);lcd.print("INPUT ");lcd.print(in+1);}
////////////////////////////////////////////////////////////////////////////////////////////
 
////////////// LOUDNESS ///////////////////////////////////////////////////////////////////
 if(menu0==3&&menu2==1){
   if(ir.value==IR_3){loud_on++;gr1=1;gr2=0;cl1();times=millis();w=1;w2=1;if(loud_on>1){loud_on=0;};if(loud_on<0){loud_on=1;}audio();}// кнопка > 
   if(ir.value==0xFFFFFFFF and gr1==1){loud_on++;gr2=0;cl1();times=millis();w=1;w2=1;if(loud_on>1){loud_on=0;};if(loud_on<0){loud_on=1;}audio();}// кнопка >>>>>>
   if(ir.value==IR_4){loud_on--;gr1=0;gr2=1;cl1();times=millis();w=1;w2=1;if(loud_on>1){loud_on=0;};if(loud_on<0){loud_on=1;}audio();}// кнопка <
   if(ir.value==0xFFFFFFFF and gr2==1){loud_on--;gr1=0;cl1();times=millis();w=1;w2=1;if(loud_on>1){loud_on=0;};if(loud_on<0){loud_on=1;}audio();}// кнопка <<<<<<
 
   if (newPosition != oldPosition){oldPosition = newPosition;if(newPosition>1){newPosition=1;}if(newPosition<-1){newPosition=-1;}
   loud_on=loud_on+newPosition;myEnc.write(0);newPosition=0;times=millis();w=1;w2=1;if(loud_on>1){loud_on=0;};if(loud_on<0){loud_on=1;};audio();}
   if(loud_on==1){lcd.setCursor(2,0);lcd.print("LOUDNESS  ON ");}
             else{lcd.setCursor(2,0);lcd.print("LOUDNESS  OFF");}}
////////////////////////////////////////////////////////////////////////////////////////////
 
////////////// BRIGHTNESS ///////////////////////////////////////////////////////////////////
 if(menu0==4&&menu2==1){
   if(ir.value==IR_3){brig++;gr1=1;gr2=0;cl1();times=millis();w=1;w2=1;brig_func();analogWrite(6,brig);}// кнопка > 
   if(ir.value==0xFFFFFFFF and gr1==1){brig++;gr2=0;cl1();times=millis();w=1;w2=1;brig_func();analogWrite(6,brig);}// кнопка >>>>>>
   if(ir.value==IR_4){brig--;gr1=0;gr2=1;cl1();times=millis();w=1;w2=1;brig_func();analogWrite(6,brig);}// кнопка <
   if(ir.value==0xFFFFFFFF and gr2==1){brig--;gr1=0;cl1();times=millis();w=1;w2=1;brig_func();analogWrite(6,brig);}// кнопка <<<<<<
 
   if (newPosition != oldPosition){oldPosition = newPosition;if(newPosition>1){newPosition=1;}if(newPosition<-1){newPosition=-1;}
   brig=brig+newPosition;myEnc.write(0);newPosition=0;times=millis();w=1;w2=1;brig_func();analogWrite(6,brig);}
   a[0]= abs(brig)/100;a[1]=abs(brig)/10%10;a[2]=abs(brig)%10;
   for(i=0;i<3;i++){switch(i){case 0: e1=7,e2=8,e3=9;break;
                              case 1: e1=10,e2=11,e3=12;break;
                              case 2: e1=13,e2=14,e3=15;break;
                              }digit();}
 
   lcd.setCursor(0,0);lcd.print("BRIGHT");
   lcd.setCursor(0,1);lcd.print(brig*100/255);lcd.print(" ");lcd.setCursor(4,1);lcd.print("%");}
////////////////////////////////////////////////////////////////////////////////////////////
 
if(millis()-times>10000&&w==1&&mute==0&&power==0){w=0;menu2=0;menu1=1;menu=0;cl();}
 
/////////////////// ЧАСЫ ///////////////////////////////////////////////////////////////////
if(power==1){digitalWrite(7,LOW);
     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(i=0;i<4;i++){
    switch(i){
        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(2)==HIGH){hour++;if(hour>23){hour=0;} clock.setDateTime(2020, 9, 15, hour, minut, secon);delay(100);}
  if(digitalRead(10)==LOW&&digitalRead(3)==HIGH){minut++;if(minut>59){minut=0;} clock.setDateTime(2020, 9, 15, hour, minut, secon);delay(100); }
  if(digitalRead(10)==LOW&&digitalRead(4)==HIGH){secon=0; clock.setDateTime(2020, 9, 15, hour, minut, secon);delay(100); }
}
////////////////////////////////////////////////////////////////////////////////////////////
}// loop
 
 
void times_f(){lcd.setCursor(0,1);lcd.print(DateTime.hour/10);lcd.print(DateTime.hour%10);lcd.print(":");lcd.print(DateTime.minute/10);lcd.print(DateTime.minute%10);lcd.print(":");lcd.print(DateTime.second/10);lcd.print(DateTime.second%10);}
void brig_func(){if(brig<0){brig=0;}if(brig>255){brig=255;}}
void gain_func(){if(gain0<0){gain0=0;}if(gain0>3){gain0=3;}}
void att_r_func(){if(att_r<0){att_r=0;}if(att_r>24){att_r=24;}}
void att_l_func(){if(att_l<0){att_l=0;}if(att_l>24){att_l=24;}}
void treb_func(){if(treb<-7){treb=-7;}if(treb>7){treb=7;}}
void bass_func(){if(bass<-7){bass=-7;}if(bass>7){bass=7;}}
void vol_func(){if(vol<0){vol=0;}if(vol>56){vol=56;}}
void cl(){ir.value=0;delay(300);lcd.clear();}
void cl1(){ir.value=0;delay(200);}  
void audio(){
  pt.setVolume(vol); // int 0...56 === -70...0 dB step 1.25 dB
  pt.setAttL(att_l); // int 0...24 === 0...-30 db step 1.25 dB > int 31 === mute on     
  pt.setAttR(att_r); // int 0...24 === 0...-30 dB step 1.25 dB > int 31 === mute on
  pt.setSwitch(in, loud_on, gain0); 
        // input      int 0..3 === IN 1...4 
        // loudness   int 0...1 === 1-on 0-off
        // input gain int 0...3 === 0...11.25dB step 3.75 dB
  pt.setBass(bass);   // int -7...+7 === -14...+14 dB step 2 dB
  pt.setTreble(treb); // int -7...+7 === -14...+14 dB step 2 dB
  }
 
void to_Timer(){newPosition = myEnc.read()/4;}  
 
void digit(){switch(a[i]){
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);}

99

Re: PT2314

Основной скетч - http://rcl-radio.ru/?p=76005

Кнопки с резисторами, кнопка нажатие === +5V, кнопка не нажата === подтягивающий резистор 10 К на GND

Исправлено меню селектора входа, устранен дефект дребезга контактов энкодера

#define IR_1 0x2FDD02F // Кнопка вверх
#define IR_2 0x2FD32CD // Кнопка вниз
#define IR_3 0x2FD906F // Кнопка >
#define IR_4 0x2FDF20D // Кнопка <
#define IR_5 0x2FD708F // Кнопка IN
#define IR_6 0x2FD6A95 // Кнопка SET
#define IR_7 0x2FD00FF // Кнопка MUTE
#define IR_8 0x2FDB24D // Кнопка STANDBY (POWER)
#define BRIG 50        // Яркость подсветки экрана в режиме POWER OFF (0...255)
#include <Wire.h> 
#include <PT2314.h>            // http://forum.rcl-radio.ru/misc.php?action=pan_download&item=434&download=1
#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>            // http://rcl-radio.ru/wp-content/uploads/2022/08/DS3231.zip
   DS3231 clock;RTCDateTime DateTime;
   PT2314 pt;
   LiquidCrystal_I2C lcd(0x27,16,2);  // Устанавливаем дисплей
   IRrecv irrecv(12); // указываем вывод модуля IR приемника
   Encoder myEnc(8, 9);// DT, CLK
   decode_results ir; 
      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};
      byte a[6],d1,d2,d3,d4,d5,d6,e1,e2,e3,w,w2,i,www,power,save,gr1,gr2;
      int menu,menu0,menu1=1,menu2=0,vol,bass,treb,att_l,att_r,in,loud_on,gain0,gain1,gain2,gain3,gain4,mute,mute1,mute2,brig,hour,minut,secon;
      long times,oldPosition  = -999,newPosition;
 
 
void setup() {
  delay(200);
  irrecv.enableIRIn();lcd.init();lcd.backlight();clock.begin();Serial.begin(9600);
  pinMode(10,INPUT);  // МЕНЮ КНОПКА SW энкодера
  pinMode(2,INPUT);   // КНОПКА SET
  pinMode(3,INPUT);   // КНОПКА IN
  pinMode(4,INPUT);   // КНОПКА MUTE
  pinMode(5,INPUT);   // КНОПКА STANDBY
  pinMode(7,OUTPUT);  // ВЫХОД УПРАВЛЕНИЯ STANDBY
  pinMode(6,OUTPUT);  // ВЫХОД УПРАВЛЕНИЯ ПОДСВЕТКОЙ
  analogWrite(6, 255);
  lcd.setCursor(0,0);lcd.print("Sound Processor");lcd.setCursor(0,1);lcd.print("PT2314"); delay(2000);lcd.clear();
  MsTimer2::set(1, to_Timer);MsTimer2::start();
  //  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);
  if(EEPROM.read(100)!=0){for(int i=0;i<101;i++){EEPROM.update(i,0);}}// очистка памяти при первом включении  
  vol = EEPROM.read(0);treb = EEPROM.read(1)-7;bass = EEPROM.read(2)-7;in = EEPROM.read(3);
  att_l = EEPROM.read(4);att_r = EEPROM.read(5);gain1 = EEPROM.read(6);gain2 = EEPROM.read(7);
  gain3 = EEPROM.read(8);gain4 = EEPROM.read(9);loud_on = EEPROM.read(10);brig = EEPROM.read(11);
  audio();
  analogWrite(6, brig);
}
 
void loop() {
  DateTime = clock.getDateTime();hour = DateTime.hour;minut = DateTime.minute;secon = DateTime.second;
 
////////////////////// 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;}// запрет нажатий не активных кнопок пульта  
 
    if(mute==0&&power==0){
  if(ir.value==IR_6&&menu1==1){menu1=0;menu2=1;gr1=0;gr2=0;cl();times=millis();w=1;w2=1;lcd.setCursor(4,0);lcd.print("SETTING"); delay(2000);lcd.clear();}
  if(ir.value==IR_6&&menu2==1){menu1=1;menu2=0;menu=0;gr1=0;gr2=0;cl();times=millis();w=1;w2=1;lcd.setCursor(6,0);lcd.print("MENU"); delay(2000);lcd.clear();}
 
  if(ir.value==IR_1&&menu1==1){menu++;gr1=0;gr2=0;cl();times=millis();w=1;w2=1;if(menu>2){menu=0;}}//меню 1
  if(ir.value==IR_2&&menu1==1){menu--;gr1=0;gr2=0;cl();times=millis();w=1;w2=1;if(menu<0){menu=2;}}//меню 1
 
  if(ir.value==IR_1&&menu2==1){menu0++;gr1=0;gr2=0;cl();times=millis();w=1;w2=1;if(menu0>4){menu0=0;}}//меню 2
  if(ir.value==IR_2&&menu2==1){menu0--;gr1=0;gr2=0;cl();times=millis();w=1;w2=1;if(menu0<0){menu0=4;}}//меню 2
 
  if(ir.value==IR_5){in++;gr1=0;gr2=0;cl();times=millis()-8000;w=1;w2=1;if(in>3){in=0;}lcd.setCursor(4,0);lcd.print("INPUT ");lcd.print(in+1);audio();delay(200);}// IN
  }
 
  if(ir.value==IR_7&&mute==0&&power==0){mute=1;pt.setAttR(31);pt.setAttL(31);gr1=0;gr2=0;cl();lcd.setCursor(6,0);lcd.print("MUTE");menu1=100;menu2=100;delay(500);}// MUTE
  if(ir.value==IR_7&&mute==1&&power==0){mute=0;cl();menu1=1;menu=0;gr1=0;gr2=0;cl();audio();}// MUTE
 
  if(ir.value==IR_8&&power==0){power=1;pt.setAttR(31);pt.setAttL(31);audio();gr1=0;gr2=0;cl();lcd.clear();lcd.setCursor(3,0);lcd.print("POWER  OFF");menu0=0;menu1=0;menu2=0;save=1;analogWrite(6, BRIG);delay(3000);lcd.clear();}// power off
  if(ir.value==IR_8&&power==1){power=0;gr1=0;gr2=0;cl();lcd.backlight();lcd.clear();lcd.setCursor(3,0);lcd.print("POWER   ON ");menu1=1;menu=0;myEnc.write(0);audio();analogWrite(6, brig);delay(3000);lcd.clear();}// power on
///////////////////////////////////////////////////////////////////////////////////////// 
 
/////////////////////////////// УПРАВЛЕНИЕ //////////////////////////////////////////////  
  if(mute==0&&power==0){
  if(digitalRead(2)==HIGH&&menu1==1){menu1=0;menu2=1;cl();times=millis();w=1;w2=1;lcd.setCursor(4,0);lcd.print("SETTING"); delay(2000);lcd.clear();}
  if(digitalRead(2)==HIGH&&menu2==1){menu1=1;menu2=0;menu=0;cl();times=millis();w=1;w2=1;lcd.setCursor(6,0);lcd.print("MENU"); delay(2000);lcd.clear();}
 
  if(digitalRead(10)==LOW&&menu1==1){menu++;cl();times=millis();w=1;w2=1;if(menu>2){menu=0;}}//меню 1
  if(digitalRead(10)==LOW&&menu2==1){menu0++;cl();times=millis();w=1;w2=1;if(menu0>4){menu0=0;}}//меню 2
 
  if(digitalRead(3)==HIGH){in++;cl();menu=100;times=millis()-8000;w=1;w2=1;if(in>3){in=0;}lcd.setCursor(4,0);lcd.print("INPUT ");lcd.print(in+1);audio();delay(200);}// IN
  }
 
  if(digitalRead(4)==HIGH&&mute==0&&power==0){mute=1;pt.setAttR(31);pt.setAttL(31);cl();lcd.setCursor(6,0);lcd.print("MUTE");menu1=100;menu2=100;delay(500);}// MUTE
  if(digitalRead(4)==HIGH&&mute==1&&power==0){mute=0;cl();menu1=1;menu=0;cl();audio();}// MUTE
 
  if(digitalRead(5)==HIGH&&power==0){power=1;pt.setAttR(31);pt.setAttL(31);lcd.clear();lcd.setCursor(3,0);lcd.print("POWER  OFF");menu0=0;menu1=0;menu2=0;save=1;analogWrite(6, 50);delay(3000);lcd.clear();}// power off
  if(digitalRead(5)==HIGH&&power==1){power=0;lcd.backlight();lcd.clear();lcd.setCursor(3,0);lcd.print("POWER   ON ");menu1=1;menu=0;myEnc.write(0);audio();analogWrite(6, brig);delay(3000);lcd.clear();}// power on
    if(power==0){digitalWrite(7,HIGH);}
  //if(power==0){digitalWrite(7,LOW);}// инверсия выхода STANDBY


  
 
  if(save==1&&w2==1){save=0;w2=0;
     EEPROM.update(0,vol);EEPROM.update(1,treb+7);EEPROM.update(2,bass+7);EEPROM.update(3,in);
     EEPROM.update(4,att_l);EEPROM.update(5,att_r);EEPROM.update(6,gain1);EEPROM.update(7,gain2);
     EEPROM.update(8,gain3);EEPROM.update(9,gain4);EEPROM.update(10,loud_on);EEPROM.update(11,brig);}
///////////////////////////////////////////////////////////////////////////////////////// 
 
////////////// VOLUME ///////////////////////////////////////////////////////////////////
 if(menu==0&&menu1==1){
   if(ir.value==IR_3){vol++;gr1=1;gr2=0;cl1();times=millis();w=1;w2=1;vol_func();audio();}// кнопка > 
   if(ir.value==0xFFFFFFFF and gr1==1){vol++;gr2=0;cl1();times=millis();w=1;w2=1;vol_func();audio();}// кнопка >>>>>>
   if(ir.value==IR_4){vol--;gr1=0;gr2=1;cl1();times=millis();w=1;w2=1;vol_func();audio();}// кнопка <
   if(ir.value==0xFFFFFFFF and gr2==1){vol--;gr1=0;cl1();times=millis();w=1;w2=1;vol_func();audio();}// кнопка <<<<<<
 
   if (newPosition != oldPosition){oldPosition = newPosition;if(newPosition>1){newPosition=1;}if(newPosition<-1){newPosition=-1;}
   vol=vol+newPosition;myEnc.write(0);newPosition=0;times=millis();w=1;w2=1;vol_func();audio();}
   a[0]= vol/10;a[1]=vol%10;
   for(i=0;i<2;i++){switch(i){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("IN");lcd.print(in+1);lcd.print("  VOL");
   if(vol<0){lcd.setCursor(9,1);lcd.write((uint8_t)8);}else{lcd.setCursor(9,1);lcd.print(" ");}
   times_f();
   }
////////////////////////////////////////////////////////////////////////////////////////////
 
////////////// BASS ///////////////////////////////////////////////////////////////////
 if(menu==1&&menu1==1){
   if(ir.value==IR_3){bass++;gr1=1;gr2=0;cl1();times=millis();w=1;w2=1;bass_func();audio();}// кнопка > 
   if(ir.value==0xFFFFFFFF and gr1==1){bass++;gr2=0;cl1();times=millis();w=1;w2=1;bass_func();audio();}// кнопка >>>>>>
   if(ir.value==IR_4){bass--;gr1=0;gr2=1;cl1();times=millis();w=1;w2=1;bass_func();audio();}// кнопка <
   if(ir.value==0xFFFFFFFF and gr2==1){bass--;gr1=0;cl1();times=millis();w=1;w2=1;bass_func();audio();}// кнопка <<<<<<
 
   if (newPosition != oldPosition){oldPosition = newPosition;if(newPosition>1){newPosition=1;}if(newPosition<-1){newPosition=-1;}
   bass=bass+newPosition;myEnc.write(0);newPosition=0;times=millis();w=1;w2=1;bass_func();audio();}
   a[0]= abs(bass*2)/10;a[1]=abs(bass*2)%10;
   for(i=0;i<2;i++){switch(i){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   dB");
   if(bass<0){lcd.setCursor(9,1);lcd.write((uint8_t)8);}else{lcd.setCursor(9,1);lcd.print(" ");}
   times_f();
   }
////////////////////////////////////////////////////////////////////////////////////////////
 
////////////// TREBLE ///////////////////////////////////////////////////////////////////
 if(menu==2&&menu1==1){
   if(ir.value==IR_3){treb++;gr1=1;gr2=0;cl1();times=millis();w=1;w2=1;treb_func();audio();}// кнопка > 
   if(ir.value==0xFFFFFFFF and gr1==1){treb++;gr2=0;cl1();times=millis();w=1;w2=1;treb_func();audio();}// кнопка >>>>>>
   if(ir.value==IR_4){treb--;gr1=0;gr2=1;cl1();times=millis();w=1;w2=1;treb_func();audio();}// кнопка <
   if(ir.value==0xFFFFFFFF and gr2==1){treb--;gr1=0;cl1();times=millis();w=1;w2=1;treb_func();audio();}// кнопка <<<<<<
 
   if (newPosition != oldPosition){oldPosition = newPosition;if(newPosition>1){newPosition=1;}if(newPosition<-1){newPosition=-1;}
   treb=treb+newPosition;myEnc.write(0);newPosition=0;times=millis();w=1;w2=1;treb_func();audio();}
   a[0]= abs(treb*2)/10;a[1]=abs(treb*2)%10;
 
   for(i=0;i<2;i++){switch(i){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 dB");
   if(treb<0){lcd.setCursor(9,1);lcd.write((uint8_t)8);}else{lcd.setCursor(9,1);lcd.print(" ");}
   times_f();
   }
////////////////////////////////////////////////////////////////////////////////////////////
 
////////////// ATT_L ///////////////////////////////////////////////////////////////////
 if(menu0==0&&menu2==1){
   if(ir.value==IR_3){att_l++;gr1=1;gr2=0;cl1();times=millis();w=1;w2=1;att_l_func();audio();}// кнопка > 
   if(ir.value==0xFFFFFFFF and gr1==1){att_l++;gr2=0;cl1();times=millis();w=1;w2=1;att_l_func();audio();}// кнопка >>>>>>
   if(ir.value==IR_4){att_l--;gr1=0;gr2=1;cl1();times=millis();w=1;w2=1;att_l_func();audio();}// кнопка <
   if(ir.value==0xFFFFFFFF and gr2==1){att_l--;gr1=0;cl1();times=millis();w=1;w2=1;att_l_func();audio();}// кнопка <<<<<<
 
   if (newPosition != oldPosition){oldPosition = newPosition;if(newPosition>1){newPosition=1;}if(newPosition<-1){newPosition=-1;}
   att_l=att_l+newPosition;myEnc.write(0);newPosition=0;times=millis();w=1;w2=1;att_l_func();audio();}
   a[0]= abs(att_l)/10;a[1]=abs(att_l)%10;
   for(i=0;i<2;i++){switch(i){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_L");
   lcd.setCursor(0,1);lcd.print(-att_l*1.25,2);lcd.print(" ");lcd.setCursor(6,1);lcd.print("dB");}
////////////////////////////////////////////////////////////////////////////////////////////
 
////////////// ATT_R ///////////////////////////////////////////////////////////////////
 if(menu0==1&&menu2==1){
   if(ir.value==IR_3){att_r++;gr1=1;gr2=0;cl1();times=millis();w=1;w2=1;att_r_func();audio();}// кнопка > 
   if(ir.value==0xFFFFFFFF and gr1==1){att_r++;gr2=0;cl1();times=millis();w=1;w2=1;att_r_func();audio();}// кнопка >>>>>>
   if(ir.value==IR_4){att_r--;gr1=0;gr2=1;cl1();times=millis();w=1;w2=1;att_r_func();audio();}// кнопка <
   if(ir.value==0xFFFFFFFF and gr2==1){att_r--;gr1=0;cl1();times=millis();w=1;w2=1;att_r_func();audio();}// кнопка <<<<<<
 
   if (newPosition != oldPosition){oldPosition = newPosition;if(newPosition>1){newPosition=1;}if(newPosition<-1){newPosition=-1;}
   att_r=att_r+newPosition;myEnc.write(0);newPosition=0;times=millis();w=1;w2=1;att_r_func();audio();}
   a[0]= abs(att_r)/10;a[1]=abs(att_r)%10;
   for(i=0;i<2;i++){switch(i){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_R");
   lcd.setCursor(0,1);lcd.print(-att_r*1.25,2);lcd.print(" ");lcd.setCursor(6,1);lcd.print("dB");}
////////////////////////////////////////////////////////////////////////////////////////////
 
////////////// INPUT GAIN ///////////////////////////////////////////////////////////////////
 if(menu0==2&&menu2==1){
   switch(in){
     case 0: gain0 = gain1;break;
     case 1: gain0 = gain2;break;
     case 2: gain0 = gain3;break;
     case 3: gain0 = gain4;break;
     }
 
   if(ir.value==IR_3){gain0++;gr1=1;gr2=0;cl1();times=millis();w=1;w2=1;gain_func();www=1;}// кнопка > 
   if(ir.value==0xFFFFFFFF and gr1==1){gain0++;gr2=0;cl1();times=millis();w=1;w2=1;gain_func();www=1;}// кнопка >>>>>>
   if(ir.value==IR_4){gain0--;gr1=0;gr2=1;cl1();times=millis();w=1;w2=1;gain_func();www=1;}// кнопка <
   if(ir.value==0xFFFFFFFF and gr2==1){gain0--;gr1=0;cl1();times=millis();w=1;w2=1;gain_func();www=1;}// кнопка <<<<<<
 
   if (newPosition != oldPosition){oldPosition = newPosition;if(newPosition>1){newPosition=1;}if(newPosition<-1){newPosition=-1;}
   gain0=gain0+newPosition;myEnc.write(0);newPosition=0;times=millis();www=1;w=1;w2=1;gain_func();}
 
  switch(in){
     case 0: gain1 = gain0;break;
     case 1: gain2 = gain0;break;
     case 2: gain3 = gain0;break;
     case 3: gain4 = gain0;break;
     }  
     a[0]= abs(gain0);
 
   for(i=0;i<1;i++){switch(i){case 0: e1=13,e2=14,e3=15;break;case 1: e1=13,e2=14,e3=15;break;}digit();}
   lcd.setCursor(0,1);lcd.print("GAIN ");lcd.print(gain0*3.75,2);lcd.print(" ");lcd.setCursor(10,1);lcd.print("dB");
   if(www==1){audio();www=0;}
   lcd.setCursor(0,0);lcd.print("INPUT ");lcd.print(in+1);}
////////////////////////////////////////////////////////////////////////////////////////////
 
////////////// LOUDNESS ///////////////////////////////////////////////////////////////////
 if(menu0==3&&menu2==1){
   if(ir.value==IR_3){loud_on++;gr1=1;gr2=0;cl1();times=millis();w=1;w2=1;if(loud_on>1){loud_on=0;};if(loud_on<0){loud_on=1;}audio();}// кнопка > 
   if(ir.value==0xFFFFFFFF and gr1==1){loud_on++;gr2=0;cl1();times=millis();w=1;w2=1;if(loud_on>1){loud_on=0;};if(loud_on<0){loud_on=1;}audio();}// кнопка >>>>>>
   if(ir.value==IR_4){loud_on--;gr1=0;gr2=1;cl1();times=millis();w=1;w2=1;if(loud_on>1){loud_on=0;};if(loud_on<0){loud_on=1;}audio();}// кнопка <
   if(ir.value==0xFFFFFFFF and gr2==1){loud_on--;gr1=0;cl1();times=millis();w=1;w2=1;if(loud_on>1){loud_on=0;};if(loud_on<0){loud_on=1;}audio();}// кнопка <<<<<<
 
   if (newPosition != oldPosition){oldPosition = newPosition;if(newPosition>1){newPosition=1;}if(newPosition<-1){newPosition=-1;}
   loud_on=loud_on+newPosition;myEnc.write(0);newPosition=0;times=millis();w=1;w2=1;if(loud_on>1){loud_on=0;};if(loud_on<0){loud_on=1;};audio();}
   if(loud_on==1){lcd.setCursor(2,0);lcd.print("LOUDNESS  ON ");}
             else{lcd.setCursor(2,0);lcd.print("LOUDNESS  OFF");}}
////////////////////////////////////////////////////////////////////////////////////////////
 
////////////// BRIGHTNESS ///////////////////////////////////////////////////////////////////
 if(menu0==4&&menu2==1){
   if(ir.value==IR_3){brig++;gr1=1;gr2=0;cl1();times=millis();w=1;w2=1;brig_func();analogWrite(6,brig);}// кнопка > 
   if(ir.value==0xFFFFFFFF and gr1==1){brig++;gr2=0;cl1();times=millis();w=1;w2=1;brig_func();analogWrite(6,brig);}// кнопка >>>>>>
   if(ir.value==IR_4){brig--;gr1=0;gr2=1;cl1();times=millis();w=1;w2=1;brig_func();analogWrite(6,brig);}// кнопка <
   if(ir.value==0xFFFFFFFF and gr2==1){brig--;gr1=0;cl1();times=millis();w=1;w2=1;brig_func();analogWrite(6,brig);}// кнопка <<<<<<
 
   if (newPosition != oldPosition){oldPosition = newPosition;if(newPosition>1){newPosition=1;}if(newPosition<-1){newPosition=-1;}
   brig=brig+newPosition;myEnc.write(0);newPosition=0;times=millis();w=1;w2=1;brig_func();analogWrite(6,brig);}
   a[0]= abs(brig)/100;a[1]=abs(brig)/10%10;a[2]=abs(brig)%10;
   for(i=0;i<3;i++){switch(i){case 0: e1=7,e2=8,e3=9;break;
                              case 1: e1=10,e2=11,e3=12;break;
                              case 2: e1=13,e2=14,e3=15;break;
                              }digit();}
 
   lcd.setCursor(0,0);lcd.print("BRIGHT");
   lcd.setCursor(0,1);lcd.print(brig*100/255);lcd.print(" ");lcd.setCursor(4,1);lcd.print("%");}
////////////////////////////////////////////////////////////////////////////////////////////
 
if(millis()-times>10000&&w==1&&mute==0&&power==0){w=0;menu2=0;menu1=1;menu=0;cl();}
 
/////////////////// ЧАСЫ ///////////////////////////////////////////////////////////////////
if(power==1){digitalWrite(7,LOW);
     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(i=0;i<4;i++){
    switch(i){
        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(2)==HIGH){hour++;if(hour>23){hour=0;} clock.setDateTime(2020, 9, 15, hour, minut, secon);delay(100);}
  if(digitalRead(10)==LOW&&digitalRead(3)==HIGH){minut++;if(minut>59){minut=0;} clock.setDateTime(2020, 9, 15, hour, minut, secon);delay(100); }
  if(digitalRead(10)==LOW&&digitalRead(4)==HIGH){secon=0; clock.setDateTime(2020, 9, 15, hour, minut, secon);delay(100); }
}
////////////////////////////////////////////////////////////////////////////////////////////
}// loop
 
 
void times_f(){lcd.setCursor(0,1);lcd.print(DateTime.hour/10);lcd.print(DateTime.hour%10);lcd.print(":");lcd.print(DateTime.minute/10);lcd.print(DateTime.minute%10);lcd.print(":");lcd.print(DateTime.second/10);lcd.print(DateTime.second%10);}
void brig_func(){if(brig<0){brig=0;}if(brig>255){brig=255;}}
void gain_func(){if(gain0<0){gain0=0;}if(gain0>3){gain0=3;}}
void att_r_func(){if(att_r<0){att_r=0;}if(att_r>24){att_r=24;}}
void att_l_func(){if(att_l<0){att_l=0;}if(att_l>24){att_l=24;}}
void treb_func(){if(treb<-7){treb=-7;}if(treb>7){treb=7;}}
void bass_func(){if(bass<-7){bass=-7;}if(bass>7){bass=7;}}
void vol_func(){if(vol<0){vol=0;}if(vol>56){vol=56;}}
void cl(){ir.value=0;delay(300);lcd.clear();}
void cl1(){ir.value=0;delay(200);}  
void audio(){
  pt.setVolume(vol); // int 0...56 === -70...0 dB step 1.25 dB
  pt.setAttL(att_l); // int 0...24 === 0...-30 db step 1.25 dB > int 31 === mute on     
  pt.setAttR(att_r); // int 0...24 === 0...-30 dB step 1.25 dB > int 31 === mute on
  pt.setSwitch(in, loud_on, gain0); 
        // input      int 0..3 === IN 1...4 
        // loudness   int 0...1 === 1-on 0-off
        // input gain int 0...3 === 0...11.25dB step 3.75 dB
  pt.setBass(bass);   // int -7...+7 === -14...+14 dB step 2 dB
  pt.setTreble(treb); // int -7...+7 === -14...+14 dB step 2 dB
  }
 
void to_Timer(){newPosition = myEnc.read()/4;}  
 
void digit(){switch(a[i]){
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);}

100

Re: PT2314

Вот теперь входы переключаются адекватно!!! Не знаю что Вы сделали с энкодером, но стало намного хуже, приходится делать ОООочень много оборотов, может надо убрать подтягивающие резисторы на 10К? Но раньше работал как надо! Ну и к примеру нажимаю кнопку"SET" и надпись "SETINGS" висит очень долго, тоже самое и с "POWER ON, OFF". Можно ли сократить раза в 3 это время? Ну и последний момент, выставляю в скетче яркость дисплея "10", заливаю, а яркость остаётся всё равно "50", да и почему то при сбосе питания сбиваются все настройки