1

Тема: PT2033

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


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
}