Тема: Аудиопроцессор TDA7313 + LCD дисплей 84×48 Nokia 5110
Библиотеки:
http://rcl-radio.ru/wp-content/uploads/ … 8544-2.zip
http://rcl-radio.ru/wp-content/uploads/ … Timer2.zip
http://rcl-radio.ru/wp-content/uploads/ … ncoder.zip
http://rcl-radio.ru/wp-content/uploads/ … 7313-1.zip
#include <Wire.h>
#include <SPI.h>
#include <PCD8544.h>
#include <EEPROM.h>
#include <MsTimer2.h>
#include <Encoder.h>
#include <TDA7313.h>
TDA7313 tda;
Encoder myEnc(9, 8);//CLK, DT подключение энкодера
PCD8544 lcd; // RST,CE,DC,DIN,CLK VCC,BL,GND (3,4,5,6,7 +3.3V,200 OM +3.3V, GND)
static const byte asd[] = { B00111100,B00000000,B00000000,B00000000,B00000000 };
static const byte asd1[] = { B00111100,B00111100,B00111100,B0000000,B11111111 };
static const byte asd2[] = { B00111100,B00111100,B00111100,B0000000,B00111100 };
unsigned long newPosition,time,oldPosition = -999;
int i,w=1,w1=1,w2=1,menu,vol,lr,rr,lf,rf,in,loud,gain,bass,treb,eeprom;
void setup() {
Serial.begin(9600);Wire.begin();
lcd.begin(84, 48);
lcd.setContrast(120);// контрастность 0-127
pinMode(10,INPUT);// SW кнопка энкодера
lcd.createChar(0, asd); lcd.createChar(1, asd1);lcd.createChar(2, asd2);
MsTimer2::set(1, to_Timer);MsTimer2::start();
vol = EEPROM.read(0);bass = EEPROM.read(1)-7;treb = EEPROM.read(2)-7;in = EEPROM.read(3);
loud = EEPROM.read(7);lr = EEPROM.read(8);rr = EEPROM.read(9);lf = EEPROM.read(10);rf = EEPROM.read(11);
audio();
}
void loop() {
if(digitalRead(10)==LOW){menu++;w=1;w1=1;w2=1;myEnc.write(0);time=millis();eeprom=1;delay(200);if(menu>8){menu=0;}}
////////////////////////////// vol ///////////////////////////////////////////////////////
if(menu==0){
if (newPosition != oldPosition) {
oldPosition = newPosition;
vol=vol+newPosition;myEnc.write(0);newPosition=0;time=millis();w=1;if(vol>63){vol=63;}if(vol<0){vol=0;}audio();}
}
if(w==1){w=0;
lcd.setCursor(0,0);lcd.print("}P");
for(i=15;i<68;i++){lcd.setCursor(i,0);lcd.write(0);}
lcd.setCursor(vol/1.3+15,0);if(menu==0){lcd.write(1);}else{lcd.write(2);}lcd.setCursor(72,0);if(vol<10){lcd.print(" ");}lcd.print(vol);
}
///////////////////////////////////////// bass ///////////////////////////////////
if(menu==1){
if (newPosition != oldPosition) {
oldPosition = newPosition;
bass=bass+newPosition;myEnc.write(0);newPosition=0;time=millis();w1=1;if(bass>7){bass=7;}if(bass<-7){bass=-7;}audio();}
}
if(w1==1){w1=0;
lcd.setCursor(0,1);lcd.print("H'");
for(i=8;i<60;i=i+1){lcd.setCursor(i+7,1);lcd.write(0);}
lcd.setCursor(bass*3+37,1);if(menu==1){lcd.write(1);}else{lcd.write(2);}lcd.setCursor(72,1);if(bass<10&&bass>=0){lcd.print(" ");}lcd.print(bass);
}
//////////////////////////////////////////// treble /////////////////////////////
if(menu==2){
if (newPosition != oldPosition) {
oldPosition = newPosition;
treb=treb+newPosition;myEnc.write(0);newPosition=0;time=millis();w2=1;if(treb>7){treb=7;}if(treb<-7){treb=-7;}audio();}
}
if(w2==1){w2=0;
lcd.setCursor(0,2);lcd.print("B'");
for(i=8;i<60;i=i+1){lcd.setCursor(i+7,2);lcd.write(0);}
lcd.setCursor(treb*3+37,2);if(menu==2){lcd.write(1);}else{lcd.write(2);}lcd.setCursor(72,2);if(treb<10&&treb>=0){lcd.print(" ");}lcd.print(treb);
}
/////////////////////// att LR //////////////////////////////////////////////////////
if(menu==3){
if (newPosition != oldPosition) {
oldPosition = newPosition;
lr=lr+newPosition;myEnc.write(0);newPosition=0;time=millis();if(lr>31){lr=31;}if(lr<0){lr=0;}audio();}
lcd.setCursor(0,3);lcd.print("+LR ");lcd.print(lr);lcd.print(" ");}else{lcd.setCursor(0,3);lcd.print(" LR ");lcd.print(lr);lcd.print(" ");}
/////////////////////// att RR //////////////////////////////////////////////////////
if(menu==4){
if (newPosition != oldPosition) {
oldPosition = newPosition;
rr=rr+newPosition;myEnc.write(0);newPosition=0;time=millis();if(rr>31){rr=31;}if(rr<0){rr=0;}audio();}
lcd.setCursor(44,3);lcd.print("+RR ");lcd.print(rr);lcd.print(" ");}else{lcd.setCursor(44,3);lcd.print(" RR ");lcd.print(rr);lcd.print(" ");}
/////////////////////// att LF //////////////////////////////////////////////////////
if(menu==5){
if (newPosition != oldPosition) {
oldPosition = newPosition;
lf=lf+newPosition;myEnc.write(0);newPosition=0;time=millis();if(lf>31){lf=31;}if(lf<0){lf=0;}audio();}
lcd.setCursor(0,4);lcd.print("+LF ");lcd.print(lf);lcd.print(" ");}else{lcd.setCursor(0,4);lcd.print(" LF ");lcd.print(lf);lcd.print(" ");}
/////////////////////// att RF //////////////////////////////////////////////////////
if(menu==6){
if (newPosition != oldPosition) {
oldPosition = newPosition;
rf=rf+newPosition;myEnc.write(0);newPosition=0;time=millis();if(rf>31){rf=31;}if(rf<0){rf=0;}audio();}
lcd.setCursor(44,4);lcd.print("+RF ");lcd.print(rf);lcd.print(" ");}else{lcd.setCursor(44,4);lcd.print(" RF ");lcd.print(rf);lcd.print(" ");}
///////////////////////IN //////////////////////////////////////////////////////
if(menu==7){
if (newPosition != oldPosition) {
oldPosition = newPosition;
in=in+newPosition;myEnc.write(0);newPosition=0;time=millis();if(in>2){in=2;}if(in<0){in=0;}audio();}
lcd.setCursor(0,5);lcd.print("+IN ");lcd.print(in+1);lcd.print(" ");}else{lcd.setCursor(0,5);lcd.print(" IN ");lcd.print(in+1);lcd.print(" ");}
/////////////////////// LOUDNESS //////////////////////////////////////////////////////
if(menu==8){
if (newPosition != oldPosition) {
oldPosition = newPosition;
loud=loud+newPosition;myEnc.write(0);newPosition=0;time=millis();if(loud>1){loud=1;}if(loud<0){loud=0;}audio();}
lcd.setCursor(44,5);lcd.print("+LD ");lcd.print(loud);lcd.print(" ");}else{lcd.setCursor(44,5);lcd.print(" LD ");lcd.print(loud);lcd.print(" ");}
///////////////////////////////////////////////////////////////////////////////////////
if(millis()-time>10000 && eeprom==1){
EEPROM.update(0,vol);
EEPROM.update(1,bass+7);
EEPROM.update(2,treb+7);
EEPROM.update(3,in);
EEPROM.update(7,loud);
EEPROM.update(8,lr);EEPROM.update(9,rr);EEPROM.update(10,lf);EEPROM.update(11,rf);
menu=0;eeprom=0;w=1;w1=1;w2=1;}
}
void cl(){delay(300);lcd.clear();}
void audio(){
tda.setVolume(vol); // громкость 0...63
tda.setAttLR(lr); // аттенюатор LR 0...31
tda.setAttRR(rr); // аттенюатор RR 0...31
tda.setAttLF(lf); // аттенюатор LF 0...31
tda.setAttRF(rf); // аттенюатор RF 0...31
tda.setSwitch(in,loud,3); // вход 0...2, тонкомпенсация 1 вкл 0 выкл, усиление 0...3
tda.setBass(bass); // тембр НЧ -7...+7
tda.setTreble(treb); // тембр ВЧ -7...+7
}
void to_Timer(){newPosition = myEnc.read()/4;}