<?xml version="1.0" encoding="utf-8"?>
<feed xmlns="http://www.w3.org/2005/Atom">
	<title type="html"><![CDATA[forum.rcl-radio.ru &mdash; PT2314]]></title>
	<link rel="self" href="http://forum.rcl-radio.ru/extern.php?action=feed&amp;tid=481&amp;type=atom" />
	<updated>2022-03-13T08:30:19Z</updated>
	<generator>PunBB</generator>
	<id>http://forum.rcl-radio.ru/viewtopic.php?id=481</id>
		<entry>
			<title type="html"><![CDATA[PT2314]]></title>
			<link rel="alternate" href="http://forum.rcl-radio.ru/viewtopic.php?pid=5518#p5518" />
			<content type="html"><![CDATA[<p><span class="attention-yellow"></span> </p><p>PT2314.h<br /></p><div class="codebox"><pre><code>// liman324@yandex.ru rcl-radio.ru


#ifndef PT2314_H
#define PT2314_H

#define PT2314_address 0x44 // адрес 0b10001000


#include &lt;Arduino.h&gt;
class PT2314
{
  public:
    PT2314();
        void setVolume(int vol); // int 0...56 === 0...-70 dB step 1.25 dB
	void setAttL(int att_l); // int 0...24 === 0...-30 db step 1.25 dB      
	void setAttR(int att_r); // int 0...24 === 0...-30 dB step 1.25 dB
        void setSwitch(int input, int loud, int usil); 
        // input int 0..2 === IN 1...3 
        // loudness int 0...1 === 1-on 0-off
        // input gain int 0...3 === 0...11.25dB step 3.75 dB
        void setBass(int bass);   // int -7...+7 === -14...+14 dB step 2 dB
        void setTreble(int treb); // int -7...+7 === -14...+14 dB step 2 dB
	
  private:
	void writeWire(char a);
};
	
#endif //PT2314_H</code></pre></div><p>PT2314.cpp<br /></p><div class="codebox"><pre><code>#include &lt;Arduino.h&gt;
#include &lt;Wire.h&gt;
#include &quot;PT2314.h&quot;

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

void PT2314::setVolume(int vol){
  vol = 56-vol;
  writeWire(vol);
}

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

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

void PT2314::setSwitch(int input, int loud, int usil){
  switch (loud){
    case 1:loud = 0b00000000;break;
    case 0:loud = 0b00000100;break;
  }
  switch (usil){
    case 3:usil = 0b00000000;break;
    case 2:usil = 0b00001000;break;
    case 1:usil = 0b00010000;break;
    case 0:usil = 0b00011000;break; 
  }
  writeWire(0b01000000 + input + loud + usil);
}

void PT2314::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 PT2314::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 PT2314::writeWire(char a){
  Wire.beginTransmission(PT2314_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;PT2314.h&gt;

PT2314 pt;

void setup() {
     audio();
}

void loop() {
}

void audio(){
  pt.setVolume(45); // int 0...56 === -70...0 dB step 1.25 dB
  pt.setAttL(0); // int 0...24 === 0...-30 db step 1.25 dB &gt; int 31 === mute on     
  pt.setAttR(0); // int 0...24 === 0...-30 dB step 1.25 dB &gt; int 31 === mute on
  pt.setSwitch(0, 0, 0); 
        // input      int 0..3 === IN 1...4 
        // loudness   int 0...1 === 1-on 0-off
        // input gain int 0...3 === 11.25...0 dB step 3.75 dB
  pt.setBass(0);   // int -7...+7 === -14...+14 dB step 2 dB
  pt.setTreble(0); // int -7...+7 === -14...+14 dB step 2 dB
  }</code></pre></div>]]></content>
			<author>
				<name><![CDATA[liman324]]></name>
				<uri>http://forum.rcl-radio.ru/profile.php?id=2</uri>
			</author>
			<updated>2022-03-13T08:30:19Z</updated>
			<id>http://forum.rcl-radio.ru/viewtopic.php?pid=5518#p5518</id>
		</entry>
</feed>
