1

Тема: NTP3000 РАЗРАБОТКА

http://forum.rcl-radio.ru/uploads/images/2023/02/10fc5babdfdab4b1e68e6707c371ccaf.gif

http://forum.rcl-radio.ru/uploads/images/2023/02/07cfbafc27236f1aca084f9cc3c77498.gif

http://forum.rcl-radio.ru/uploads/images/2023/02/c77b4d44785107de3bff39b9817df88c.gif

Test

#define I2C_NTP3000 0x2A // Address chip | MONITOR_0 = GND 

#include <Wire.h>

int in=1;

void setup() {
  delay(500);
  Wire.begin();Serial.begin(9600);
  pinMode(2,OUTPUT); // RSEL0 PIN  CS8416
  pinMode(3,OUTPUT); // RSEL1 PIN  CS8416
  pinMode(4,OUTPUT);
  pinMode(5,OUTPUT);
  
  digitalWrite(4,HIGH);delay(100);  // RESET NTP
  digitalWrite(4,LOW);delay(100);   // RESET NTP
  digitalWrite(4,HIGH);delay(100);  // RESET NTP
  in_sw();
  init_ntp(); 
  Serial.println(wireRead(I2C_NTP3000,0x75),BIN); 
  digitalWrite(5,HIGH);delay(200);  // FAULT NTP
}

void loop() {
 // Serial.println(wireRead(I2C_NTP3000,0x75),BIN);

  delay(1000);
}


void init_ntp(){ 
    wireWrite(I2C_NTP3000,0x00,0b00011100);// I2S, slave mode|192kHz
    wireWrite(I2C_NTP3000,0x01,0b00000000);// 24 bit, 64 BCK/WCK
    wireWrite(I2C_NTP3000,0x02,0b00000010);// 18.432 MHz
    wireWrite(I2C_NTP3000,0x03,0b00000000);// AD MODE ASIN
    wireWrite(I2C_NTP3000,0x04,0);// AUTO MUTE OFF 1-2CH
    wireWrite(I2C_NTP3000,0x05,0);// AUTO MUTE OFF 3CH
    wireWrite(I2C_NTP3000,0x06,0b00101010);// EQ USER DEFINED
    wireWrite(I2C_NTP3000,0x07,0);// ACL CONF_1
    wireWrite(I2C_NTP3000,0x08,0);// ACL CONF_2
    wireWrite(I2C_NTP3000,0x09,0);// ACL CONF_3
    wireWrite(I2C_NTP3000,0x0A,0b00000111);// MASTER VOL OVERRIDE
    wireWrite(I2C_NTP3000,0x0B,0b00001000);// PWM 1A&1B
    wireWrite(I2C_NTP3000,0x0C,0b00011010);// PWM 2A&2B
    wireWrite(I2C_NTP3000,0x0D,0b00101100);// PWM 3A&3B
    wireWrite(I2C_NTP3000,0x0E,0);// DRC CONTR CH1-2
    wireWrite(I2C_NTP3000,0x0F,0);// DRC CONTR CH3
    wireWrite(I2C_NTP3000,0x10,0);// DRC CONFIG
    wireWrite(I2C_NTP3000,0x11,0);// NS-TUPE DEF
    wireWrite(I2C_NTP3000,0x12,208);// PRESCALER CONRT CH1-2 DEF
    wireWrite(I2C_NTP3000,0x13,0);// PRESCALER CONTR CH3
   
    wireWrite(I2C_NTP3000,0x17,0);// AOUT RISING EDGE DELAY DEF
    wireWrite(I2C_NTP3000,0x18,0);// AOUT FALLING EDGE DELAY DEF
    wireWrite(I2C_NTP3000,0x19,0);// BOUT RISING EDGE DELAY
    wireWrite(I2C_NTP3000,0x1A,0);// BOUT FALLING EDGE DELAY
    wireWrite(I2C_NTP3000,0x1B,0b10101000);// PWM OFF & AUTO PROTECT CONTR DEF
    wireWrite(I2C_NTP3000,0x1C,0);// AUTO PROTECT CONF CONTROL MASKING
    wireWrite(I2C_NTP3000,0x1D,0);// PROTECT CONTROL DEF
    wireWrite(I2C_NTP3000,0x1E,0b00000000);// PROTECT CONTROL DEF
    wireWrite(I2C_NTP3000,0x1F,0b00000000);// SWITCHING OFF !!!!!
    
    wireWrite(I2C_NTP3000,0x20,0b00000000);// SOFTMUTE !!!!
    wireWrite(I2C_NTP3000,0x2C,0b00111111);// FBQ_FLAG CH1-2-3 DEF
    wireWrite(I2C_NTP3000,0x2D,0b00000001);// MASTER FINE VOLUME DEF
    wireWrite(I2C_NTP3000,0x2E,240);// MASTER VOLUME 
    wireWrite(I2C_NTP3000,0x2F,170);// MASTER VOLUME CH1
    wireWrite(I2C_NTP3000,0x30,170);// MASTER VOLUME CH2
    wireWrite(I2C_NTP3000,0x31,0);// MASTER VOLUME CH3
    
    wireWrite(I2C_NTP3000,0x69,0);// EQ 80 HZ
    wireWrite(I2C_NTP3000,0x6A,0);// EQ 120 KHZ
    wireWrite(I2C_NTP3000,0x32,0);// EQ 220 HZ
    wireWrite(I2C_NTP3000,0x33,0);// EQ 470 HZ
    wireWrite(I2C_NTP3000,0x36,0);// EQ 1 KHZ
    wireWrite(I2C_NTP3000,0x34,0);// EQ 2.2 KHZ
    wireWrite(I2C_NTP3000,0x35,0);// EQ 4.7 KHZ
    
    wireWrite(I2C_NTP3000,0x37,80);// MIXER GAIN
    wireWrite(I2C_NTP3000,0x38,80);// MIXER GAIN
    wireWrite(I2C_NTP3000,0x39,80);// MIXER GAIN
    wireWrite(I2C_NTP3000,0x3A,80);// MIXER GAIN
    wireWrite(I2C_NTP3000,0x3B,0);// MIXER GAIN
    wireWrite(I2C_NTP3000,0x3C,0);// MIXER GAIN
    wireWrite(I2C_NTP3000,0x3D,0);// Back Biquad Filter Conf Ch1-2 DEF
    wireWrite(I2C_NTP3000,0x3E,0);// Back Biquad Filter Conf Ch1-2 DEF
    wireWrite(I2C_NTP3000,0x3F,0);// Biquad Filter Coefficient DEF 
    
    wireWrite(I2C_NTP3000,0x60,1);// 3D DELAY
    wireWrite(I2C_NTP3000,0x61,0);// 3D EFFECT
    wireWrite(I2C_NTP3000,0x62,0b00000010);// PWM 2.0 CH
    wireWrite(I2C_NTP3000,0x63,0b00000001);// STANDBY  
  }


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

void in_sw(){
  switch(in){
    case 0: digitalWrite(2,LOW);digitalWrite(3,LOW);break;
    case 1: digitalWrite(2,HIGH);digitalWrite(3,LOW);break;
    case 2: digitalWrite(2,LOW);digitalWrite(3,HIGH);break;
    case 3: digitalWrite(2,HIGH);digitalWrite(3,HIGH);break;
    }} 

2

Re: NTP3000 РАЗРАБОТКА

Проект завершен - http://rcl-radio.ru/?p=130078

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

3

Re: NTP3000 РАЗРАБОТКА

Доработка №1

Добавлены часы реального времени DS3231, время отображается в режиме STANDBY

#define I2C_NTP3000 0x2A // Address chip | MONITOR_0 = GND 
#define GAIN    0x4D  // 10 - 126 КОЭФФИЦИЕНТ УСИЛЕНИЯ УСИЛИТЕЛЯ
 
#define CLK     9   //  ENCODER 
#define DT      8   //  ENCODER 
#define SW     10   //  ENCODER 

#define BRIG_H 200      // Яркость 0...255 POWER ON
#define BRIG_L 50       // Яркость 0...255 POWER OFF

#define IR_1 0x2FDD02F // Кнопка вверх
#define IR_2 0x2FD32CD // Кнопка вниз
#define IR_3 0x2FD906F // Кнопка >
#define IR_4 0x2FDF20D // Кнопка <
#define IR_5 0x2FD6A95 // Кнопка IN
#define IR_6 0x2FDEA15 // Кнопка MUTE
#define IR_7 0x2FD00FF // Кнопка STANDBY (POWER)

#include <Wire.h>
#include <EEPROM.h>
#include <MsTimer2.h>                    // http://rcl-radio.ru/wp-content/uploads/2018/11/MsTimer2.zip
#include <Encoder.h>                     // http://rcl-radio.ru/wp-content/uploads/2019/05/Encoder.zip
#include <LiquidCrystal_I2C.h>           // http://forum.rcl-radio.ru/misc.php?action=pan_download&item=45&download=1 
#include <boarddefs.h>                   // входит в состав библиотеки IRremote
#include <IRremote.h>                    // http://rcl-radio.ru/wp-content/uploads/2019/06/IRremote.zip 
#include <DS3231.h>                      // http://rcl-radio.ru/wp-content/uploads/2022/07/DS3231.zip
 Encoder myEnc(CLK, DT);
 LiquidCrystal_I2C lcd(0x27,16,2);  // Устанавливаем дисплей 
 IRrecv irrecv(12); // указываем вывод модуля IR приемника
 decode_results ir; 
 DS3231 clock;RTCDateTime DateTime;

 unsigned long times,times1,oldPosition  = -999,newPosition;
 byte i,d1,d2,d3,d4,d5,d6,e1,e2,e3;
 int menu,vol,a[3],in,qi,qq;
 byte w,w2,mute,m0=1,m1,aa[6];
 int q[7],qqq[7],ball,chl,chr,i1;  
 bool gr1,gr2,www,power;
 int hour,minut,secon,x;

void setup() {
  delay(500);Wire.begin();Serial.begin(9600);irrecv.enableIRIn();clock.begin();
//  clock.setDateTime(__DATE__, __TIME__); 
  MsTimer2::set(1, to_Timer);MsTimer2::start(); 
  if(EEPROM.read(100)!=0){for(int i=0;i<101;i++){EEPROM.update(i,0);}}// очистка памяти при первом включении 
  pinMode(2,OUTPUT); // RSEL0 PIN  CS8416
  pinMode(3,OUTPUT); // RSEL1 PIN  CS8416
  pinMode(4,OUTPUT); // RESET PIN  NTP3000
  pinMode(5,OUTPUT); // FAULT PIN  NTP3000
  digitalWrite(4,HIGH);delay(100);  // RESET NTP
  digitalWrite(4,LOW);delay(100);   // RESET NTP
  digitalWrite(4,HIGH);delay(100);  // RESET NTP
  pinMode(A0,INPUT_PULLUP); // MUTE
  pinMode(A1,INPUT_PULLUP); // INPUT
  pinMode(A2,INPUT_PULLUP); // POWER
  pinMode(6,OUTPUT);  // ВЫХОД УПРАВЛЕНИЯ ПОДСВЕТКОЙ
  analogWrite(6, BRIG_H);// больше 200 не делать
  vol = EEPROM.read(0);in = EEPROM.read(1);
  q[0] = EEPROM.read(2)-100;q[1] = EEPROM.read(3)-100;q[2] = EEPROM.read(4)-100;q[3] = EEPROM.read(5)-100;q[4] = EEPROM.read(6)-100;
  q[5] = EEPROM.read(7)-100;q[6] = EEPROM.read(8)-100;ball = EEPROM.read(9)-100;
  in_sw();
  init_ntp(); 
  Serial.println(wireRead(I2C_NTP3000,0x75),BIN); 
  digitalWrite(5,HIGH);delay(200);  // FAULT NTP
  lcd.init();lcd.backlight();
  lcd.setCursor(5,0);lcd.print("CS 8416");
  lcd.setCursor(5,1);lcd.print("NTP3000");
  delay(1000);lcd.clear(); 
}

void loop() {
   if ( irrecv.decode( &ir )) {Serial.print("0x");Serial.println( ir.value,HEX);irrecv.resume();times=millis();w=1;w2=1;}// IR приемник - чтение, в мониторе порта отображаются коды кнопок
   if(ir.value==0){gr1=0;gr2=0;}// запрет нажатий не активных кнопок пульта  
   
   if(m0==1){m0=0;
    byte v1[8] = {0x07,0x07,0x07,0x07,0x07,0x07,0x07,0x07};
    byte v2[8] = {0x07,0x07,0x00,0x00,0x00,0x00,0x00,0x00};      
    byte v3[8] = {0x00,0x00,0x00,0x00,0x00,0x00,0x1F,0x1F};
    byte v4[8] = {0x1F,0x1F,0x00,0x00,0x00,0x00,0x1F,0x1F};
    byte v5[8] = {0x1C,0x1C,0x00,0x00,0x00,0x00,0x1C,0x1C};
    byte v6[8] = {0x1C,0x1C,0x1C,0x1C,0x1C,0x1C,0x1C,0x1C};
    byte v7[8] = {0x00,0x00,0x00,0x00,0x00,0x00,0x07,0x07};
    byte v8[8] = {0x1F,0x1F,0x00,0x00,0x00,0x00,0x00,0x00};
    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(m1==1){m1=0;
    byte v1[8] = {0b00000, 0b00000, 0b00000, 0b00000, 0b00000, 0b00000, 0b00000, 0b01110};
    byte v2[8] = {0b00000, 0b00000, 0b00000, 0b00000, 0b00000, 0b00000, 0b01110, 0b01110};
    byte v3[8] = {0b00000, 0b00000, 0b00000, 0b00000, 0b00000, 0b01110, 0b01110, 0b01110};
    byte v4[8] = {0b00000, 0b00000, 0b00000, 0b00000, 0b01110, 0b01110, 0b01110, 0b01110};
    byte v5[8] = {0b00000, 0b00000, 0b00000, 0b01110, 0b01110, 0b01110, 0b01110, 0b01110};
    byte v6[8] = {0b00000, 0b00000, 0b01110, 0b01110, 0b01110, 0b01110, 0b01110, 0b01110};
    byte v7[8] = {0b00000, 0b01110, 0b01110, 0b01110, 0b01110, 0b01110, 0b01110, 0b01110};
    byte v8[8] = {0b01110, 0b01110, 0b01110, 0b01110, 0b01110, 0b01110, 0b01110, 0b01110};
    lcd.createChar(0, v1);lcd.createChar(1, v2);lcd.createChar(2, v3);lcd.createChar(3, v4);lcd.createChar(4, v5);lcd.createChar(5, v6);lcd.createChar(6, v7);lcd.createChar(7, v8);}

 if(power==0){
  /// MENU //////////////////////////////
  if(digitalRead(SW)==LOW){menu++;if(menu>2){menu=0;};switch(menu){case 0: m0=1;break;case 1: m1=1;break;case 2: m0=1;break;}delay(200);lcd.clear();w=1;w2=1;times=millis();w2=1;}
  if(ir.value==IR_1){menu++;gr1=0;gr2=0;cl1();times=millis();w=1;w2=1;if(menu>2){menu=0;};switch(menu){case 0: m0=1;break;case 1: m1=1;break;case 2: m0=1;break;}delay(200);lcd.clear();w=1;w2=1;times=millis();w2=1;}
  if(ir.value==IR_2){menu--;gr1=0;gr2=0;cl1();times=millis();w=1;w2=1;if(menu<0){menu=2;};switch(menu){case 0: m0=1;break;case 1: m1=1;break;case 2: m0=1;break;}delay(200);lcd.clear();w=1;w2=1;times=millis();w2=1;}
 
  /// INPUT ////////////////////////////
  if((digitalRead(A1)==LOW||ir.value==IR_5)&&menu!=1){in++;gr1=0;gr2=0;if(in>3){in=0;}menu=100;w=1;w2=1;times=millis();cl();lcd.setCursor(4,0);lcd.print("INPUT ");lcd.print(in+1);
  in_sw();
  delay(500);cl();menu=0;}
 
 /// MUTE //////////////////////////////
 if((digitalRead(A0)==LOW||ir.value==IR_6)&&mute==0){mute=1;gr1=0;gr2=0;menu=100;cl();wireWrite(I2C_NTP3000,0x20,0b00000111);lcd.setCursor(6,0);lcd.print("MUTE");}
 if((digitalRead(A0)==LOW||ir.value==IR_6)&&mute==1){mute=0;gr1=0;gr2=0;menu=0;m0=1;cl();wireWrite(I2C_NTP3000,0x20,0b00000000);w2=1;}  
  }
 /// POWER ///////////////////////////// 
  if((ir.value==IR_7||digitalRead(A2)==LOW)&&power==0){power=1;cl();lcd.setCursor(3,0);lcd.print("POWER  OFF");menu=100;m0=1;
    wireWrite(I2C_NTP3000,0x1F,0b00000111); // standby 
    delay(3000);analogWrite(6,BRIG_L);}// power off
  if((ir.value==IR_7||digitalRead(A2)==LOW)&&power==1){power=0;analogWrite(6, BRIG_H);cl();lcd.setCursor(3,0);lcd.print("POWER   ON ");
    w2=1;w=1;menu=0;m0=1;myEnc.write(0);
    wireWrite(I2C_NTP3000,0x1F,0b00000000);
    delay(3000);cl();}// power on

 
 /// VOLUME ///////////////////////////////////////////////////
 if(menu==0){
   if(ir.value==IR_3){vol++;gr1=1;gr2=0;cl1();times=millis();www=1;w=1;w2=1;if(vol>120){vol=120;}if(vol<28){vol=28;}}// кнопка > 
   if(ir.value==0xFFFFFFFF and gr1==1){vol++;gr2=0;cl1();times=millis();www=1;w=1;w2=1;if(vol>120){vol=120;}if(vol<28){vol=28;}}// кнопка >>>>>>
   if(ir.value==IR_4){vol--;gr1=0;gr2=1;cl1();times=millis();www=1;w=1;w2=1;if(vol>120){vol=120;}if(vol<28){vol=28;}}// кнопка <
   if(ir.value==0xFFFFFFFF and gr2==1){vol--;gr1=0;cl1();times=millis();www=1;w=1;w2=1;if(vol>120){vol=120;}if(vol<28){vol=28;}}// кнопка <<<<<<  
 
   if (newPosition != oldPosition){oldPosition = newPosition;
     vol=vol+newPosition;myEnc.write(0);newPosition=0;w=1;times=millis();w2=1;
     if(vol>120){vol=120;}if(vol<28){vol=28;}
     www=1;
     }
   if(www==1){www=0;
     wireWrite(I2C_NTP3000,0x2E,vol*2);// MASTER VOLUME 
     wireWrite(I2C_NTP3000,0x2F,vol*2+ball);// MASTER VOLUME CH1
     wireWrite(I2C_NTP3000,0x30,vol*2-ball);// MASTER VOLUME CH2
   }  
      lcd.setCursor(0,0);lcd.print("VOLUME ");
      lcd.setCursor(0,1);lcd.print("INPUT ");lcd.print(in+1);
 
  if(w2==1){w2=0;
     a[0]=(vol-28)/10;a[1]=(vol-28)%10;
       for(i=0;i<2;i++){
      switch(i){
        case 0: e1=9,e2=10,e3=11;break;
        case 1: e1=12,e2=13,e3=14;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);
 }} 
 }

// Equalizer /////////////////////////////////////
 if(menu==1){ 
   if(digitalRead(A1)==LOW||ir.value==IR_5){qi++;gr1=0;gr2=0;ir.value=0;if(qi>6){qi=0;}w=1;w2=1;delay(300);}
   switch(qi){
    case 0: qq=q[0];break;
    case 1: qq=q[1];break;
    case 2: qq=q[2];break;
    case 3: qq=q[3];break;
    case 4: qq=q[4];break;
    case 5: qq=q[5];break;
    case 6: qq=q[6];break;
    }
 
   if(ir.value==IR_3){qq++;gr1=1;gr2=0;cl1();times=millis();www=1;w=1;w2=1;if(qq>12){qq=12;}if(qq<-12){qq=-12;}}// кнопка > 
   if(ir.value==0xFFFFFFFF and gr1==1){qq++;gr2=0;cl1();times=millis();www=1;w=1;w2=1;if(qq>12){qq=12;}if(qq<-12){qq=-12;}}// кнопка >>>>>>
   if(ir.value==IR_4){qq--;gr1=0;gr2=1;cl1();times=millis();www=1;w=1;w2=1;if(qq>12){qq=12;}if(qq<-12){qq=-12;}}// кнопка <
   if(ir.value==0xFFFFFFFF and gr2==1){qq--;gr1=0;cl1();times=millis();www=1;w=1;w2=1;if(qq>12){qq=12;}if(qq<-12){qq=-12;}}// кнопка <<<<<<   
 
   if (newPosition != oldPosition){oldPosition = newPosition;
     qq=qq+newPosition;myEnc.write(0);newPosition=0;w=1;times=millis();w2=1;
     if(qq>12){qq=12;}if(qq<-12){qq=-12;}
     www=1;
     }
     if(www==1){www=0;
     q[qi]=qq;
     if(qq>=0){
    wireWrite(I2C_NTP3000,0x69,q[0]);// EQ 80 HZ
    wireWrite(I2C_NTP3000,0x32,q[1]);// EQ 220 HZ
    wireWrite(I2C_NTP3000,0x33,q[2]);// EQ 470 HZ
    wireWrite(I2C_NTP3000,0x36,q[3]);// EQ 1 KHZ
    wireWrite(I2C_NTP3000,0x34,q[4]);// EQ 2.2 KHZ
    wireWrite(I2C_NTP3000,0x35,q[5]);// EQ 4.7 KHZ
    wireWrite(I2C_NTP3000,0x6A,q[6]);// EQ 12.0 KHZ
     }
     if(qq<0){
    wireWrite(I2C_NTP3000,0x69,q[0]+32);// EQ 80 HZ
    wireWrite(I2C_NTP3000,0x32,q[1]+32);// EQ 220 HZ
    wireWrite(I2C_NTP3000,0x33,q[2]+32);// EQ 470 HZ
    wireWrite(I2C_NTP3000,0x36,q[3]+32);// EQ 1 KHZ
    wireWrite(I2C_NTP3000,0x34,q[4]+32);// EQ 2.2 KHZ
    wireWrite(I2C_NTP3000,0x35,q[5]+32);// EQ 4.7 KHZ
    wireWrite(I2C_NTP3000,0x6A,q[6]+32);// EQ 12.0 KHZ
     }}
 
  for (int pos = 0; pos < 7; pos++) {lcd.setCursor(pos, 0);
    qqq[pos] = map(q[pos],-12,12,0,15);
    if (qqq[pos] > 7){lcd.write((uint8_t)qqq[pos] - 8);lcd.setCursor(pos, 1);lcd.write((uint8_t)7);} 
    else {lcd.print(" ");lcd.setCursor(pos, 1);lcd.write((uint8_t)qqq[pos]);}}
    lcd.setCursor(8,0);lcd.print("F ");
    switch(qi){
      case 0: lcd.print("80  Hz");break;
      case 1: lcd.print("220 Hz");break;
      case 2: lcd.print("470 Hz");break;
      case 3: lcd.print("1.0kHz");break;
      case 4: lcd.print("2.2kHz");break;
      case 5: lcd.print("4.7kHz");break;
      case 6: lcd.print("12 kHz");break;
      }
    lcd.setCursor(8,1);lcd.print("G ");lcd.print(q[qi]);lcd.print(" dB  ");
 } 

//// EEPROM ///////////////////////////////////////
 if(millis()-times>10000 && w==1 && power==0){w=0;EEPROM.update(0,vol);EEPROM.update(1,in);
 EEPROM.update(2,q[0]+100);EEPROM.update(3,q[1]+100);EEPROM.update(4,q[2]+100);EEPROM.update(5,q[3]+100);EEPROM.update(6,q[4]+100);
 EEPROM.update(7,q[3]+100);EEPROM.update(8,q[4]+100);
 EEPROM.update(9,ball+100);
 menu=0;cl();m0=1;w2=1;
}

 //////// BALANCE /////////////////////////////////////////////////////////////// 
 if(menu==2){ 
   if(ir.value==IR_3){ball++;gr1=1;gr2=0;cl1();times=millis();www=1;w=1;w2=1;ball_fun();}// кнопка > 
   if(ir.value==0xFFFFFFFF and gr1==1){ball++;gr2=0;cl1();times=millis();www=1;w=1;w2=1;ball_fun();}// кнопка >>>>>>
   if(ir.value==IR_4){ball--;gr1=0;gr2=1;cl1();times=millis();www=1;w=1;w2=1;ball_fun();}// кнопка <
   if(ir.value==0xFFFFFFFF and gr2==1){ball--;gr1=0;cl1();times=millis();www=1;w=1;w2=1;ball_fun();}// кнопка <<<<<<  
 
   if (newPosition != oldPosition){oldPosition = newPosition;
   ball=ball-newPosition;myEnc.write(0);newPosition=0;times=millis();w=1;w2=1;ball_fun();www=1;
   }
   if(www==1){www=0;
     wireWrite(I2C_NTP3000,0x2E,vol*2);// MASTER VOLUME 
     wireWrite(I2C_NTP3000,0x2F,vol*2+ball);// MASTER VOLUME CH1
     wireWrite(I2C_NTP3000,0x30,vol*2-ball);// MASTER VOLUME CH2
   }
   lcd.setCursor(4,0);lcd.print(F("   <>   "));lcd.setCursor(4,1);lcd.print(F("CHL  CHR"));
   chl=(4+ball)-4;chr=(4-ball)-4;
   if(chl<0){lcd.setCursor(12,0);chl=abs(chl);lcd.write((uint8_t)3);}else{lcd.setCursor(12,0);lcd.print(" ");}
   if(chr<0){lcd.setCursor(0,0);chr=abs(chr);lcd.write((uint8_t)3);}else{lcd.setCursor(0,0);lcd.print(" ");}
   if(w2==1){w2=0;a[0]=chl;a[1]=chr;
   for(i1=0;i1<2;i1++){
      switch(i1){
        case 0: e1=1,e2=2,e3=3;break;
        case 1: e1=13,e2=14,e3=15;break;
        }
      switch(a[i1]){
        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);
 }}}  

/////////////////// ЧАСЫ ///////////////////////////////////////////////////////////////////
DateTime = clock.getDateTime();hour = DateTime.hour;minut = DateTime.minute;secon = DateTime.second;   
if(power==1){
     aa[0]=DateTime.hour/10;
     aa[1]=DateTime.hour%10;
     aa[2]=DateTime.minute/10;
     aa[3]=DateTime.minute%10;
     aa[4]=DateTime.second/10;
     aa[5]=DateTime.second%10;
   for(x=0;x<4;x++){
    switch(x){
        case 0: e1=0,e2=1,e3=2;break;
        case 1: e1=3,e2=4,e3=5;break;
        case 2: e1=7,e2=8,e3=9;break;
        case 3: e1=10,e2=11,e3=12;break;
   }digit();}
 
   lcd.setCursor(6,0);lcd.print(".");lcd.setCursor(6,1);lcd.print(".");
   lcd.setCursor(14,1);lcd.print(aa[4]);lcd.setCursor(15,1);lcd.print(aa[5]);   
//// set time ////
   if(digitalRead(10)==LOW&&digitalRead(A0)==LOW){hour++;if(hour>23){hour=0;} clock.setDateTime(2023, 1, 14, hour, minut, secon);delay(200);}// MUTE button HH++
   if(digitalRead(10)==LOW&&digitalRead(A1)==LOW){minut++;if(minut>59){minut=0;} clock.setDateTime(2023, 1, 14, hour, minut, secon);delay(200);}// INPUT button MM++
   if(digitalRead(10)==LOW&&digitalRead(A2)==LOW){clock.setDateTime(2023, 1, 14, hour, minut, 0);delay(200);}// POWER button SS clear
}     
 
} // end loop


void init_ntp(){ 
    wireWrite(I2C_NTP3000,0x00,0b00011100);// I2S, slave mode|192kHz
    wireWrite(I2C_NTP3000,0x01,0b00000000);// 24 bit, 64 BCK/WCK
    wireWrite(I2C_NTP3000,0x02,0b00000010);// 18.432 MHz
    wireWrite(I2C_NTP3000,0x03,0b00000000);// AD MODE ASIN
    wireWrite(I2C_NTP3000,0x04,0);// AUTO MUTE OFF 1-2CH
    wireWrite(I2C_NTP3000,0x05,0);// AUTO MUTE OFF 3CH
    wireWrite(I2C_NTP3000,0x06,0b00101110);// EQ USER DEFINED
    wireWrite(I2C_NTP3000,0x07,0);// ACL CONF_1
    wireWrite(I2C_NTP3000,0x08,0);// ACL CONF_2
    wireWrite(I2C_NTP3000,0x09,0);// ACL CONF_3
    wireWrite(I2C_NTP3000,0x0A,0b00000111);// MASTER VOL OVERRIDE
    wireWrite(I2C_NTP3000,0x0B,0b00001000);// PWM 1A&1B
    wireWrite(I2C_NTP3000,0x0C,0b00011010);// PWM 2A&2B
    wireWrite(I2C_NTP3000,0x0D,0b00101100);// PWM 3A&3B
    wireWrite(I2C_NTP3000,0x0E,0);// DRC CONTR CH1-2
    wireWrite(I2C_NTP3000,0x0F,0);// DRC CONTR CH3
    wireWrite(I2C_NTP3000,0x10,0);// DRC CONFIG
    wireWrite(I2C_NTP3000,0x11,0b01110000);// NS-TUPE DEF
    wireWrite(I2C_NTP3000,0x12,100);// PRESCALER CONRT CH1-2 DEF
    wireWrite(I2C_NTP3000,0x13,0);// PRESCALER CONTR CH3
   
    wireWrite(I2C_NTP3000,0x17,0);// AOUT RISING EDGE DELAY DEF
    wireWrite(I2C_NTP3000,0x18,0);// AOUT FALLING EDGE DELAY DEF
    wireWrite(I2C_NTP3000,0x19,0);// BOUT RISING EDGE DELAY
    wireWrite(I2C_NTP3000,0x1A,0);// BOUT FALLING EDGE DELAY
    wireWrite(I2C_NTP3000,0x1B,0b10101000);// PWM OFF & AUTO PROTECT CONTR DEF
    wireWrite(I2C_NTP3000,0x1C,0);// AUTO PROTECT CONF CONTROL MASKING
    wireWrite(I2C_NTP3000,0x1D,0);// PROTECT CONTROL DEF
    wireWrite(I2C_NTP3000,0x1E,0b00000000);// PROTECT CONTROL DEF
    wireWrite(I2C_NTP3000,0x1F,0b00000000);// SWITCHING OFF !!!!!
    
    wireWrite(I2C_NTP3000,0x20,0b00000000);// SOFTMUTE !!!!
    wireWrite(I2C_NTP3000,0x2C,0b00111111);// FBQ_FLAG CH1-2-3 DEF
    wireWrite(I2C_NTP3000,0x2D,0b00000001);// MASTER FINE VOLUME DEF
    wireWrite(I2C_NTP3000,0x2E,vol*2);// MASTER VOLUME 
    wireWrite(I2C_NTP3000,0x2F,vol*2+ball);// MASTER VOLUME CH1
    wireWrite(I2C_NTP3000,0x30,vol*2-ball);// MASTER VOLUME CH2
    wireWrite(I2C_NTP3000,0x31,0);// MASTER VOLUME CH3   

    if(q[0]>=0){wireWrite(I2C_NTP3000,0x69,q[0]);}else{wireWrite(I2C_NTP3000,0x69,q[0]+32);} // EQ 80 HZ
    if(q[1]>=0){wireWrite(I2C_NTP3000,0x32,q[2]);}else{wireWrite(I2C_NTP3000,0x32,q[1]+32);} // EQ 220 HZ
    if(q[2]>=0){wireWrite(I2C_NTP3000,0x33,q[3]);}else{wireWrite(I2C_NTP3000,0x33,q[2]+32);} // EQ 470 HZ
    if(q[3]>=0){wireWrite(I2C_NTP3000,0x36,q[4]);}else{wireWrite(I2C_NTP3000,0x36,q[3]+32);} // EQ 1 KHZ
    if(q[4]>=0){wireWrite(I2C_NTP3000,0x34,q[5]);}else{wireWrite(I2C_NTP3000,0x34,q[4]+32);} // EQ 2.2 KHZ
    if(q[5]>=0){wireWrite(I2C_NTP3000,0x35,q[6]);}else{wireWrite(I2C_NTP3000,0x35,q[5]+32);} // EQ 4.7 KHZ
    if(q[6]>=0){wireWrite(I2C_NTP3000,0x6A,q[1]);}else{wireWrite(I2C_NTP3000,0x6A,q[6]+32);} // EQ 12.0 KHZ
    
    wireWrite(I2C_NTP3000,0x37,GAIN);// MIXER GAIN
    wireWrite(I2C_NTP3000,0x38,GAIN);// MIXER GAIN
    wireWrite(I2C_NTP3000,0x39,GAIN);// MIXER GAIN
    wireWrite(I2C_NTP3000,0x3A,GAIN);// MIXER GAIN
    wireWrite(I2C_NTP3000,0x3B,0);// MIXER GAIN
    wireWrite(I2C_NTP3000,0x3C,0);// MIXER GAIN
    wireWrite(I2C_NTP3000,0x3D,0);// Back Biquad Filter Conf Ch1-2 DEF
    wireWrite(I2C_NTP3000,0x3E,0);// Back Biquad Filter Conf Ch1-2 DEF
    wireWrite(I2C_NTP3000,0x3F,0);// Biquad Filter Coefficient DEF 
    
    wireWrite(I2C_NTP3000,0x60,40);// 3D DELAY
    wireWrite(I2C_NTP3000,0x61,0);// 3D EFFECT
    wireWrite(I2C_NTP3000,0x62,0b00000010);// PWM 2.0 CH
    wireWrite(I2C_NTP3000,0x63,0b00000001);// STANDBY  
  }

void ball_fun(){if(ball>8){ball=8;}if(ball<-8){ball=-8;}}
void cl(){ir.value=0;delay(300);lcd.clear();}
void cl1(){ir.value=0;delay(200);} 

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

void in_sw(){
  switch(in){
    case 0: digitalWrite(2,LOW);digitalWrite(3,LOW);break;
    case 1: digitalWrite(2,HIGH);digitalWrite(3,LOW);break;
    case 2: digitalWrite(2,LOW);digitalWrite(3,HIGH);break;
    case 3: digitalWrite(2,HIGH);digitalWrite(3,HIGH);break;
    }} 

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

void digit(){switch(aa[x]){
case 0: d1=1,d2=8,d3=6,d4=1,d5=3,d6=6;break;case 1: d1=32,d2=2,d3=6,d4=32,d5=32,d6=6;break;
case 2: d1=2,d2=8,d3=6,d4=1,d5=4,d6=5;break;case 3: d1=2,d2=4,d3=6,d4=7,d5=3,d6=6;break;
case 4: d1=1,d2=3,d3=6,d4=32,d5=32,d6=6;break;case 5: d1=1,d2=4,d3=5,d4=7,d5=3,d6=6;break;
case 6: d1=1,d2=4,d3=5,d4=1,d5=3,d6=6;break;case 7: d1=1,d2=8,d3=6,d4=32,d5=32,d6=6;break;
case 8: d1=1,d2=4,d3=6,d4=1,d5=3,d6=6;break;case 9: d1=1,d2=4,d3=6,d4=7,d5=3,d6=6;break;}
lcd.setCursor(e1,0);lcd.write((uint8_t)d1);lcd.setCursor(e2,0);lcd.write((uint8_t)d2);lcd.setCursor(e3,0);lcd.write((uint8_t)d3);
lcd.setCursor(e1,1);lcd.write((uint8_t)d4);lcd.setCursor(e2,1);lcd.write((uint8_t)d5);lcd.setCursor(e3,1);lcd.write((uint8_t)d6);}