Тема: BD37033FV
Данный контент доступен только зарегистрированным пользователям.
BD37033FV.h
#ifndef BD37033FV_H
#define BD37033FV_H
#define BD37033FV_address 0b1000000
#define INITIAL_SETUP 0x01
#define LPF_SETUP 0x02
#define MIXING_SETUP 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_1 0x2C
#define FADER_SUB_2 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 BD37033FV
{
public:
BD37033FV();
void setInitial();
void setSub_setup(int sub_f,int sub_out, int faza); // off 55hz 85hz 120hz 160hz pass = int sub_f(0...5) || LPF front rear sub = int sub_out(0...3) 0 - default || 0 180 = int faza(0...1)
void setLoud_f(int mix_in, int loud_f, int mix_ch1, int mix_ch2); // MIX_IN 0...3 3=off || 400hz 800hz 2400hz Prohibition = int loud_f(0...3) || MIXING 1ch 2ch -- on off = mix_ch1(0...1) mix_ch2(0..1)
void setIn(int in); // in1 in2 in3 = int in(0...2)
void setIn_gain(int in_gain, int mute); // 0...16 dB = int in_gain(0...16) || off on = int mute(0...1)
void setVol(int vol); // -79...+15 dB = int vol(-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 setSub1(int sub1); // -79...+15 dB = int -79...15
void setSub2(int sub2); // -79...+15 dB = int -79...15
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); // --15 ... +15 dB = int -15 ... 15
void setMiddle_gain(int mid_gain); // --15 ... +15 dB = int -15 ... 15
void setTreble_gain(int treb_gain); // --15 ... +20 dB = int -15 ... 15
void setLoudness_gain(int loud_gain); // 0 ... 15 dB = int 0 ... 15
private:
void writeWire(char a, char b);
};
#endif //BD37033FV_H
BD37033FV.cpp
#include <Arduino.h>
#include <Wire.h>
#include "BD37033FV.h"
BD37033FV::BD37033FV(){
Wire.begin();
}
void BD37033FV::setInitial(){
int initial = 0b00100100;
writeWire(INITIAL_SETUP, initial);
}
void BD37033FV::setSub_setup(int sub_f,int sub_out, 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;
case 5: sub_f = 0b00000101;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(faza){
case 0: faza = 0b00000000;break;
case 1: faza = 0b10000000;break;
}
int sub_set_sum = sub_f + sub_out + faza;
writeWire(LPF_SETUP, sub_set_sum);
}
void BD37033FV::setLoud_f(int mix_in, int loud_f, int mix_ch1, int mix_ch2){
switch(mix_in){
case 0: mix_in = 0b00000000;break;
case 1: mix_in = 0b01000000;break;
case 2: mix_in = 0b10000000;break;
case 3: mix_in = 0b11000000;break;
}
switch(loud_f){
case 0: loud_f = 0b00000000;break;
case 1: loud_f = 0b00001000;break;
case 2: loud_f = 0b00010000;break;
case 3: loud_f = 0b00011000;break;
}
switch(mix_ch1){
case 0: mix_ch1 = 0b00000000;break;
case 1: mix_ch1 = 0b00000010;break;
}
switch(mix_ch2){
case 0: mix_ch2 = 0b00000000;break;
case 1: mix_ch2 = 0b00000100;break;
}
int loun_sum = 0b00000001 + loud_f + mix_ch1 + mix_ch2 + mix_in;
writeWire(MIXING_SETUP, loun_sum);
}
void BD37033FV::setIn(int in){
switch(in){
case 0: in = 0b00000000;break;
case 1: in = 0b00000001;break;
case 2: in = 0b00000010;break;
}
writeWire(INPUT_SELECT, in);
}
void BD37033FV::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 BD37033FV::setVol(int vol){
if(vol > 0){vol = 128 - vol;}
if(vol <= 0){vol = abs(vol) + 128;}
writeWire(VOLUME_GAIN, vol);
}
void BD37033FV::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 BD37033FV::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 BD37033FV::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 BD37033FV::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 BD37033FV::setSub1(int sub1){
if(sub1 > 0){sub1 = 128 - sub1;}
if(sub1 <= 0){sub1 = abs(sub1) + 128;}
writeWire(FADER_SUB_1, sub1);
}
void BD37033FV::setSub2(int sub2){
if(sub2 > 0){sub2 = 128 - sub2;}
if(sub2 <= 0){sub2 = abs(sub2) + 128;}
writeWire(FADER_SUB_2, sub2);
}
void BD37033FV::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 BD37033FV::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 BD37033FV::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 BD37033FV::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 BD37033FV::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 BD37033FV::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 BD37033FV::setLoudness_gain(int loud_gain){
writeWire(LOUDNESS_GAIN, loud_gain);
}
void BD37033FV::writeWire(char a, char b){
Wire.beginTransmission(BD37033FV_address);
Wire.write (a);
Wire.write (b);
Wire.endTransmission();
}
test.ino
#include <Wire.h>
#include <BD37033FV.h>
BD37033FV tda;
void setup(){
Wire.begin();
audio();
}
void loop(){}
void audio(){
tda.setInitial();
tda.setSub_setup(0,0,0); // off 55hz 85hz 120hz 160hz pass = int sub_f(0...5) || LPF front rear sub = int sub_out(0...3) 0 - default || 0 180 = int faza(0...1)
tda.setLoud_f(3,0,0,0); // mix_in off || 400hz 800hz 2400hz Prohibition = int loud_f(0...3) || MIXING 1ch 2ch -- on off = mix_ch1(0...1) mix_ch2(0..1)
tda.setIn(0); // in1 in2 in3 = int in(0...2)
tda.setIn_gain(0,0); // 0...16 dB = int in_gain(0...16) || off on = int mute(0...1)
tda.setVol(0); // -79...+15 dB = int vol(-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.setSub1(0); // -79...+15 dB = int -79...15
tda.setSub2(0); // -79...+15 dB = int -79...15
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); // --15 ... +15 dB = int -15 ... 15
tda.setMiddle_gain(0); // --15 ... +15 dB = int -15 ... 15
tda.setTreble_gain(0); // --15 ... +20 dB = int -15 ... 15
tda.setLoudness_gain(0); // 0 ... 15 dB = int 0 ... 15
}