1

Тема: PT2314 - регулировка громкости и тембра при помощи потенциометров

http://forum.rcl-radio.ru/uploads/images/2020/03/a5ad4d7a1914354b8b31044077dcddc0.png

пробный скетч - не тестировался!!!

http://forum.rcl-radio.ru/uploads/images/2020/03/ff773f40de2df7424fd52f6c27dbe2c7.png

При коротком нажатии кнопки ST-BY/MUTE срабатывает MUTE, при удержании кнопки STANDBY

#include <Wire.h> 
#include <PT2314.h>  // http://forum.rcl-radio.ru/misc.php?action=pan_download&item=434&download=1
#include <LiquidCrystal_I2C.h> // http://forum.rcl-radio.ru/misc.php?action=pan_download&item=45&download=1
#include <EEPROM.h>
   PT2314 pt;
   LiquidCrystal_I2C lcd(0x27,16,2);  // Устанавливаем дисплей

   int vol,bass,treb,vol_old,bass_old,treb_old,in,menu;
   byte power,mute,save,pin;
   unsigned long time0,w;

void setup(){Serial.begin(9600);
  lcd.init();lcd.backlight();
  pinMode(A0,INPUT);    // VOLUME
  pinMode(A1,INPUT);    // BASS
  pinMode(A2,INPUT);    // TREBLE
  pinMode(9,INPUT);     // MUTE / STANDBY
  pinMode(10,INPUT);    // IN
  pinMode(8,INPUT);     // STANDBY OUTPUT
  in = EEPROM.read(3);
  }

void loop(){
////////////// mute power 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);menu=100;cl();menu=1000;;lcd.setCursor(6,0);lcd.print("MUTE");delay(1000);}// mute on
  if((pin>0&&pin<10&&digitalRead(9)==LOW)&&mute==1&&power==0){pin=0;mute=0;cl();time0=millis();w=1;menu=0;audio();}// mute off

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

  if(mute==0&&power==0&&digitalRead(10)==HIGH){in++;in_func();cl();w=1;lcd.setCursor(4,0);lcd.print("INPUT ");lcd.print(in+1);delay(1000);}
  if(power==0){digitalWrite(8,HIGH);}else{digitalWrite(8,LOW);}
////////////////////////////////////////////
  
  vol_old = vol;
  bass_old = bass;
  treb_old = treb;
  
  vol = map(analogRead(A0),0,1023,0,57);
  bass = map(analogRead(A1),0,1023,-7,8);
  treb = map(analogRead(A2),0,1023,-7,8);
  
  if(menu==0&&(vol_old!=vol||bass_old!=bass||treb_old!=treb||w==1)){w=0;audio();
  lcd.setCursor(0,0);lcd.print("VOLUME ");lcd.print(vol);lcd.print("  ");
  lcd.setCursor(10,0);lcd.print("INPUT");lcd.print(in+1);
  lcd.setCursor(10,1);lcd.print("BASS ");if(bass<0){lcd.setCursor(14,1);}else{lcd.setCursor(15,1);}lcd.print(bass);lcd.print(" ");
  lcd.setCursor(0,1);lcd.print("TREBLE ");if(treb<0){lcd.setCursor(6,1);}else{lcd.setCursor(7,1);}lcd.print(treb);lcd.print(" ");
  
  }
  delay(100);
  /////////////////// eeprom ////////////////////////
  if(save==1){save=0;EEPROM.update(3,in);}
  ///////////////////////////////////////////////////
  }// loop  

void in_func(){if(in>3){in=0;}}
void cl(){delay(300);lcd.clear();}
void audio(){
  pt.setVolume(vol); // int 0...56 === -70...0 dB step 1.25 dB
  pt.setAttL(0); // int 0...24 === 0...-30 db step 1.25 dB > int 31 === mute on     
  pt.setAttR(0); // int 0...24 === 0...-30 dB step 1.25 dB > int 31 === mute on
  pt.setSwitch(in, 0, 0); 
        // 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
  }

2

Re: PT2314 - регулировка громкости и тембра при помощи потенциометров

Без дисплея, только светодиоды.

Скетч нуждается  в тестировании!!!

http://forum.rcl-radio.ru/uploads/images/2020/03/2cd6c371ac10fcacccc0058231671337.png

При коротком нажатии кнопки ST-BY/MUTE срабатывает MUTE, при удержании кнопки STANDBY

#include <Wire.h> 
#include <PT2314.h>  // http://forum.rcl-radio.ru/misc.php?action=pan_download&item=434&download=1
#include <EEPROM.h>
   PT2314 pt;

   int vol,bass,treb,vol_old,bass_old,treb_old,in,menu;
   byte power,mute,save,pin;
   unsigned long time0,w,w1;

void setup(){
  pinMode(A0,INPUT);// VOLUME
  pinMode(A1,INPUT);// BASS
  pinMode(A2,INPUT);// TREBLE
  pinMode(9,INPUT);// MUTE / STANDBY
  pinMode(10,INPUT);// IN
  pinMode(8,INPUT);// STANDBY OUTPUT
  pinMode(2,OUTPUT);// LED IN1
  pinMode(3,OUTPUT);// LED IN2
  pinMode(4,OUTPUT);// LED IN3
  pinMode(5,OUTPUT);// LED IN4
  pinMode(7,OUTPUT);// LED POWER
  pinMode(11,OUTPUT);// LED MUTE
  in = EEPROM.read(3);
  audio();
  }

void loop(){
////////////// mute power 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);menu=100;digitalWrite(11,HIGH);delay(200);}// mute on
  if((pin>0&&pin<10&&digitalRead(9)==LOW)&&mute==1&&power==0){pin=0;mute=0;digitalWrite(11,LOW);audio();delay(200);}// mute off

  if((pin>10)&&power==0){pin=0;power=1;save=1;pt.setAttR(31);pt.setAttL(31);digitalWrite(7,LOW);digitalWrite(2,LOW);digitalWrite(3,LOW);digitalWrite(4,LOW);digitalWrite(5,LOW);delay(1000);}// power off
  if((pin>0)&&power==1){pin=0;power=0;digitalWrite(7,HIGH);audio();delay(200);}// power on

  if(mute==0&&power==0&&digitalRead(10)==HIGH){in++;in_func();}
  switch(in){
    case 0 : digitalWrite(2,HIGH);digitalWrite(3,LOW);digitalWrite(4,LOW);digitalWrite(5,LOW);break;
    case 1 : digitalWrite(2,LOW);digitalWrite(3,HIGH);digitalWrite(4,LOW);digitalWrite(5,LOW);break;
    case 2 : digitalWrite(2,LOW);digitalWrite(3,LOW);digitalWrite(4,HIGH);digitalWrite(5,LOW);break;
    case 3 : digitalWrite(2,LOW);digitalWrite(3,LOW);digitalWrite(4,LOW);digitalWrite(5,HIGH);break;
    }
  
  if(power==0){digitalWrite(8,HIGH);}else{digitalWrite(8,LOW);}
////////////////////////////////////////////
  
  vol_old = vol;
  bass_old = bass;
  treb_old = treb;
  
  vol = map(analogRead(A0),0,1023,0,57);
  bass = map(analogRead(A1),0,1023,-7,8);
  treb = map(analogRead(A2),0,1023,-7,8);

  if(vol_old!=vol||bass_old!=bass||treb_old!=treb||w==1){w=0;audio();delay(100);}

  /////////////////// eeprom ////////////////////////
  if(save==1){save=0;EEPROM.update(3,in);}
  ///////////////////////////////////////////////////
  }// loop  

void in_func(){if(in>3){in=0;}}
void audio(){
  pt.setVolume(vol); // int 0...56 === -70...0 dB step 1.25 dB
  pt.setAttL(0); // int 0...24 === 0...-30 db step 1.25 dB > int 31 === mute on     
  pt.setAttR(0); // int 0...24 === 0...-30 dB step 1.25 dB > int 31 === mute on
  pt.setSwitch(in, 0, 0); 
        // 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
  }