Тема: PT2322
Данный контент доступен только зарегистрированным пользователям.
PT2322.h
// PT2322 | rcl-radio.ru | liman324@yandex.ru
#ifndef PT2322_H
#define PT2322_H
#define PT2322_address 0x44 // адрес
#include <Arduino.h>
class PT2322
{
public:
PT2322();
///////////////// аттенюаторы ////////////////////////
void setFront_lk_att(int f_lk_att);// att front L
void setFront_rk_att(int f_rk_att);// att front R
void setCenter_att(int c_att); // att center
void setRear_lk_att(int r_lk_att); // att rear L
void setRear_rk_att(int r_rk_att); // att rear R
void setSub_att(int sub_att); // att SUB
// -15...0 dB (int 15...0)
//////////////////////////////////////////////////////
void setFunc(int mute, int ddd, int tembr);// FUNC:
// mute - 0 выкл, 1 вкл
// ddd - 0 вкл, 1 выкл
// тембр - 0 вкл, 1 выкл
// (int 0,0,0) - по умолчанию
void setBass(int bass); // BASS -14...0...14 dB (int -7...0...7)
void setMiddle(int mid); // MIDDLE -14...0...14 dB (int -7...0...7)
void setTreble(int treb); // TREBLE -14...0...14 dB (int -7...0...7)
void setVol(int vol); // VOLUME -79...0 dB (int 0...79)
private:
void writeWire(char a);
};
#endif // PT2322_H
PT2322.cpp
#include <Arduino.h>
#include <Wire.h>
#include "PT2322.h"
PT2322::PT2322(){
Wire.begin();
}
void PT2322::setFront_lk_att(int f_lk_att){
writeWire(f_lk_att + 0b00010000);
}
void PT2322::setFront_rk_att(int f_rk_att){
writeWire(f_rk_att + 0b00100000);
}
void PT2322::setCenter_att(int c_att){
writeWire(c_att + 0b00110000);
}
void PT2322::setRear_lk_att(int r_lk_att){
writeWire(r_lk_att + 0b01000000);
}
void PT2322::setRear_rk_att(int r_rk_att){
writeWire(r_rk_att + 0b01010000);
}
void PT2322::setSub_att(int sub_att){
writeWire(sub_att + 0b01100000);
}
void PT2322::setFunc(int mute, int ddd, int tembr){
switch(mute){
case 0: mute = 0b00000000; break;
case 1: mute = 0b00001000; break;
}
switch(ddd){
case 0: ddd = 0b00000000; break;
case 1: ddd = 0b00000100; break;
}
switch(tembr){
case 0: tembr = 0b00000000; break;
case 1: tembr = 0b00000010; break;
}
writeWire(0b01110000 + mute + ddd + tembr);
}
void PT2322::setBass(int bass){
switch(bass){
case -7: bass = 0b00000000; break;
case -6: bass = 0b00000001; break;
case -5: bass = 0b00000010; break;
case -4: bass = 0b00000011; break;
case -3: bass = 0b00000100; break;
case -2: bass = 0b00000101; break;
case -1: bass = 0b00000110; break;
case 0: bass = 0b00000111; break;
case 7: bass = 0b00001000; break;
case 6: bass = 0b00001001; break;
case 5: bass = 0b00001010; break;
case 4: bass = 0b00001011; break;
case 3: bass = 0b00001100; break;
case 2: bass = 0b00001101; break;
case 1: bass = 0b00001110; break;
}
writeWire(0b10010000 + bass);
}
void PT2322::setMiddle(int mid){
switch(mid){
case -7: mid = 0b00000000; break;
case -6: mid = 0b00000001; break;
case -5: mid = 0b00000010; break;
case -4: mid = 0b00000011; break;
case -3: mid = 0b00000100; break;
case -2: mid = 0b00000101; break;
case -1: mid = 0b00000110; break;
case 0: mid = 0b00000111; break;
case 7: mid = 0b00001000; break;
case 6: mid = 0b00001001; break;
case 5: mid = 0b00001010; break;
case 4: mid = 0b00001011; break;
case 3: mid = 0b00001100; break;
case 2: mid = 0b00001101; break;
case 1: mid = 0b00001110; break;
}
writeWire(0b10100000 + mid);
}
void PT2322::setTreble(int treb){
switch(treb){
case -7: treb = 0b00000000; break;
case -6: treb = 0b00000001; break;
case -5: treb = 0b00000010; break;
case -4: treb = 0b00000011; break;
case -3: treb = 0b00000100; break;
case -2: treb = 0b00000101; break;
case -1: treb = 0b00000110; break;
case 0: treb = 0b00000111; break;
case 7: treb = 0b00001000; break;
case 6: treb = 0b00001001; break;
case 5: treb = 0b00001010; break;
case 4: treb = 0b00001011; break;
case 3: treb = 0b00001100; break;
case 2: treb = 0b00001101; break;
case 1: treb = 0b00001110; break;
}
writeWire(0b10110000 + treb);
}
void PT2322::setVol(int vol){
vol = vol - 78;
vol = abs(vol);
int vol_10 = vol / 10;
int vol_1 = vol - vol_10 * 10;
writeWire(vol_10 + 0b11100000);
writeWire(vol_1 + 0b11010000);
}
void PT2322::writeWire(char a){
Wire.beginTransmission(PT2322_address);
// Wire.write (0b11111111); // очистка регистра
Wire.write (0b11000111); // активация входов
Wire.write (0b00000000);
Wire.write (a);
Wire.endTransmission();
}
PT2322.ino
#include <Wire.h>
#include <PT2322.h>
PT2322 pt1;
void setup(){}
void loop(){
audio();
delay(1000);
}
void audio(){
pt1.setFront_lk_att(0);// att front L
pt1.setFront_rk_att(0);// att front R
pt1.setCenter_att(0); // att center
pt1.setRear_lk_att(0); // att rear L
pt1.setRear_rk_att(0); // att rear R
pt1.setSub_att(0); // att sub
// int -7...7 = -14...+14 dB
pt1.setFunc(0,0,0);// FUNC:
// mute - 0 выкл, 1 вкл
// 3d - 0 вкл, 1 выкл
// тембр - 0 вкл, 1 выкл
// (int 0,0,0) - по умолчанию
pt1.setBass(0); // BASS -14...0...14 dB (int -7...0...7)
pt1.setMiddle(0); // MIDDLE -14...0...14 dB (int -7...0...7)
pt1.setTreble(0); // TREBLE -14...0...14 dB (int -7...0...7)
pt1.setVol(65); // 0...79
}