1

Тема: BD3491FS

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

BD3491FS.h

// ALEXSANDER LIMAN
// liman324@yandex.ru
// rcl-radio.ru
// 08.11.2019

#ifndef BD3491FS_H
#define BD3491FS_H

#define BD3491FS_address 0b1000001 

#define INPUT_SELECT        0x04
#define INPUT_GAIN          0x06
#define VOLUME_GAIN_1       0x21
#define VOLUME_GAIN_2       0x22
#define BASS_GAIN           0x51
#define TREBLE_GAIN         0x57
#define SURROUND            0x78

#include <Arduino.h>
class BD3491FS
{
  public:
    BD3491FS();
    void setSelect(int in);// int 0...7 === A B C D E F INPUT_SHORT INPUT_MUTE
    void setIn_gain(int in_gain); // int 0...7 === 0...20 dB    
    void setVol_1(int vol_1); // int 0...87 === 0...-87 dB
    void setVol_2(int vol_2); // int 0...87 === 0...-87 dB
    void setBass(int bass); // int -7...0...+7 === -14...+14 dB
    void setTreb(int treb); // int -7...0...+7 === -14...+14 dB
    void setSurround(int sur); // int 0...3 === OFF LOW MIDDLE HIGH
	
  private:
	void writeWire(char a, char b);
};
	
#endif //BD3491FS_H

BD3491FS.cpp

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

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

void BD3491FS::setSelect(int in){
     writeWire(INPUT_SELECT, in); 
}

void BD3491FS::setIn_gain(int in_gain){
     switch(in_gain){
       case 0: in_gain = 0b00000000;break;
       case 1: in_gain = 0b00000010;break;
       case 2: in_gain = 0b00000100;break;
       case 3: in_gain = 0b00000110;break;
       case 4: in_gain = 0b00001000;break;
       case 5: in_gain = 0b00001100;break;
       case 6: in_gain = 0b00010000;break;
       case 7: in_gain = 0b00010100;break;
}
     writeWire(INPUT_GAIN, in_gain); 
}

void BD3491FS::setVol_1(int vol_1){
     writeWire(VOLUME_GAIN_1, vol_1 + 0b10000000); 
}

void BD3491FS::setVol_2(int vol_2){
     writeWire(VOLUME_GAIN_2, vol_2 + 0b10000000); 
}

void BD3491FS::setBass(int bass){
     switch(bass){
       case 0: bass = 0b00000000;break;
       case 1: bass = 0b00000010;break;
       case 2: bass = 0b00000100;break;
       case 3: bass = 0b00000110;break;
       case 4: bass = 0b00001000;break;
       case 5: bass = 0b00001010;break;
       case 6: bass = 0b00001100;break;
       case 7: bass = 0b00001110;break;
       case -1: bass = 0b10000010;break;
       case -2: bass = 0b10000100;break;
       case -3: bass = 0b10000110;break;
       case -4: bass = 0b10001000;break;
       case -5: bass = 0b10001010;break;
       case -6: bass = 0b10001100;break;
       case -7: bass = 0b10001110;break;
}
     writeWire(BASS_GAIN, bass); 
}

void BD3491FS::setTreb(int treb){
     switch(treb){
       case 0: treb = 0b00000000;break;
       case 1: treb = 0b00000010;break;
       case 2: treb = 0b00000100;break;
       case 3: treb = 0b00000110;break;
       case 4: treb = 0b00001000;break;
       case 5: treb = 0b00001010;break;
       case 6: treb = 0b00001100;break;
       case 7: treb = 0b00001110;break;
       case -1: treb = 0b10000010;break;
       case -2: treb = 0b10000100;break;
       case -3: treb = 0b10000110;break;
       case -4: treb = 0b10001000;break;
       case -5: treb = 0b10001010;break;
       case -6: treb = 0b10001100;break;
       case -7: treb = 0b10001110;break;
}
     writeWire(TREBLE_GAIN, treb); 
}

void BD3491FS::setSurround(int sur){
     switch(sur){
       case 0: sur = 0b10000000;break;
       case 1: sur = 0b10000101;break;
       case 2: sur = 0b10001010;break;
       case 3: sur = 0b10001111;break;
}
     writeWire(SURROUND, sur); 
}

void BD3491FS::writeWire(char a, char b){
  Wire.beginTransmission(BD3491FS_address);
  Wire.write (a);
  Wire.write (b);
  Wire.endTransmission();
}

test.ino

#include <Wire.h> 
#include <BD3491FS.h>
BD3491FS bd; 

void setup(){
   Wire.begin();
   audio();
}

void loop(){}

void audio(){
    bd.setSelect(0);// int 0...7 === A B C D E F INPUT_SHORT INPUT_MUTE
    bd.setIn_gain(0); // int 0...7 === 0...20 dB    
    bd.setVol_1(0); // int 0...87 === 0...-87 dB
    bd.setVol_2(0); // int 0...87 === 0...-87 dB
    bd.setBass(0); // int -7...0...+7 === -14...+14 dB
    bd.setTreb(0); // int -7...0...+7 === -14...+14 dB
    bd.setSurround(1); // int 0...3 === OFF LOW MIDDLE HIGH
  }