<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
	<channel>
		<title><![CDATA[forum.rcl-radio.ru &mdash; PT2033]]></title>
		<link>http://forum.rcl-radio.ru/viewtopic.php?id=476</link>
		<atom:link href="http://forum.rcl-radio.ru/extern.php?action=feed&amp;tid=476&amp;type=rss" rel="self" type="application/rss+xml" />
		<description><![CDATA[Недавние сообщения в теме «PT2033».]]></description>
		<lastBuildDate>Sun, 13 Mar 2022 08:19:20 +0000</lastBuildDate>
		<generator>PunBB</generator>
		<item>
			<title><![CDATA[PT2033]]></title>
			<link>http://forum.rcl-radio.ru/viewtopic.php?pid=5513#p5513</link>
			<description><![CDATA[<p><span class="attention-yellow"></span> </p><br /><p>PT2033.h<br /></p><div class="codebox"><pre><code>// liman324@yandex.ru rcl-radio.ru


#ifndef PT2033_H
#define PT2033_H

#define PT2033_address 0b1000100


#include &lt;Arduino.h&gt;
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</code></pre></div><p>PT2033.cpp<br /></p><div class="codebox"><pre><code>#include &lt;Arduino.h&gt;
#include &lt;Wire.h&gt;
#include &quot;PT2033.h&quot;

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();
}</code></pre></div><p>test.ino<br /></p><div class="codebox"><pre><code>#include &lt;Wire.h&gt;
#include &lt;PT2033.h&gt;
  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
}</code></pre></div>]]></description>
			<author><![CDATA[null@example.com (liman324)]]></author>
			<pubDate>Sun, 13 Mar 2022 08:19:20 +0000</pubDate>
			<guid>http://forum.rcl-radio.ru/viewtopic.php?pid=5513#p5513</guid>
		</item>
	</channel>
</rss>
