<?xml version="1.0" encoding="utf-8"?>
<feed xmlns="http://www.w3.org/2005/Atom">
	<title type="html"><![CDATA[forum.rcl-radio.ru &mdash; R2S15900SP]]></title>
	<link rel="self" href="http://forum.rcl-radio.ru/extern.php?action=feed&amp;tid=277&amp;type=atom" />
	<updated>2021-03-03T17:11:36Z</updated>
	<generator>PunBB</generator>
	<id>http://forum.rcl-radio.ru/viewtopic.php?id=277</id>
		<entry>
			<title type="html"><![CDATA[Re: R2S15900SP]]></title>
			<link rel="alternate" href="http://forum.rcl-radio.ru/viewtopic.php?pid=3191#p3191" />
			<content type="html"><![CDATA[<div class="codebox"><pre><code>#define CLK     9   //  ENCODER 
#define DT      8   //  ENCODER 
#define SW     10   //  ENCODER 

#include &lt;Wire.h&gt;
#include &lt;EEPROM.h&gt;
#include &lt;MsTimer2.h&gt;                    // http://rcl-radio.ru/wp-content/uploads/2018/11/MsTimer2.zip
#include &lt;R2S15900SP.h&gt;
#include &lt;Encoder.h&gt;                     // http://rcl-radio.ru/wp-content/uploads/2019/05/Encoder.zip
#include &lt;LiquidCrystal_I2C.h&gt;           // http://forum.rcl-radio.ru/misc.php?action=pan_download&amp;item=45&amp;download=1 
 Encoder myEnc(CLK, DT);
 R2S15900SP r2s;
 LiquidCrystal_I2C lcd(0x27,16,2);  // Устанавливаем дисплей 
 

    byte v1[8] = {0x07,0x07,0x07,0x07,0x07,0x07,0x07,0x07};
    byte v2[8] = {0x07,0x07,0x00,0x00,0x00,0x00,0x00,0x00};      
    byte v3[8] = {0x00,0x00,0x00,0x00,0x00,0x00,0x1F,0x1F};
    byte v4[8] = {0x1F,0x1F,0x00,0x00,0x00,0x00,0x1F,0x1F};
    byte v5[8] = {0x1C,0x1C,0x00,0x00,0x00,0x00,0x1C,0x1C};
    byte v6[8] = {0x1C,0x1C,0x1C,0x1C,0x1C,0x1C,0x1C,0x1C};
    byte v7[8] = {0x00,0x00,0x00,0x00,0x00,0x00,0x07,0x07};
    byte v8[8] = {0x1F,0x1F,0x00,0x00,0x00,0x00,0x00,0x00};
    unsigned long times,times1,oldPosition  = -999,newPosition;
    int menu,w,w2,vol,mut,a[3],in,bas,treb;
    byte i,d1,d2,d3,d4,d5,d6,e1,e2,e3;
  

void setup() {
  Serial.begin(9600);MsTimer2::set(3, to_Timer);MsTimer2::start();
  pinMode(SW,INPUT);
  lcd.init();lcd.backlight();
  lcd.createChar(1, v1);lcd.createChar(2, v2);lcd.createChar(3, v3);lcd.createChar(4, v4);lcd.createChar(5, v5);lcd.createChar(6, v6);lcd.createChar(7, v7);lcd.createChar(8, v8);
  if(EEPROM.read(100)!=0){for(int i=0;i&lt;101;i++){EEPROM.update(i,0);}}// очистка памяти при первом включении 
  vol = EEPROM.read(0);in = EEPROM.read(1);bas = EEPROM.read(2)-15;treb = EEPROM.read(3)-15;
  lcd.setCursor(0,0);lcd.print(&quot;   R2S15900SP   &quot;);
  delay(1000);
  audio();
  lcd.clear();
}

void loop() {
  if(digitalRead(SW)==LOW){menu++;if(menu&gt;2){menu=0;};delay(200);lcd.clear();w=1;times=millis();w2=1;}
  
  /// VOLUME ///////////////////////////////////////////////////
 if(menu==0){
   if (newPosition != oldPosition){oldPosition = newPosition;
     vol=vol-newPosition;myEnc.write(0);newPosition=0;w=1;times=millis();w2=1;
     if(vol&gt;84){vol=84;}if(vol&lt;0){vol=0;}
     audio();}
 
     lcd.setCursor(0,0);
       if(mut==1){lcd.print(&quot;MUTE    &quot;);}
       if(mut==0){lcd.print(&quot;VOLUME  &quot;);}  
     lcd.setCursor(0,1);lcd.print(&quot;IN &quot;);lcd.print(in);
     
 
if(w2==1){w2=0;
     
     a[0]=(84-vol)/10;a[1]=(84-vol)%10;
      for(i=0;i&lt;2;i++){
      switch(i){
        case 0: e1=9,e2=10,e3=11;break;
        case 1: e1=12,e2=13,e3=14;break;
        }
      switch(a[i]){
        case 0: d1=1,d2=8,d3=6,d4=1,d5=3,d6=6;break;
        case 1: d1=32,d2=2,d3=6,d4=32,d5=32,d6=6;break;
        case 2: d1=2,d2=8,d3=6,d4=1,d5=4,d6=5;break;
        case 3: d1=2,d2=4,d3=6,d4=7,d5=3,d6=6;break;
        case 4: d1=1,d2=3,d3=6,d4=32,d5=32,d6=6;break;
        case 5: d1=1,d2=4,d3=5,d4=7,d5=3,d6=6;break;
        case 6: d1=1,d2=4,d3=5,d4=1,d5=3,d6=6;break;
        case 7: d1=1,d2=8,d3=6,d4=32,d5=32,d6=6;break;
        case 8: d1=1,d2=4,d3=6,d4=1,d5=3,d6=6;break;
        case 9: d1=1,d2=4,d3=6,d4=7,d5=3,d6=6;break;
    }
      lcd.setCursor(e1,0);lcd.write((uint8_t)d1);lcd.setCursor(e2,0);lcd.write((uint8_t)d2);lcd.setCursor(e3,0);lcd.write((uint8_t)d3);
      lcd.setCursor(e1,1);lcd.write((uint8_t)d4);lcd.setCursor(e2,1);lcd.write((uint8_t)d5);lcd.setCursor(e3,1);lcd.write((uint8_t)d6);
 }} 
 }

  /// bas ///////////////////////////////////////////////////
 if(menu==1){
   if (newPosition != oldPosition){oldPosition = newPosition;
     bas=bas+newPosition;myEnc.write(0);newPosition=0;w=1;times=millis();w2=1;
     if(bas&gt;15){bas=15;}if(bas&lt;-15){bas=-15;}
     audio();}
 
     lcd.setCursor(0,0);
     lcd.print(&quot;BASS  &quot;);
     if(bas&lt;0){lcd.setCursor(8,1);lcd.write((uint8_t)0);}else{lcd.setCursor(8,1);lcd.print(&quot; &quot;);}
 
if(w2==1){w2=0;
     
     a[0]=abs(bas)/10;a[1]=abs(bas)%10;
      for(i=0;i&lt;2;i++){
      switch(i){
        case 0: e1=9,e2=10,e3=11;break;
        case 1: e1=12,e2=13,e3=14;break;
        }
      switch(a[i]){
        case 0: d1=1,d2=8,d3=6,d4=1,d5=3,d6=6;break;
        case 1: d1=32,d2=2,d3=6,d4=32,d5=32,d6=6;break;
        case 2: d1=2,d2=8,d3=6,d4=1,d5=4,d6=5;break;
        case 3: d1=2,d2=4,d3=6,d4=7,d5=3,d6=6;break;
        case 4: d1=1,d2=3,d3=6,d4=32,d5=32,d6=6;break;
        case 5: d1=1,d2=4,d3=5,d4=7,d5=3,d6=6;break;
        case 6: d1=1,d2=4,d3=5,d4=1,d5=3,d6=6;break;
        case 7: d1=1,d2=8,d3=6,d4=32,d5=32,d6=6;break;
        case 8: d1=1,d2=4,d3=6,d4=1,d5=3,d6=6;break;
        case 9: d1=1,d2=4,d3=6,d4=7,d5=3,d6=6;break;
    }
      lcd.setCursor(e1,0);lcd.write((uint8_t)d1);lcd.setCursor(e2,0);lcd.write((uint8_t)d2);lcd.setCursor(e3,0);lcd.write((uint8_t)d3);
      lcd.setCursor(e1,1);lcd.write((uint8_t)d4);lcd.setCursor(e2,1);lcd.write((uint8_t)d5);lcd.setCursor(e3,1);lcd.write((uint8_t)d6);
 }} 
 }

 /// TREB ///////////////////////////////////////////////////
 if(menu==2){
   if (newPosition != oldPosition){oldPosition = newPosition;
     treb=treb+newPosition;myEnc.write(0);newPosition=0;w=1;times=millis();w2=1;
     if(treb&gt;15){treb=15;}if(treb&lt;-15){treb=-15;}
     audio();}
 
     lcd.setCursor(0,0);
     lcd.print(&quot;TREBLE  &quot;);
     if(treb&lt;0){lcd.setCursor(8,1);lcd.write((uint8_t)0);}else{lcd.setCursor(8,1);lcd.print(&quot; &quot;);}
 
if(w2==1){w2=0;
     
     a[0]=abs(treb)/10;a[1]=abs(treb)%10;
      for(i=0;i&lt;2;i++){
      switch(i){
        case 0: e1=9,e2=10,e3=11;break;
        case 1: e1=12,e2=13,e3=14;break;
        }
      switch(a[i]){
        case 0: d1=1,d2=8,d3=6,d4=1,d5=3,d6=6;break;
        case 1: d1=32,d2=2,d3=6,d4=32,d5=32,d6=6;break;
        case 2: d1=2,d2=8,d3=6,d4=1,d5=4,d6=5;break;
        case 3: d1=2,d2=4,d3=6,d4=7,d5=3,d6=6;break;
        case 4: d1=1,d2=3,d3=6,d4=32,d5=32,d6=6;break;
        case 5: d1=1,d2=4,d3=5,d4=7,d5=3,d6=6;break;
        case 6: d1=1,d2=4,d3=5,d4=1,d5=3,d6=6;break;
        case 7: d1=1,d2=8,d3=6,d4=32,d5=32,d6=6;break;
        case 8: d1=1,d2=4,d3=6,d4=1,d5=3,d6=6;break;
        case 9: d1=1,d2=4,d3=6,d4=7,d5=3,d6=6;break;
    }
      lcd.setCursor(e1,0);lcd.write((uint8_t)d1);lcd.setCursor(e2,0);lcd.write((uint8_t)d2);lcd.setCursor(e3,0);lcd.write((uint8_t)d3);
      lcd.setCursor(e1,1);lcd.write((uint8_t)d4);lcd.setCursor(e2,1);lcd.write((uint8_t)d5);lcd.setCursor(e3,1);lcd.write((uint8_t)d6);
 }} 
 }


 //// EEPROM ///////////////////////////////////////
 if(millis()-times&gt;5000 &amp;&amp; w==1){w=0;EEPROM.update(0,vol);EEPROM.update(1,in);EEPROM.update(2,bas+15);EEPROM.update(3,treb+15);menu=0;lcd.clear();w2=1;}
 delay(10);
  
}

void to_Timer(){newPosition = myEnc.read()/4;}
void audio(){             
  r2s.setVol_l(vol);  // volume left &gt;&gt; int 84...0 === -84...0 dB
  r2s.setVol_r(vol);  // volume_right &gt;&gt; int 84...0 === -84...0 dB
  r2s.setIn(1, 0, 1);     
             // input &gt;&gt; int 0 === all off | int 1...5 === input 1...5 
             // gain &gt;&gt; int 0...1 === 0 dB...+4.5 dB
             // mute &gt;&gt; int 0...1 === mute on...mute off
  r2s.set_Bass(1, 1, bas);
             // surround mode &gt;&gt; int 0...1 === low level...high level
             // mode selector &gt;&gt; int 0...3 === bypass tone tone&amp;Pseudo_stereo tone&amp;Surround
             // tone control bas &gt;&gt; int -15...15 === -15dB...+15dB
  r2s.set_Treb(treb);   // tone control treble &gt;&gt; int -15...15 === -15dB...+15dB
}</code></pre></div>]]></content>
			<author>
				<name><![CDATA[liman324]]></name>
				<uri>http://forum.rcl-radio.ru/profile.php?id=2</uri>
			</author>
			<updated>2021-03-03T17:11:36Z</updated>
			<id>http://forum.rcl-radio.ru/viewtopic.php?pid=3191#p3191</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[R2S15900SP]]></title>
			<link rel="alternate" href="http://forum.rcl-radio.ru/viewtopic.php?pid=3170#p3170" />
			<content type="html"><![CDATA[<p>Description<br />The R2S15900SP is an optimum audio signal processor IC for TV. It has a 5ch input selector, surround/pseudo stereo tone control(2band), output gain control and 2ch master volume. It can control all of these functions with I2 C bus.</p><p>Features<br />• Volume 0 to –84dB, –∞/ 1dB step | Each channel is independence control.<br />• 5 input selector + MUTE<br />• 2 Rec output<br />• Tone control Bass: –15dB to +15dB/ 1dB step | Treble: –15dB to +15dB/ 1dB step<br />• Surround &lt;Low/ High&gt; / Pseudo Stereo<br />• Mode selector Bypass/ Tone / Tone &amp; Pseudo Stereo or Surround<br />• Output gain control 0dB/ +4.5dB<br />• I2C-BUS control<br />• Package 28pin SOP </p><p>Даташит - <span class="attention-yellow"></span> </p><p>Библиотека - <span class="attention-yellow"></span> </p><p>R2S15900SP.h</p><div class="codebox"><pre><code>// Алксандр Лиман
// liman324@yandex.ru

#ifndef R2S15900SP_H
#define R2S15900SP_H
#define R2S15900SP_address 0b1000001 

#define R2S15900SP_VOL_L   0x00
#define R2S15900SP_VOL_R   0x01
#define R2S15900SP_INPUT   0x02
#define R2S15900SP_BASS    0x03
#define R2S15900SP_TREB    0x04

#include &lt;Arduino.h&gt;
class R2S15900SP
{
  public:
    R2S15900SP();
              
        void setVol_l(int vol_l);  // volume left &gt;&gt; int 84...0 === -84...0 dB
        void setVol_r(int vol_r);  // volume_right &gt;&gt; int 84...0 === -84...0 dB
        void setIn(int in, int gain, int mute);     
             // input &gt;&gt; int 0 === all off | int 1...5 === input 1...5 
             // gain &gt;&gt; int 0...1 === 0 dB...+4.5 dB
             // mute &gt;&gt; int 0...1 === mute on...mute off
        void set_Bass(int surr, int mode, int bass);
             // surround mode &gt;&gt; int 0...1 === low level...high level
             // mode selector &gt;&gt; int 0...3 === bypass tone tone&amp;Pseudo_stereo tone&amp;Surround
             // tone control bass &gt;&gt; int -15...15 === -15dB...+15dB
        void set_Treb(int treb);   // tone control treble &gt;&gt; int -15...15 === -15dB...+15dB

  private:
	void writeWire(char a, char b);
};
	
#endif //R2S15900SP_H</code></pre></div><br /><p>R2S15900SP.cpp</p><div class="codebox"><pre><code>#include &lt;Arduino.h&gt;
#include &lt;Wire.h&gt;
#include &quot;R2S15900SP.h&quot;

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

void R2S15900SP::setVol_l(int vol_l){
      byte vol_l10 = vol_l/10;
      byte vol_l1 = vol_l%10;
  writeWire(R2S15900SP_VOL_L, (vol_l10 &lt;&lt; 4) + vol_l1);
}

void R2S15900SP::setVol_r(int vol_r){
      byte vol_r10 = vol_r/10;
      byte vol_r1 = vol_r%10;
  writeWire(R2S15900SP_VOL_R, (vol_r10 &lt;&lt; 4) + vol_r1);
}

void R2S15900SP::setIn(int in, int gain, int mute){
      switch(in){
       case 0: in = 0b00011;break;
       case 1: in = 0b00111;break;
       case 2: in = 0b01011;break;
       case 3: in = 0b01111;break;
       case 4: in = 0b10011;break;
       case 5: in = 0b10111;break;
}
  writeWire(R2S15900SP_INPUT, (in &lt;&lt; 3) + (gain &lt;&lt; 2) + (mute &lt;&lt; 1) + mute);
}

void R2S15900SP::set_Bass(int surr, int mode, int bass){
       if(bass &gt;= 0){bass = bass + 0b10000;}
       if(bass &lt;  0){bass = abs(bass);}
  writeWire(R2S15900SP_BASS, (bass &lt;&lt; 3) + (surr &lt;&lt; 2) + mode);
}

void R2S15900SP::set_Treb(int treb){
       if(treb &gt;= 0){treb = treb + 0b10000;}
       if(treb &lt;  0){treb = abs(treb);}
  writeWire(R2S15900SP_TREB, (treb &lt;&lt; 3));
}

void R2S15900SP::writeWire(char a, char b){
  Wire.beginTransmission(R2S15900SP_address);
  Wire.write(a);
  Wire.write(b);
  Wire.endTransmission();
}</code></pre></div><p>test.ino</p><div class="codebox"><pre><code>#include &lt;Wire.h&gt;
#include &lt;R2S15900SP.h&gt;
  R2S15900SP r2s;

void setup() {
  audio();
}

void loop() {
  
}

void audio(){             
  r2s.setVol_l(0);  // volume left &gt;&gt; int 84...0 === -84...0 dB
  r2s.setVol_r(0);  // volume_right &gt;&gt; int 84...0 === -84...0 dB
  r2s.setInput(1, 0, 0);     
             // input &gt;&gt; int 0 === all off | int 1...5 === input 1...5 
             // gain &gt;&gt; int 0...1 === 0 dB...+4.5 dB
             // mute &gt;&gt; int 0...1 === mute off...mute on
  r2s.set_Bass(0, 0, 0);
             // surround mode &gt;&gt; int 0...1 === low level...high level
             // mode selector &gt;&gt; int 0...3 === bypass tone tone&amp;Pseudo_stereo tone&amp;Surround
             // tone control bass &gt;&gt; int -15...15 === -15dB...+15dB
  r2s.set_Treb(0);   // tone control treble &gt;&gt; int -15...15 === -15dB...+15dB
}</code></pre></div><div class="quotebox"><blockquote><p>Скетч использует 2054 байт (6%) памяти устройства. Всего доступно 32256 байт.<br />Глобальные переменные используют 219 байт (10%) динамической памяти, оставляя 1829 байт для локальных переменных. Максимум: 2048 байт.</p></blockquote></div><p>Библиотека zip - <span class="attention-yellow"></span></p>]]></content>
			<author>
				<name><![CDATA[liman324]]></name>
				<uri>http://forum.rcl-radio.ru/profile.php?id=2</uri>
			</author>
			<updated>2021-02-27T12:36:49Z</updated>
			<id>http://forum.rcl-radio.ru/viewtopic.php?pid=3170#p3170</id>
		</entry>
</feed>
