Тема: PT2259
Протестировано!!!
PT2259 is an 8-pin 2-channel volume controller which utilizes CMOS technology and incorporates the I2C interface control. The controller features an attenuation range of 0 to -79dB, low noise output, a high degree of stereo separation and requires only a small number of external components. PT2259 is an essential component for modern audio visual systems.
Данный контент доступен только зарегистрированным пользователям.
• Attenuation range: 0 to -79dB in 1dB steps
• Operating voltage: 4 to 10V
• Low power consumption
• Low signal noise: S/N > 100dB (A-weighting)
• Stereo separation > 100dB
• Requires few external components
• 2-channel volume individual adjust
• Available in 8 Pins DIP or SOP
Библиотека - https://github.com/liman324/PT2259.git
PT2259.ino
#include <Wire.h>
#include <PT2259.h>
PT2259 pt;
void setup(){
audio();
}
void loop(){}
void audio(){
pt.setVol_ch2(0, 79); // mute, vol
// mute on === 1
// mute off === 0
// vol === -79...0 dB === int 0...79
// channel-by-channel adjustment
// pt.setVol_left(0, 79);
// pt.setVol_right(0, 79);
}
PT2259.h
#ifndef PT2259_H
#define PT2259_H
#define PT2259_address 0b1000100
//Sub addresses
#define CLEAR 0xF0
#define MUTE_OFF 0x74
#define MUTE_ON 0x77
#define MUTE_R 0x75
#define MUTE_L 0x76
#define CH2_1 0b11010000
#define CH2_10 0b11100000
#define LEFT_1 0b10100000
#define LEFT_10 0b10110000
#define RIGHT_1 0b00100000
#define RIGHT_10 0b00110000
#include <Arduino.h>
class PT2259{
public:
PT2259();
void setVol_ch2(bool mute, int vol_ch);
void setVol_left(bool mute, int vol_l);
void setVol_right(bool mute, int vol_r);
void clear();
private:
void writeWire(int8_t a, int8_t b, int8_t c);
};
#endif //PT2259_H
PT2259.cpp
#include <Arduino.h>
#include <Wire.h>
#include "PT2259.h"
PT2259::PT2259(){
Wire.begin();
}
void PT2259::setVol_ch2(bool mute, int vol_ch){
vol_ch = 79 - vol_ch;
byte vol_ch_10 = vol_ch/10;
byte vol_ch_1 = vol_ch%10;
if(mute==0){writeWire(MUTE_OFF, CH2_10+vol_ch_10, CH2_1+vol_ch_1);}
if(mute==1){writeWire(MUTE_ON, CH2_10+vol_ch_10, CH2_1+vol_ch_1);}
}
void PT2259::setVol_left(bool mute, int vol_l){
vol_l = 79 - vol_l;
byte vol_l_10 = vol_l/10;
byte vol_l_1 = vol_l%10;
if(mute==0){writeWire(MUTE_OFF, LEFT_10+vol_l_10, LEFT_1+vol_l_1);}
if(mute==1){writeWire(MUTE_L, LEFT_10+vol_l_10, LEFT_1+vol_l_1);}
}
void PT2259::setVol_right(bool mute, int vol_r){
vol_r = 79 - vol_r;
byte vol_r_10 = vol_r/10;
byte vol_r_1 = vol_r%10;
if(mute==0){writeWire(MUTE_OFF, RIGHT_10+vol_r_10, RIGHT_1+vol_r_1);}
if(mute==1){writeWire(MUTE_R, RIGHT_10+vol_r_10, RIGHT_1+vol_r_1);}
}
void PT2259::clear(){
Wire.beginTransmission(PT2259_address);
Wire.write (CLEAR);// clear
Wire.endTransmission();
}
void PT2259::writeWire(int8_t a, int8_t b, int8_t c){
Wire.beginTransmission(PT2259_address);
Wire.write (CLEAR);// clear
Wire.write (a); // mute
Wire.write (b); // 10 dB
Wire.write (c); // 1 dB
Wire.endTransmission();
}
Скетч использует 2034 байт (6%) памяти устройства. Всего доступно 32256 байт.
Глобальные переменные используют 219 байт (10%) динамической памяти, оставляя 1829 байт для локальных переменных. Максимум: 2048 байт.