1

Тема: PT2033

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

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

PT2033.h

// liman324@yandex.ru rcl-radio.ru


#ifndef PT2033_H
#define PT2033_H

#define PT2033_address 0b1000100


#include <Arduino.h>
class PT2033
{
  public:
    PT2033();
        void setVolume(int vol); //  int 0...63     
    void setAttL(int att_l); //  int 0...31       
    void setAttR(int att_r); //  int 0...31     
        void setAttS(int att_s); //  int 0...31
        void setIn(int in, int loud, int loud_gain);   
         // int 0...3, int 0...1, int 0...3
        void setBass(int bass); // -7...+7
        void setTreble(int treb); //  -7...+7
    
  private:
    void writeWire(char a);
};
    
#endif //PT2033_H

PT2033.cpp

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

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

void PT2033::setVolume(int vol){
  vol = 63 - vol;
  writeWire(vol);
}

void PT2033::setAttL(int att_l){
  att_l = 0b11000000 + att_l;
  writeWire(att_l);
}

void PT2033::setAttR(int att_r){
  att_r = 0b11100000 + att_r;
  writeWire(att_r);
}

void PT2033::setAttS(int att_s){
  att_s = 0b10000000 + att_s;
  writeWire(att_s);
}

void PT2033::setIn(int in, int loud, int loud_gain){
  switch (in){
    case 0:in = 0b00000000;break;
    case 1:in = 0b00000001;break;
    case 2:in = 0b00000010;break;
    case 3:in = 0b00000011;break;
  }
  switch (loud){
    case 1:loud = 0b00000000;break;
    case 0:loud = 0b00000100;break;
  }
  switch (loud_gain){
    case 0:loud_gain = 0b00000000;break;
    case 1:loud_gain = 0b00001000;break;
    case 2:loud_gain = 0b00010000;break;
    case 3:loud_gain = 0b00011000;break; 
  }
  int sw = 0b01000000 + in + loud + loud_gain;
  writeWire(sw);
}

void PT2033::setBass(int bass){
  switch (bass){
    case -7: bass = 0b01100000;break;
    case -6: bass = 0b01100001;break;
    case -5: bass = 0b01100010;break;
    case -4: bass = 0b01100011;break; 
    case -3: bass = 0b01100100;break;
    case -2: bass = 0b01100101;break;
    case -1: bass = 0b01100110;break;
    case 0:  bass = 0b01100111;break;
    case 1:  bass = 0b01101110;break;
    case 2:  bass = 0b01101101;break;
    case 3:  bass = 0b01101100;break;
    case 4:  bass = 0b01101011;break;
    case 5:  bass = 0b01101010;break;
    case 6:  bass = 0b01101001;break;
    case 7:  bass = 0b01101000;break;
  }
  writeWire(bass);
}

void PT2033::setTreble(int treb){
  switch (treb){
    case -7: treb = 0b01110000;break;
    case -6: treb = 0b01110001;break;
    case -5: treb = 0b01110010;break;
    case -4: treb = 0b01110011;break; 
    case -3: treb = 0b01110100;break;
    case -2: treb = 0b01110101;break;
    case -1: treb = 0b01110110;break;
    case 0:  treb = 0b01111111;break;
    case 1:  treb = 0b01111110;break;
    case 2:  treb = 0b01111101;break;
    case 3:  treb = 0b01111100;break;
    case 4:  treb = 0b01111011;break;
    case 5:  treb = 0b01111010;break;
    case 6:  treb = 0b01111001;break;
    case 7:  treb = 0b01111000;break;
  }
  writeWire(treb);
}

void PT2033::writeWire(char a){
  Wire.beginTransmission(PT2033_address);
  Wire.write (a);
  Wire.endTransmission();
}

test.ino

#include <Wire.h>
#include <PT2033.h>
  PT2033 pt;
  
void setup(){ 
  Serial.begin(9600);Wire.begin();
  audio();
}

void loop(){}

void audio(){
  pt.setVolume(55);  // громкость 0...63       
  pt.setAttL(0);     // аттенюатор L 0...31     
  pt.setAttR(0);     // аттенюатор R 0...31
  pt.setAttS(0);    // аттенюатор S 0...31

  pt.setIn(0,0,0); // вход 0...3, тонкомпенсация 1 вкл 0 выкл, усиление 0...3
  pt.setBass(0);       // тембр НЧ -7...+7
  pt.setTreble(0);     // тембр ВЧ -7...+7
}

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

2

Re: PT2033

http://forum.rcl-radio.ru/uploads/images/2019/12/3000d3423d3d462e121f57a1fd56d9bb.png

http://forum.rcl-radio.ru/uploads/images/2019/12/ed0b3e6d6f793ab176f9f22d1e674f02.png

http://forum.rcl-radio.ru/uploads/images/2019/12/4b1db89682c35aecbbe92285dd46f8dc.png

http://forum.rcl-radio.ru/uploads/images/2019/12/df1202b4034a8c05bd431ffc788196fd.png

http://forum.rcl-radio.ru/uploads/images/2019/12/26267d193ab71907d7b7c3d17919b352.png

http://forum.rcl-radio.ru/uploads/images/2019/12/da708241ff6a3deb1f7ba688343c4d24.png

http://forum.rcl-radio.ru/uploads/images/2019/12/20b426fa460cb25aa295333b5216ec93.png

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

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


void setup(){
  Wire.begin();lcd.init();lcd.backlight();
  irrecv.enableIRIn();
  lcd.setCursor(0,0);lcd.print("     PT2033     ");delay(2000);
  Serial.begin(9600); lcd.createChar(0,a1);lcd.createChar(1,a2);lcd.createChar(2,a3);
   pinMode(10,INPUT);  // МЕНЮ КНОПКА SW энкодера
   pinMode(2,INPUT);   // ВЫБОР ВХОДА КНОПКА IN
   MsTimer2::set(3, to_Timer);MsTimer2::start();
   if(EEPROM.read(100)!=0){for(int i=0;i<101;i++){EEPROM.update(i,0);}}// очистка памяти при первом включении 
   vol = EEPROM.read(0);bass = EEPROM.read(1)-7;treb = EEPROM.read(2)-7;in = EEPROM.read(3);loud = EEPROM.read(4);attl = EEPROM.read(5);attr = EEPROM.read(6);atts = EEPROM.read(7);
   cl();audio();
}
void loop(){
   if(digitalRead(10)==LOW){menu++;cl();eep();if(menu>6){menu=0;}}// меню
   if(digitalRead(2)==HIGH){in++;;cl();eep();if(in>3){in=0;};lcd.setCursor(0,0);lcd.print("    INPUT ");lcd.print(in+1);audio();delay(2000);}// КНОПКА ВЫБОРА ВХОДА IN

  ////////////////////// IR /////////////////////////////////////////////////
  if ( irrecv.decode( &ir )) {Serial.print("0x");Serial.println( ir.value,HEX);irrecv.resume();eep();}// IR приемник - чтение, в мониторе порта отображаются коды кнопок
  if(ir.value==0){gr1=0;gr2=0;}// запрет нажатий не активных кнопок пульта
  
  if(ir.value==IR_1){menu++;gr1=0;gr2=0;cl();eep();if(menu>6){menu=0;}}// меню кнопка вверх 
  if(ir.value==IR_2){menu--;gr1=0;gr2=0;cl();eep();if(menu<0){menu=6;}}// меню кнопка вниз
  
  if(ir.value==IR_5){in++;gr1=0;gr2=0;cl();eep();if(in>3){in=0;};lcd.setCursor(0,0);lcd.print("    INPUT ");lcd.print(in+1);audio();delay(2000);}// КНОПКА ВЫБОРА ВХОДА IN
  
  /////////////////////////////// VOLUME 0...63  ////////////////////////////////////////////////
 if(menu==0){
     if(ir.value==IR_3){vol++;gr1=1;gr2=0;cl1();eep();vol_func();audio();}// кнопка > 
     if(ir.value==0xFFFFFFFF and gr1==1){vol++;gr2=0;cl1();eep();vol_func();audio();}// кнопка >>>>>>
     if(ir.value==IR_4){vol--;gr1=0;gr2=1;cl1();eep();vol_func();audio();}// кнопка <
     if(ir.value==0xFFFFFFFF and gr2==1){vol--;gr1=0;cl1();eep();vol_func();audio();}// кнопка <<<<<<
   
   if (newPosition != oldPosition){oldPosition = newPosition;
     vol=vol+newPosition;myEnc.write(0);newPosition=0;eep();vol_func();audio();} 
     lcd.setCursor(0,0);lcd.print("VOLUME     ");lcd.print(vol);vol_d=vol-15;
   if(w2==1){
   for(z=0,z0=0,z1=0;z<=vol_d;z++,z1++){if(z1>2){z1=0;z0++;}
   if(z1==1){lcd.setCursor(z0,1);lcd.write((uint8_t)0);lcd.setCursor(z0+1,1);lcd.print("   ");}}
   if(z1==3){lcd.setCursor(z0,1);lcd.write((uint8_t)1);}
   if(z1==2){lcd.setCursor(z0,1);lcd.write((uint8_t)2);}w2=0;}}

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

/////////////////////// TREBLE +/-14 dB ///////////////////////////////////////////////////////////
   if(menu==2){
     if(ir.value==IR_3){treb++;gr1=1;gr2=0;cl1();eep();treb_func();audio();}// кнопка > 
     if(ir.value==0xFFFFFFFF and gr1==1){treb++;gr2=0;cl1();eep();treb_func();audio();}// кнопка >>>>>>
     if(ir.value==IR_4){treb--;gr1=0;gr2=1;cl1();eep();treb_func();audio();}// кнопка < 
     if(ir.value==0xFFFFFFFF and gr2==1){treb--;gr1=0;cl1();eep();treb_func();audio();}// кнопка <<<<<<  
    
    if (newPosition != oldPosition) {
    oldPosition = newPosition;
    treb=treb+newPosition;myEnc.write(0);newPosition=0;eep();treb_func();audio();} 
   lcd.setCursor(0,0);lcd.print("TREBLE  ");
   lcd.print(" ");lcd.print(treb*2);lcd.print(" ");lcd.setCursor(13,0);lcd.print("dB");treb_d=treb*2+14;
   if(w2==1){
   for(z=0,z0=0,z1=0;z<=treb_d;z++,z1++){if(z1>2){z1=0;z0++;}
   if(z1==1){lcd.setCursor(z0+3,1);lcd.write((uint8_t)0);lcd.setCursor(z0+1+3,1);lcd.print("   ");}}
   if(z1==3){lcd.setCursor(z0+3,1);lcd.write((uint8_t)1);}
   if(z1==2){lcd.setCursor(z0+3,1);lcd.write((uint8_t)2);}w2=0;}}   
 
 ///////////////////////// LOUDNESS ////////////////////////////////////////////////////////  
 if(menu==3){ 
     if(ir.value==IR_3){loud++;gr1=1;gr2=0;cl1();eep();loud_func();audio();}// кнопка > 
     if(ir.value==0xFFFFFFFF and gr1==1){loud++;gr2=0;cl1();eep();loud_func();audio();}// кнопка >>>>>>
     if(ir.value==IR_4){loud--;gr1=0;gr2=1;cl1();eep();loud_func();audio();}// кнопка < 
     if(ir.value==0xFFFFFFFF and gr2==1){loud--;gr1=0;cl1();eep();loud_func();audio();}// кнопка <<<<<<  
     
      if (newPosition != oldPosition) {
      oldPosition = newPosition;
      loud=loud+newPosition;myEnc.write(0);newPosition=0;eep();loud_func();audio();}   
    lcd.setCursor(0,0);lcd.print("LOUDNESS   ");lcd.print(loud);
    if(loud>0){loud_off=1;lcd.setCursor(0,1);lcd.print("ON ");}else{loud_off=0;lcd.setCursor(0,1);lcd.print("OFF");}}

  /////////////////////////////// ATT L 0...31  ////////////////////////////////////////////////
 if(menu==4){
     if(ir.value==IR_3){attl++;gr1=1;gr2=0;cl1();eep();attl_func();audio();}// кнопка > 
     if(ir.value==0xFFFFFFFF and gr1==1){attl++;gr2=0;cl1();eep();attl_func();audio();}// кнопка >>>>>>
     if(ir.value==IR_4){attl--;gr1=0;gr2=1;cl1();eep();attl_func();audio();}// кнопка <
     if(ir.value==0xFFFFFFFF and gr2==1){attl--;gr1=0;cl1();eep();attl_func();audio();}// кнопка <<<<<<
   
   if (newPosition != oldPosition){oldPosition = newPosition;
     attl=attl+newPosition;myEnc.write(0);newPosition=0;eep();attl_func();audio();} 
     lcd.setCursor(0,0);lcd.print("ATT L    ");lcd.print(attl);lcd.print("   ");
   if(w2==1){
   for(z=0,z0=0,z1=0;z<=attl;z++,z1++){if(z1>2){z1=0;z0++;}
   if(z1==1){lcd.setCursor(z0+3,1);lcd.write((uint8_t)0);lcd.setCursor(z0+1+3,1);lcd.print("   ");}}
   if(z1==3){lcd.setCursor(z0+3,1);lcd.write((uint8_t)1);}
   if(z1==2){lcd.setCursor(z0+3,1);lcd.write((uint8_t)2);}w2=0;}}   
    
   /////////////////////////////// ATT R 0...31  ////////////////////////////////////////////////
 if(menu==5){
     if(ir.value==IR_3){attr++;gr1=1;gr2=0;cl1();eep();attr_func();audio();}// кнопка > 
     if(ir.value==0xFFFFFFFF and gr1==1){attr++;gr2=0;cl1();eep();attr_func();audio();}// кнопка >>>>>>
     if(ir.value==IR_4){attr--;gr1=0;gr2=1;cl1();eep();attr_func();audio();}// кнопка <
     if(ir.value==0xFFFFFFFF and gr2==1){attr--;gr1=0;cl1();eep();attr_func();audio();}// кнопка <<<<<<
   
   if (newPosition != oldPosition){oldPosition = newPosition;
     attr=attr+newPosition;myEnc.write(0);newPosition=0;eep();attr_func();audio();} 
     lcd.setCursor(0,0);lcd.print("ATT R    ");lcd.print(attr);lcd.print("   ");
   if(w2==1){
   for(z=0,z0=0,z1=0;z<=attr;z++,z1++){if(z1>2){z1=0;z0++;}
   if(z1==1){lcd.setCursor(z0+3,1);lcd.write((uint8_t)0);lcd.setCursor(z0+1+3,1);lcd.print("   ");}}
   if(z1==3){lcd.setCursor(z0+3,1);lcd.write((uint8_t)1);}
   if(z1==2){lcd.setCursor(z0+3,1);lcd.write((uint8_t)2);}w2=0;}} 

   /////////////////////////////// ATT S 0...31  ////////////////////////////////////////////////
 if(menu==6){
     if(ir.value==IR_3){atts++;gr1=1;gr2=0;cl1();eep();atts_func();audio();}// кнопка > 
     if(ir.value==0xFFFFFFFF and gr1==1){atts++;gr2=0;cl1();eep();atts_func();audio();}// кнопка >>>>>>
     if(ir.value==IR_4){atts--;gr1=0;gr2=1;cl1();eep();atts_func();audio();}// кнопка <
     if(ir.value==0xFFFFFFFF and gr2==1){atts--;gr1=0;cl1();eep();atts_func();audio();}// кнопка <<<<<<
   
   if (newPosition != oldPosition){oldPosition = newPosition;
     atts=atts+newPosition;myEnc.write(0);newPosition=0;eep();atts_func();audio();} 
     lcd.setCursor(0,0);lcd.print("ATT SUB  ");lcd.print(atts);lcd.print("   ");
   if(w2==1){
   for(z=0,z0=0,z1=0;z<=atts;z++,z1++){if(z1>2){z1=0;z0++;}
   if(z1==1){lcd.setCursor(z0+3,1);lcd.write((uint8_t)0);lcd.setCursor(z0+1+3,1);lcd.print("   ");}}
   if(z1==3){lcd.setCursor(z0+3,1);lcd.write((uint8_t)1);}
   if(z1==2){lcd.setCursor(z0+3,1);lcd.write((uint8_t)2);}w2=0;}}     

 ///////////////////// EEPROM ///////////////////////////////////////////////////////////////         
  if(millis()-time>10000 && w==1){
     EEPROM.update(0,vol);EEPROM.update(1,bass+7);EEPROM.update(2,treb+7);EEPROM.update(3,in);EEPROM.update(4,loud);EEPROM.update(5,attl);EEPROM.update(6,attr);EEPROM.update(7,atts);
     menu=0;w=0;w2=1;cl();}

  }//loop

void atts_func(){if(atts>30){atts=30;}if(atts<0){atts=0;}}
void attr_func(){if(attr>30){attr=30;}if(attr<0){attr=0;}}
void attl_func(){if(attl>30){attl=30;}if(attl<0){attl=0;}}
void loud_func(){if(loud>3){loud=3;}if(loud<0){loud=0;}};
void bass_func(){if(bass>7){bass=7;}if(bass<-7){bass=-7;}}
void treb_func(){if(treb>7){treb=7;}if(treb<-7){treb=-7;}}
void eep(){newPosition=0;time=millis();w=1;w2=1;}
void vol_func(){if(vol>63){vol=63;}if(vol<0){vol=0;}}
void cl(){ir.value=0;delay(300);lcd.clear();}
void cl1(){ir.value=0;delay(100);}
void to_Timer(){newPosition = myEnc.read()/4;}
void audio(){
  pt.setVolume(vol);  // громкость 0...63       
  pt.setAttL(attl);     // аттенюатор L 0...31     
  pt.setAttR(attr);     // аттенюатор R 0...31
  pt.setAttS(atts);    // аттенюатор S 0...31
  pt.setIn(in,loud_off,loud); // вход 0...3, тонкомпенсация 1 вкл 0 выкл, усиление 0...3
  pt.setBass(bass);       // тембр НЧ -7...+7
  pt.setTreble(treb);     // тембр ВЧ -7...+7
}

3

Re: PT2033

Регулировка громкости и тембра потенциометрами.

Не тестировалось.

#include <Wire.h>
#include <PT2033.h>
  PT2033 pt;
  int vol,treb,bass,in;
  
void setup(){ 
  Serial.begin(9600);Wire.begin();
  pinMode(A0,INPUT);//vol
  pinMode(A1,INPUT);//bass
  pinMode(A2,INPUT);//treble
  pinMode(2,INPUT);// IN
}
 
void loop(){
  if(digitalRead(2)==HIGH){in++;delay(200);if(in>3){in=0;}}
  vol = map(analogRead(A0),0,1024,0,55);
  bass = map(analogRead(A1),0,1024,-7,7);
  treb = map(analogRead(A2),0,1024,-7,7);
  audio();
  dalay(100);
  }
 
void audio(){
  pt.setVolume(vol);  // громкость 0...63       
  pt.setAttL(0);     // аттенюатор L 0...31     
  pt.setAttR(0);     // аттенюатор R 0...31
  pt.setAttS(0);    // аттенюатор S 0...31
 
  pt.setIn(in,0,0); // вход 0...3, тонкомпенсация 1 вкл 0 выкл, усиление 0...3
  pt.setBass(bass);       // тембр НЧ -7...+7
  pt.setTreble(treb);     // тембр ВЧ -7...+7
}