1

Тема: BD37534FV

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

BD37534FV.h

#ifndef BD37534FV_H
#define BD37534FV_H

#define BD37534FV_address 0b1000000 

#define SETUP_1        0x01
#define SETUP_2        0x02
#define SETUP_3        0x03
#define INPUT_SELECT   0x05
#define INPUT_GAIN     0x06
#define VOLUME_GAIN    0x20
#define FADER_1_FRONT  0x28
#define FADER_2_FRONT  0x29
#define FADER_1_REAR   0x2A
#define FADER_2_REAR   0x2B
#define FADER_SUB      0x2C
#define MIXING         0x30
#define BASS_SETUP     0x41
#define MIDDLE_SETUP   0x44
#define TREBLE_SETUP   0x47
#define BASS_GAIN      0x51
#define MIDDLE_GAIN    0x54
#define TREBLE_GAIN    0x57
#define LOUDNESS_GAIN  0x75

#include <Arduino.h>
class BD37534FV
{
  public:
    BD37534FV();
    void setSetup_1(int sw_of, int sw_time, int time_mute); // default (1,2,0)
        void setSetup_2(int sub_f, int sub_out, int level_metr, int faza); 
                   // int sub_f ------ OFF 55Hz 85Hz 120Hz 160Hz = int 0...4
                   // int sub_out ---- LPF Front Rear Prohibition = int 0...3
                   // int level_metr - HOLD REST = int 0..1
                   // int faza ------- 0 180 = int 0...1
        void setLoudness_f(int loud_f); // 250Hz 400Hz 800Hz Prohibition = int 0...3
        void setIn(int in); // 0...2
        void setIn_gain(int in_gain, int mute); // in_gain -- 0...20 = 0...20 dB, mute -- 0 default 
        void setVol(int vol); // -79...+15 dB = int -79...15
        void setFront_1(int front_1); // -79...+15 dB = int -79...15
        void setFront_2(int front_2); // -79...+15 dB = int -79...15
        void setRear_1(int rear_1); // -79...+15 dB = int -79...15
        void setRear_2(int rear_2); // -79...+15 dB = int -79...15
        void setSub(int sub); // -79...+15 dB = int -79...15
        void mix();
        void setBass_setup(int bass_q, int bass_f); // 0.5 1.0 1.5 2.0 --- int 0...3, 60Hz 80Hz 100Hz 120Hz --- int 0...3
        void setMiddle_setup(int mid_q, int mid_f); // 0.75 1.0 1.25 1.5 --- int 0...3, 500Hz 1kHz 1.5kHz 2.5kHz --- int 0...3
        void setTreble_setup(int treb_q, int treb_f); // 0.75 1.25  --- int 0...1, 7.5kHz 10kHz 12.5kHz 15kHz --- int 0...3
        void setBass_gain(int bass_gain); // --20 ... +20 dB = int -20 ... 20    
        void setMiddle_gain(int mid_gain); // --20 ... +20 dB = int -20 ... 20
        void setTreble_gain(int treb_gain); // --20 ... +20 dB = int -20 ... 20        
        void setLoudness_gain(int loud_gain); // 0 ... 20 dB = int 0 ... 20

  private:
    void writeWire(char a, char b);
};
    
#endif //BD37534FV_H

BD37534FV.cpp

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

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

void BD37534FV::setSetup_1(int sw_of, int sw_time, int time_mute){
           switch(sw_of){
               case 0: sw_of = 0b00000000;break;
               case 1: sw_of = 0b10000000;break;
   }
           switch(sw_time){
               case 0: sw_time = 0b00000000;break;
               case 1: sw_time = 0b00010000;break;
               case 2: sw_time = 0b00100000;break;
               case 3: sw_time = 0b00110000;break;        
   }
           switch(time_mute){
               case 0: time_mute = 0b00000000;break;
               case 1: time_mute = 0b00000001;break;
               case 2: time_mute = 0b00000010;break;
               case 3: time_mute = 0b00000011;break;        
   }
           int set1_sum = 0b00000100 + sw_of + sw_time + time_mute;
           writeWire(SETUP_1, set1_sum); 
   }

void BD37534FV::setSetup_2(int sub_f, int sub_out, int level_metr, int faza){
            switch(sub_f){
               case 0: sub_f = 0b00000000;break;
               case 1: sub_f = 0b00000001;break;
               case 2: sub_f = 0b00000010;break;
               case 3: sub_f = 0b00000011;break;  
               case 4: sub_f = 0b00000100;break; 
   }
            switch(sub_out){
               case 0: sub_out = 0b00000000;break;
               case 1: sub_out = 0b00010000;break;
               case 2: sub_out = 0b00100000;break;
               case 3: sub_out = 0b00110000;break;  
   }
            switch(level_metr){
               case 0: level_metr = 0b00000000;break;
               case 1: level_metr = 0b01000000;break;
   }
            switch(faza){
               case 0: faza = 0b00000000;break;
               case 1: faza = 0b10000000;break;
   }
            int set2_sum =  sub_f + sub_out + level_metr + faza;
            writeWire(SETUP_2, set2_sum); 
   }
   
void BD37534FV::setLoudness_f(int loud_f){
            switch(loud_f){
               case 0: loud_f = 0b00000001;break;
               case 1: loud_f = 0b00001001;break;
               case 2: loud_f = 0b00010001;break;
               case 3: loud_f = 0b00011001;break;  
   }
            writeWire(SETUP_3, loud_f); 
   }

void BD37534FV::setIn(int in){
            writeWire(INPUT_SELECT, in); 
   }


void BD37534FV::setIn_gain(int in_gain, int mute){
            switch(mute){
               case 0: mute = 0b00000000;break;
               case 1: mute = 0b10000000;break;
   }
            int sum_in_gain = in_gain + mute;
            writeWire(INPUT_GAIN, sum_in_gain); 
   }

void BD37534FV::setVol(int vol){
            if(vol > 0){vol = 128 - vol;}
            if(vol <= 0){vol = abs(vol) + 128;}
            writeWire(VOLUME_GAIN, vol); 
   }

void BD37534FV::setFront_1(int front_1){
            if(front_1 > 0){front_1 = 128 - front_1;}
            if(front_1 <= 0){front_1 = abs(front_1) + 128;}
            writeWire(FADER_1_FRONT, front_1); 
   }

void BD37534FV::setFront_2(int front_2){
            if(front_2 > 0){front_2 = 128 - front_2;}
            if(front_2 <= 0){front_2 = abs(front_2) + 128;}
            writeWire(FADER_2_FRONT, front_2); 
   }

void BD37534FV::setRear_1(int rear_1){
            if(rear_1 > 0){rear_1 = 128 - rear_1;}
            if(rear_1 <= 0){rear_1 = abs(rear_1) + 128;}
            writeWire(FADER_1_REAR, rear_1); 
   }

void BD37534FV::setRear_2(int rear_2){
            if(rear_2 > 0){rear_2 = 128 - rear_2;}
            if(rear_2 <= 0){rear_2 = abs(rear_2) + 128;}
            writeWire(FADER_2_REAR, rear_2); 
   }

void BD37534FV::setSub(int sub){
            if(sub > 0){sub = 128 - sub;}
            if(sub <= 0){sub = abs(sub) + 128;}
            writeWire(FADER_SUB, sub); 
   }

void BD37534FV::mix(){
            writeWire(MIXING, 0b11111111); 
   }

void BD37534FV::setBass_setup(int bass_q, int bass_f){
            switch(bass_q){
               case 0: bass_q = 0b00000000;break;
               case 1: bass_q = 0b00000001;break;
               case 2: bass_q = 0b00000010;break;
               case 3: bass_q = 0b00000011;break;  
   }
            switch(bass_f){
               case 0: bass_f = 0b00000000;break;
               case 1: bass_f = 0b00010000;break;
               case 2: bass_f = 0b00100000;break;
               case 3: bass_f = 0b00110000;break;  
   }
            int bass_s_sum = bass_q + bass_f;
            writeWire(BASS_SETUP, bass_s_sum); 
   }

void BD37534FV::setTreble_setup(int treb_q, int treb_f){
            switch(treb_q){
               case 0: treb_q = 0b00000000;break;
               case 1: treb_q = 0b00000001;break; 
   }
            switch(treb_f){
               case 0: treb_f = 0b00000000;break;
               case 1: treb_f = 0b00010000;break;
               case 2: treb_f = 0b00100000;break;
               case 3: treb_f = 0b00110000;break;  
   }
            int treb_s_sum = treb_q + treb_f;
            writeWire(TREBLE_SETUP, treb_s_sum); 
   }

void BD37534FV::setBass_gain(int bass_gain){
                 if(bass_gain>0){bass_gain = bass_gain + 0b00000000;}                     
                 if(bass_gain<=0){bass_gain = abs(bass_gain) + 0b10000000;}  
               writeWire(BASS_GAIN, bass_gain);   
   }

void BD37534FV::setMiddle_gain(int mid_gain){
                 if(mid_gain>0){mid_gain = mid_gain + 0b00000000;}                     
                 if(mid_gain<=0){mid_gain = abs(mid_gain) + 0b10000000;}  
               writeWire(MIDDLE_GAIN, mid_gain);   
   }

void BD37534FV::setTreble_gain(int treb_gain){
                 if(treb_gain>0){treb_gain = treb_gain + 0b00000000;}                     
                 if(treb_gain<=0){treb_gain = abs(treb_gain) + 0b10000000;}  
               writeWire(TREBLE_GAIN, treb_gain);   
   }

void BD37534FV::setLoudness_gain(int loud_gain){
               writeWire(LOUDNESS_GAIN, loud_gain);  
   }


void BD37534FV::setMiddle_setup(int mid_q, int mid_f){
            switch(mid_q){
               case 0: mid_q = 0b00000000;break;
               case 1: mid_q = 0b00000001;break;
               case 2: mid_q = 0b00000010;break;
               case 3: mid_q = 0b00000011;break;  
   }
            switch(mid_f){
               case 0: mid_f = 0b00000000;break;
               case 1: mid_f = 0b00010000;break;
               case 2: mid_f = 0b00100000;break;
               case 3: mid_f = 0b00110000;break;  
   }
            int mid_s_sum = mid_q + mid_f;
            writeWire(MIDDLE_SETUP, mid_s_sum); 
   }



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

test.ino

#include <Wire.h> 
#include <BD37534FV.h>
BD37534FV tda; 

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

void loop(){}

void audio(){
   tda.setSetup_1(1,2,0); // default (1,2,0)
   tda.setSetup_2(0,0,0,0); 
                   // int sub_f ------ OFF 55Hz 85Hz 120Hz 160Hz = int 0...4
                   // int sub_out ---- LPF Front Rear Prohibition = int 0...3
                   // int level_metr - HOLD REST = int 0..1
                   // int faza ------- 0 180 = int 0...1
   tda.setLoudness_f(0); // 250Hz 400Hz 800Hz Prohibition = int 0...3
   tda.setIn(0); // 0...2
   tda.setIn_gain(0,0); // in_gain -- 0...20 = 0...20 dB, mute -- 0 default 
   tda.setVol(0); // -79...+15 dB = int -79...15
   tda.setFront_1(0); // -79...+15 dB = int -79...15
   tda.setFront_2(0); // -79...+15 dB = int -79...15
   tda.setRear_1(0); // -79...+15 dB = int -79...15
   tda.setRear_2(0); // -79...+15 dB = int -79...15
   tda.setSub(0); // -79...+15 dB = int -79...15
   tda.mix();
   tda.setBass_setup(0,0); // 0.5 1.0 1.5 2.0 --- int 0...3, 60Hz 80Hz 100Hz 120Hz --- int 0...3
   tda.setMiddle_setup(0,0); // 0.75 1.0 1.25 1.5 --- int 0...3, 500Hz 1kHz 1.5kHz 2.5kHz --- int 0...3
   tda.setTreble_setup(0,0); // 0.75 1.25  --- int 0...1, 7.5kHz 10kHz 12.5kHz 15kHz --- int 0...3
   tda.setBass_gain(0); // --20 ... +20 dB = int -20 ... 20  
   tda.setMiddle_gain(0); // --20 ... +20 dB = int -20 ... 20
   tda.setTreble_gain(0); // --20 ... +20 dB = int -20 ... 20   
   tda.setLoudness_gain(0); // 0 ... 20 dB = int 0 ... 20
  }