Тема: TDA7448 — шести канальный регулятор громкости (Arduino)
Основная статья - http://rcl-radio.ru/?p=65647
Доработка - общий регулятор громкости + 6-и канальный аттенюатор от -20 до 0 дБ.
Версия с LCD1602_I2C
#include <Wire.h>
#include <MsTimer2.h>
//#include <LiquidCrystal.h>
#include <LiquidCrystal_I2C.h> // http://forum.rcl-radio.ru/misc.php?action=pan_download&item=45&download=1
LiquidCrystal_I2C lcd(0x27,16,2);
#include <Encoder.h>
#include <EEPROM.h>
#include <TDA7448.h>
TDA7448 tda;
Encoder myEnc(9, 8);//CLK, DT подключение энкодера
//LiquidCrystal lcd(7, 6, 2, 3, 4, 5);// RS,E,D4,D5,D6,D7 подключение LCD
byte a1[8]={0b00000,0b10101,0b10101,0b10101,0b10101,0b10101,0b10101,0b00000};
byte a2[8]={0b00000,0b10100,0b10100,0b10100,0b10100,0b10100,0b10100,0b00000};
byte a3[8]={0b00000,0b10000,0b10000,0b10000,0b10000,0b10000,0b10000,0b00000};
unsigned long newPosition,time,oldPosition = -999;
int vol1,vol2,vol3,vol4,vol5,vol6,vol1_d,vol2_d,vol3_d,vol4_d,vol5_d,vol6_d,vol,vol_d;
int w,w2,menu,z,z0,z1;
void setup(){Serial.begin(9600);
Wire.begin(); lcd.init();lcd.backlight();
lcd.begin(16, 2);
lcd.createChar(0,a1);lcd.createChar(1,a2);lcd.createChar(2,a3);
vol1 = -EEPROM.read(0);
vol2 = -EEPROM.read(1);
vol3 = -EEPROM.read(2);
vol4 = -EEPROM.read(3);
vol5 = -EEPROM.read(4);
vol6 = -EEPROM.read(5);
vol = -EEPROM.read(6);
pinMode(7,INPUT);// КНОПКА ЭНКОДЕРA
MsTimer2::set(3, to_Timer);MsTimer2::start();
lcd.setCursor(0,0);lcd.print(" TDA7448 ");delay(1000);lcd.clear();audio_tda();
}
void loop(){
if(digitalRead(7)==LOW){menu++;cl();myEnc.write(0);time=millis();w=1;w2=1;if(menu>6){menu=0;}}// меню
if(menu==0){
if (newPosition != oldPosition) {
oldPosition = newPosition;
vol=vol+newPosition;myEnc.write(0);newPosition=0;time=millis();w=1;w2=1;if(vol>0){vol=0;}if(vol<-59){vol=-59;}audio_tda();}
lcd.setCursor(0,0);lcd.print("VOLUME ");
lcd.print(" ");lcd.print(vol);lcd.print(" ");lcd.setCursor(13,0);lcd.print("dB");vol_d=map(vol,-59,0,0,48);
if(w2==1){
for(z=0,z0=0,z1=0;z<=vol_d;z++,z1++){if(z1>2){z1=0;z0++;}
if(z1==1){lcd.setCursor(z0,1);lcd.write((uint8_t)0);lcd.setCursor(z0+1,1);lcd.print(" ");}}
if(z1==3){lcd.setCursor(z0,1);lcd.write((uint8_t)1);}
if(z1==2){lcd.setCursor(z0,1);lcd.write((uint8_t)2);}w2=0;}}
/////////////////////////////////////////////////
if(menu==1){
if (newPosition != oldPosition) {
oldPosition = newPosition;
vol1=vol1+newPosition;myEnc.write(0);newPosition=0;time=millis();w=1;w2=1;if(vol1>0){vol1=0;}if(vol1<-20){vol1=-20;}audio_tda();}
lcd.setCursor(0,0);lcd.print("FRONT R ");
lcd.print(" ");lcd.print(vol1);lcd.print(" ");lcd.setCursor(13,0);lcd.print("dB");vol1_d=map(vol1,-20,0,0,20);
if(w2==1){
for(z=0,z0=0,z1=0;z<=vol1_d;z++,z1++){if(z1>2){z1=0;z0++;}
if(z1==1){lcd.setCursor(z0+4,1);lcd.write((uint8_t)0);lcd.setCursor(z0+1+4,1);lcd.print(" ");}}
if(z1==3){lcd.setCursor(z0+4,1);lcd.write((uint8_t)1);}
if(z1==2){lcd.setCursor(z0+4,1);lcd.write((uint8_t)2);}w2=0;}}
if(menu==2){
if (newPosition != oldPosition) {
oldPosition = newPosition;
vol2=vol2+newPosition;myEnc.write(0);newPosition=0;time=millis();w=1;w2=1;if(vol2>0){vol2=0;}if(vol2<-20){vol2=-20;}audio_tda();}
lcd.setCursor(0,0);lcd.print("FRONT L ");
lcd.print(" ");lcd.print(vol2);lcd.print(" ");lcd.setCursor(13,0);lcd.print("dB");vol2_d=map(vol2,-20,0,0,20);
if(w2==1){
for(z=0,z0=0,z1=0;z<=vol2_d;z++,z1++){if(z1>2){z1=0;z0++;}
if(z1==1){lcd.setCursor(z0+4,1);lcd.write((uint8_t)0);lcd.setCursor(z0+1+4,1);lcd.print(" ");}}
if(z1==3){lcd.setCursor(z0+4,1);lcd.write((uint8_t)1);}
if(z1==2){lcd.setCursor(z0+4,1);lcd.write((uint8_t)2);}w2=0;}}
if(menu==3){
if (newPosition != oldPosition) {
oldPosition = newPosition;
vol3=vol3+newPosition;myEnc.write(0);newPosition=0;time=millis();w=1;w2=1;if(vol3>0){vol3=0;}if(vol3<-20){vol3=-20;}audio_tda();}
lcd.setCursor(0,0);lcd.print("REAR R ");
lcd.print(" ");lcd.print(vol3);lcd.print(" ");lcd.setCursor(13,0);lcd.print("dB");vol3_d=map(vol3,-20,0,0,20);
if(w2==1){
for(z=0,z0=0,z1=0;z<=vol3_d;z++,z1++){if(z1>2){z1=0;z0++;}
if(z1==1){lcd.setCursor(z0+4,1);lcd.write((uint8_t)0);lcd.setCursor(z0+1+4,1);lcd.print(" ");}}
if(z1==3){lcd.setCursor(z0+4,1);lcd.write((uint8_t)1);}
if(z1==2){lcd.setCursor(z0+4,1);lcd.write((uint8_t)2);}w2=0;}}
if(menu==4){
if (newPosition != oldPosition) {
oldPosition = newPosition;
vol4=vol4+newPosition;myEnc.write(0);newPosition=0;time=millis();w=1;w2=1;if(vol4>0){vol4=0;}if(vol4<-20){vol4=-20;}audio_tda();}
lcd.setCursor(0,0);lcd.print("REAR L ");
lcd.print(" ");lcd.print(vol4);lcd.print(" ");lcd.setCursor(13,0);lcd.print("dB");vol4_d=map(vol4,-20,0,0,20);
if(w2==1){
for(z=0,z0=0,z1=0;z<=vol4_d;z++,z1++){if(z1>2){z1=0;z0++;}
if(z1==1){lcd.setCursor(z0+4,1);lcd.write((uint8_t)0);lcd.setCursor(z0+1+4,1);lcd.print(" ");}}
if(z1==3){lcd.setCursor(z0+4,1);lcd.write((uint8_t)1);}
if(z1==2){lcd.setCursor(z0+4,1);lcd.write((uint8_t)2);}w2=0;}}
if(menu==5){
if (newPosition != oldPosition) {
oldPosition = newPosition;
vol5=vol5+newPosition;myEnc.write(0);newPosition=0;time=millis();w=1;w2=1;if(vol5>0){vol5=0;}if(vol5<-20){vol5=-20;}audio_tda();}
lcd.setCursor(0,0);lcd.print("CENTER ");
lcd.print(" ");lcd.print(vol5);lcd.print(" ");lcd.setCursor(13,0);lcd.print("dB");vol5_d=map(vol5,-20,0,0,20);
if(w2==1){
for(z=0,z0=0,z1=0;z<=vol5_d;z++,z1++){if(z1>2){z1=0;z0++;}
if(z1==1){lcd.setCursor(z0+4,1);lcd.write((uint8_t)0);lcd.setCursor(z0+1+4,1);lcd.print(" ");}}
if(z1==3){lcd.setCursor(z0+4,1);lcd.write((uint8_t)1);}
if(z1==2){lcd.setCursor(z0+4,1);lcd.write((uint8_t)2);}w2=0;}}
if(menu==6){
if (newPosition != oldPosition) {
oldPosition = newPosition;
vol6=vol6+newPosition;myEnc.write(0);newPosition=0;time=millis();w=1;w2=1;if(vol6>0){vol6=0;}if(vol6<-20){vol6=-20;}audio_tda();}
lcd.setCursor(0,0);lcd.print("SUBW ");
lcd.print(" ");lcd.print(vol6);lcd.print(" ");lcd.setCursor(13,0);lcd.print("dB");vol6_d=map(vol6,-20,0,0,20);
if(w2==1){
for(z=0,z0=0,z1=0;z<=vol6_d;z++,z1++){if(z1>2){z1=0;z0++;}
if(z1==1){lcd.setCursor(z0+4,1);lcd.write((uint8_t)0);lcd.setCursor(z0+1+4,1);lcd.print(" ");}}
if(z1==3){lcd.setCursor(z0+4,1);lcd.write((uint8_t)1);}
if(z1==2){lcd.setCursor(z0+4,1);lcd.write((uint8_t)2);}w2=0;}}
if(millis()-time>10000 && w==1){
EEPROM.update(0,abs(vol1));
EEPROM.update(1,abs(vol2));
EEPROM.update(2,abs(vol3));
EEPROM.update(3,abs(vol4));
EEPROM.update(4,abs(vol5));
EEPROM.update(5,abs(vol6));
EEPROM.update(6,abs(vol));
if(menu!=0){lcd.clear();}menu=0;w2=1;
w=0;}
}
void audio_tda(){
tda.setAtt(1,vol+vol1); // 0 макс громк, -79(79) мин громк
tda.setAtt(2,vol+vol2);
tda.setAtt(3,vol+vol3);
tda.setAtt(4,vol+vol4);
tda.setAtt(5,vol+vol5);
tda.setAtt(6,vol+vol6);
Serial.println(vol+vol1);
}
void cl(){delay(300);lcd.clear();}
void to_Timer(){newPosition = myEnc.read()/4;}
Версия с параллельным подключением LCD1602
#include <Wire.h>
#include <MsTimer2.h>
#include <LiquidCrystal.h>
#include <Encoder.h>
#include <EEPROM.h>
#include <TDA7448.h>
TDA7448 tda;
Encoder myEnc(9, 8);//CLK, DT подключение энкодера
LiquidCrystal lcd(7, 6, 2, 3, 4, 5);// RS,E,D4,D5,D6,D7 подключение LCD
byte a1[8]={0b00000,0b10101,0b10101,0b10101,0b10101,0b10101,0b10101,0b00000};
byte a2[8]={0b00000,0b10100,0b10100,0b10100,0b10100,0b10100,0b10100,0b00000};
byte a3[8]={0b00000,0b10000,0b10000,0b10000,0b10000,0b10000,0b10000,0b00000};
unsigned long newPosition,time,oldPosition = -999;
int vol1,vol2,vol3,vol4,vol5,vol6,vol1_d,vol2_d,vol3_d,vol4_d,vol5_d,vol6_d,vol,vol_d;
int w,w2,menu,z,z0,z1;
void setup(){Serial.begin(9600);
Wire.begin();
lcd.begin(16, 2);
lcd.createChar(0,a1);lcd.createChar(1,a2);lcd.createChar(2,a3);
vol1 = -EEPROM.read(0);
vol2 = -EEPROM.read(1);
vol3 = -EEPROM.read(2);
vol4 = -EEPROM.read(3);
vol5 = -EEPROM.read(4);
vol6 = -EEPROM.read(5);
vol = -EEPROM.read(6);
pinMode(10,INPUT);// КНОПКА ЭНКОДЕРA
MsTimer2::set(3, to_Timer);MsTimer2::start();
lcd.setCursor(0,0);lcd.print(" TDA7448 ");delay(1000);lcd.clear();audio_tda();
}
void loop(){
if(digitalRead(10)==LOW){menu++;cl();myEnc.write(0);time=millis();w=1;w2=1;if(menu>6){menu=0;}}// меню
if(menu==0){
if (newPosition != oldPosition) {
oldPosition = newPosition;
vol=vol+newPosition;myEnc.write(0);newPosition=0;time=millis();w=1;w2=1;if(vol>0){vol=0;}if(vol<-59){vol=-59;}audio_tda();}
lcd.setCursor(0,0);lcd.print("VOLUME ");
lcd.print(" ");lcd.print(vol);lcd.print(" ");lcd.setCursor(13,0);lcd.print("dB");vol_d=map(vol,-59,0,0,48);
if(w2==1){
for(z=0,z0=0,z1=0;z<=vol_d;z++,z1++){if(z1>2){z1=0;z0++;}
if(z1==1){lcd.setCursor(z0,1);lcd.write((uint8_t)0);lcd.setCursor(z0+1,1);lcd.print(" ");}}
if(z1==3){lcd.setCursor(z0,1);lcd.write((uint8_t)1);}
if(z1==2){lcd.setCursor(z0,1);lcd.write((uint8_t)2);}w2=0;}}
/////////////////////////////////////////////////
if(menu==1){
if (newPosition != oldPosition) {
oldPosition = newPosition;
vol1=vol1+newPosition;myEnc.write(0);newPosition=0;time=millis();w=1;w2=1;if(vol1>0){vol1=0;}if(vol1<-20){vol1=-20;}audio_tda();}
lcd.setCursor(0,0);lcd.print("FRONT R ");
lcd.print(" ");lcd.print(vol1);lcd.print(" ");lcd.setCursor(13,0);lcd.print("dB");vol1_d=map(vol1,-20,0,0,20);
if(w2==1){
for(z=0,z0=0,z1=0;z<=vol1_d;z++,z1++){if(z1>2){z1=0;z0++;}
if(z1==1){lcd.setCursor(z0+4,1);lcd.write((uint8_t)0);lcd.setCursor(z0+1+4,1);lcd.print(" ");}}
if(z1==3){lcd.setCursor(z0+4,1);lcd.write((uint8_t)1);}
if(z1==2){lcd.setCursor(z0+4,1);lcd.write((uint8_t)2);}w2=0;}}
if(menu==2){
if (newPosition != oldPosition) {
oldPosition = newPosition;
vol2=vol2+newPosition;myEnc.write(0);newPosition=0;time=millis();w=1;w2=1;if(vol2>0){vol2=0;}if(vol2<-20){vol2=-20;}audio_tda();}
lcd.setCursor(0,0);lcd.print("FRONT L ");
lcd.print(" ");lcd.print(vol2);lcd.print(" ");lcd.setCursor(13,0);lcd.print("dB");vol2_d=map(vol2,-20,0,0,20);
if(w2==1){
for(z=0,z0=0,z1=0;z<=vol2_d;z++,z1++){if(z1>2){z1=0;z0++;}
if(z1==1){lcd.setCursor(z0+4,1);lcd.write((uint8_t)0);lcd.setCursor(z0+1+4,1);lcd.print(" ");}}
if(z1==3){lcd.setCursor(z0+4,1);lcd.write((uint8_t)1);}
if(z1==2){lcd.setCursor(z0+4,1);lcd.write((uint8_t)2);}w2=0;}}
if(menu==3){
if (newPosition != oldPosition) {
oldPosition = newPosition;
vol3=vol3+newPosition;myEnc.write(0);newPosition=0;time=millis();w=1;w2=1;if(vol3>0){vol3=0;}if(vol3<-20){vol3=-20;}audio_tda();}
lcd.setCursor(0,0);lcd.print("REAR R ");
lcd.print(" ");lcd.print(vol3);lcd.print(" ");lcd.setCursor(13,0);lcd.print("dB");vol3_d=map(vol3,-20,0,0,20);
if(w2==1){
for(z=0,z0=0,z1=0;z<=vol3_d;z++,z1++){if(z1>2){z1=0;z0++;}
if(z1==1){lcd.setCursor(z0+4,1);lcd.write((uint8_t)0);lcd.setCursor(z0+1+4,1);lcd.print(" ");}}
if(z1==3){lcd.setCursor(z0+4,1);lcd.write((uint8_t)1);}
if(z1==2){lcd.setCursor(z0+4,1);lcd.write((uint8_t)2);}w2=0;}}
if(menu==4){
if (newPosition != oldPosition) {
oldPosition = newPosition;
vol4=vol4+newPosition;myEnc.write(0);newPosition=0;time=millis();w=1;w2=1;if(vol4>0){vol4=0;}if(vol4<-20){vol4=-20;}audio_tda();}
lcd.setCursor(0,0);lcd.print("REAR L ");
lcd.print(" ");lcd.print(vol4);lcd.print(" ");lcd.setCursor(13,0);lcd.print("dB");vol4_d=map(vol4,-20,0,0,20);
if(w2==1){
for(z=0,z0=0,z1=0;z<=vol4_d;z++,z1++){if(z1>2){z1=0;z0++;}
if(z1==1){lcd.setCursor(z0+4,1);lcd.write((uint8_t)0);lcd.setCursor(z0+1+4,1);lcd.print(" ");}}
if(z1==3){lcd.setCursor(z0+4,1);lcd.write((uint8_t)1);}
if(z1==2){lcd.setCursor(z0+4,1);lcd.write((uint8_t)2);}w2=0;}}
if(menu==5){
if (newPosition != oldPosition) {
oldPosition = newPosition;
vol5=vol5+newPosition;myEnc.write(0);newPosition=0;time=millis();w=1;w2=1;if(vol5>0){vol5=0;}if(vol5<-20){vol5=-20;}audio_tda();}
lcd.setCursor(0,0);lcd.print("CENTER ");
lcd.print(" ");lcd.print(vol5);lcd.print(" ");lcd.setCursor(13,0);lcd.print("dB");vol5_d=map(vol5,-20,0,0,20);
if(w2==1){
for(z=0,z0=0,z1=0;z<=vol5_d;z++,z1++){if(z1>2){z1=0;z0++;}
if(z1==1){lcd.setCursor(z0+4,1);lcd.write((uint8_t)0);lcd.setCursor(z0+1+4,1);lcd.print(" ");}}
if(z1==3){lcd.setCursor(z0+4,1);lcd.write((uint8_t)1);}
if(z1==2){lcd.setCursor(z0+4,1);lcd.write((uint8_t)2);}w2=0;}}
if(menu==6){
if (newPosition != oldPosition) {
oldPosition = newPosition;
vol6=vol6+newPosition;myEnc.write(0);newPosition=0;time=millis();w=1;w2=1;if(vol6>0){vol6=0;}if(vol6<-20){vol6=-20;}audio_tda();}
lcd.setCursor(0,0);lcd.print("SUBW ");
lcd.print(" ");lcd.print(vol6);lcd.print(" ");lcd.setCursor(13,0);lcd.print("dB");vol6_d=map(vol6,-20,0,0,20);
if(w2==1){
for(z=0,z0=0,z1=0;z<=vol6_d;z++,z1++){if(z1>2){z1=0;z0++;}
if(z1==1){lcd.setCursor(z0+4,1);lcd.write((uint8_t)0);lcd.setCursor(z0+1+4,1);lcd.print(" ");}}
if(z1==3){lcd.setCursor(z0+4,1);lcd.write((uint8_t)1);}
if(z1==2){lcd.setCursor(z0+4,1);lcd.write((uint8_t)2);}w2=0;}}
if(millis()-time>10000 && w==1){
EEPROM.update(0,abs(vol1));
EEPROM.update(1,abs(vol2));
EEPROM.update(2,abs(vol3));
EEPROM.update(3,abs(vol4));
EEPROM.update(4,abs(vol5));
EEPROM.update(5,abs(vol6));
EEPROM.update(6,abs(vol));
if(menu!=0){lcd.clear();}menu=0;w2=1;
w=0;}
}
void audio_tda(){
tda.setAtt(1,vol+vol1); // 0 макс громк, -79(79) мин громк
tda.setAtt(2,vol+vol2);
tda.setAtt(3,vol+vol3);
tda.setAtt(4,vol+vol4);
tda.setAtt(5,vol+vol5);
tda.setAtt(6,vol+vol6);
Serial.println(vol+vol1);
}
void cl(){delay(300);lcd.clear();}
void to_Timer(){newPosition = myEnc.read()/4;}