Re: TDA7313 + энкодер + ИК пульт + анализатор спектра
Если будет возможность протестируйте пожалуйста скетч, в анализатор добавлено плавное понижение полос.
#define AUTO_GAIN 1 // автонастройка по громкости
#define VOL_THR 35 // порог тишины (ниже него отображения на матрице не будет)
#define LOW_PASS 30 // нижний порог чувствительности шумов (нет скачков при отсутствии звука)
#define DEF_GAIN 80 // максимальный порог по умолчанию
#define FHT_N 128 // ширина спектра х2
#define LOG_OUT 1
#include <FHT.h>
#include <Wire.h>
#include <MsTimer2.h>
#include <LiquidCrystal.h>
#include <Encoder.h>
#include <EEPROM.h>
#include <TDA7313.h>
#include <boarddefs.h>
#include <IRremote.h>
IRrecv irrecv(11); // указываем вывод модуля IR приемника
TDA7313 tda;decode_results ir;
Encoder myEnc(9, 8);//CLK, DT подключение энкодера
LiquidCrystal lcd(7, 6, 2, 3, 4, 5);// RS,E,D4,D5,D6,D7 подключение LCD
byte posOffset[20] = {2, 3, 4, 6, 8, 10, 12, 14, 16, 18, 20, 22, 24, 26, 28, 30, 32, 34, 36, 40}; // вч выше
// byte posOffset[16] = {2, 3, 4, 6, 8, 10, 12, 14, 16, 20, 25, 30, 35, 60, 80, 100};// вч ниже
unsigned long newPosition,time,time1,oldPosition = -999;
int vol,w1,w2=1,gr1,gr2,vol_d,menu,w,z,z0,z1,bass_d,bass,treb_d,treb,i,menu1,in,gain,gain1,gain2,gain3,loud,lr,rr,lf,rf;
unsigned long gainTimer;
byte maxValue, maxValue_f,spek;
float k = 0.1;
byte gain_sp = DEF_GAIN;
int i1,yyy;
int ek;
byte ur[8],urr[8];;
void setup(){
Serial.begin(9600);Wire.begin();irrecv.enableIRIn(); // запускаем модуль IR
lcd.begin(20, 4);
pinMode(10,INPUT);// КНОПКА ЭНКОДЕРA
pinMode(12,INPUT);// КНОПКА IN
pinMode(13,INPUT);
ADMUX = 0b01100000; ADCSRA = 0b11010100;
MsTimer2::set(3, to_Timer);MsTimer2::start();
vol = EEPROM.read(0);
bass = EEPROM.read(1)-7
;treb = EEPROM.read(2)-7;
in = EEPROM.read(3);
gain1 = EEPROM.read(4);
gain2 = EEPROM.read(5);
gain3 = EEPROM.read(6);
loud = EEPROM.read(7);
lr = EEPROM.read(8);
rr = EEPROM.read(9);
lf = EEPROM.read(10);
rf = EEPROM.read(11);
ek = EEPROM.read(12);
if(in==0){gain=gain1;}
if(in==1){gain=gain2;}
if(in==2){gain=gain3;}
lcd.setCursor(0,0);lcd.print(" TDA7313 ");
lcd.setCursor(0,1);lcd.print(" V3.0 ");
delay(1000);lcd.clear();audio();
}
void to_Timer(){newPosition = myEnc.read()/4;}
void loop(){
if(digitalRead(13)==HIGH){ek++;time=millis();w=1;delay(300);if(ek>5){ek=0;}}
if (newPosition != oldPosition) {if(spek==1){cl();menu=0;}}
if(spek==0){
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};
lcd.createChar(0,a1);lcd.createChar(1,a2);lcd.createChar(2,a3);
}else{
if(ek==0){
byte v1[8] = {0, 0, 0, 0, 0, 0, 0, 4};
byte v2[8] = {0, 0, 0, 0, 0, 0, 4, 4};
byte v3[8] = {0, 0, 0, 0, 0, 4, 4, 4};
byte v4[8] = {0, 0, 0, 0, 4, 4, 4, 4};
byte v5[8] = {0, 0, 0, 4, 4, 4, 4, 4};
byte v6[8] = {0, 0, 4, 4, 4, 4, 4, 4};
byte v7[8] = {0, 4, 4, 4, 4, 4, 4, 4};
byte v8[8] = {4, 4, 4, 4, 4, 4, 4, 4};
lcd.createChar(0, v1);lcd.createChar(1, v2);lcd.createChar(2, v3);lcd.createChar(3, v4);lcd.createChar(4, v5);lcd.createChar(5, v6);lcd.createChar(6, v7);lcd.createChar(7, v8);
}
if(ek==1){
byte v1[8] = {0, 0, 0, 0, 0, 0, 0, 14};
byte v2[8] = {0, 0, 0, 0, 0, 0, 14, 14};
byte v3[8] = {0, 0, 0, 0, 0, 14, 14, 14};
byte v4[8] = {0, 0, 0, 0, 14, 14, 14, 14};
byte v5[8] = {0, 0, 0, 14, 14, 14, 14, 14};
byte v6[8] = {0, 0, 14, 14, 14, 14, 14, 14};
byte v7[8] = {0, 14, 14, 14, 14, 14, 14, 14};
byte v8[8] = {14, 14, 14, 14, 14, 14, 14, 14};
lcd.createChar(0, v1);lcd.createChar(1, v2);lcd.createChar(2, v3);lcd.createChar(3, v4);lcd.createChar(4, v5);lcd.createChar(5, v6);lcd.createChar(6, v7);lcd.createChar(7, v8);
}
if(ek==2){
byte v1[8] = {0, 0, 0, 0, 0, 0, 0, 10};
byte v2[8] = {0, 0, 0, 0, 0, 0, 10, 10};
byte v3[8] = {0, 0, 0, 0, 0, 10, 10, 10};
byte v4[8] = {0, 0, 0, 0, 10, 10, 10, 10};
byte v5[8] = {0, 0, 0, 10, 10, 10, 10, 10};
byte v6[8] = {0, 0, 10, 10, 10, 10, 10, 10};
byte v7[8] = {0, 10, 10, 10, 10, 10, 10, 10};
byte v8[8] = {10, 10, 10, 10, 10, 10, 10, 10};
lcd.createChar(0, v1);lcd.createChar(1, v2);lcd.createChar(2, v3);lcd.createChar(3, v4);lcd.createChar(4, v5);lcd.createChar(5, v6);lcd.createChar(6, v7);lcd.createChar(7, v8);
}
if(ek==3){
byte v1[8] = {0, 0, 0, 0, 0, 0, 0, 27};
byte v2[8] = {0, 0, 0, 0, 0, 0, 27, 27};
byte v3[8] = {0, 0, 0, 0, 0, 27, 27, 27};
byte v4[8] = {0, 0, 0, 0, 27, 27, 27, 27};
byte v5[8] = {0, 0, 0, 27, 27, 27, 27, 27};
byte v6[8] = {0, 0, 27, 27, 27, 27, 27, 27};
byte v7[8] = {0, 27, 27, 27, 27, 27, 27, 27};
byte v8[8] = {27, 27, 27, 27, 27, 27, 27, 27};
lcd.createChar(0, v1);lcd.createChar(1, v2);lcd.createChar(2, v3);lcd.createChar(3, v4);lcd.createChar(4, v5);lcd.createChar(5, v6);lcd.createChar(6, v7);lcd.createChar(7, v8);
}
if(ek==4){
byte v1[8] = {0, 0, 0, 0, 0, 0, 0, 31};
byte v2[8] = {0, 0, 0, 0, 0, 0, 31, 31};
byte v3[8] = {0, 0, 0, 0, 0, 31, 31, 31};
byte v4[8] = {0, 0, 0, 0, 31, 31, 31, 31};
byte v5[8] = {0, 0, 0, 31, 31, 31, 31, 31};
byte v6[8] = {0, 0, 31, 31, 31, 31, 31, 31};
byte v7[8] = {0, 31, 31, 31, 31, 31, 31, 31};
byte v8[8] = {31, 31, 31, 31, 31, 31, 31, 31};
lcd.createChar(0, v1);lcd.createChar(1, v2);lcd.createChar(2, v3);lcd.createChar(3, v4);lcd.createChar(4, v5);lcd.createChar(5, v6);lcd.createChar(6, v7);lcd.createChar(7, v8);
}
if(ek==5){
byte v1[8] = {0, 0, 0, 0, 0, 0, 0, 21};
byte v2[8] = {0, 0, 0, 0, 0, 0, 21, 21};
byte v3[8] = {0, 0, 0, 0, 0, 21, 21, 21};
byte v4[8] = {0, 0, 0, 0, 21, 21, 21, 21};
byte v5[8] = {0, 0, 0, 21, 21, 21, 21, 21};
byte v6[8] = {0, 0, 21, 21, 21, 21, 21, 21};
byte v7[8] = {0, 21, 21, 21, 21, 21, 21, 21};
byte v8[8] = {21, 21, 21, 21, 21, 21, 21, 21};
lcd.createChar(0, v1);lcd.createChar(1, v2);lcd.createChar(2, v3);lcd.createChar(3, v4);lcd.createChar(4, v5);lcd.createChar(5, v6);lcd.createChar(6, v7);lcd.createChar(7, v8);
}
}
if ( irrecv.decode( &ir )) {Serial.print("0x");Serial.println( ir.value,HEX);time1=millis();time=millis();w=1;w1=1;if(spek==1){menu=0;cl();};irrecv.resume();}// IR приемник
if((digitalRead(10)==LOW)&&menu1==0){menu++;cl();myEnc.write(0);i++;time=millis();w=1;w2=1;if(menu>2){menu=0;}}// меню
if((digitalRead(10)==HIGH)){i=0;}if(i>3){cl();lcd.setCursor(5,1);lcd.print("*SETTINGS*");delay(500);cl();menu1=1;menu=100;}
if((digitalRead(10)==LOW)&&menu1>0){menu1++;cl();myEnc.write(0);time=millis();w=1;w2=1;if(menu1>6){cl();menu1=0;menu=0;}}// меню 1
if(ir.value==0x2FDD02F){menu++;gr1=0;gr2=0;cl();time=millis();w=1;w2=1;if(menu>2){menu=0;}}// меню кнопка вверх
if(ir.value==0x2FD32CD){menu--;gr1=0;gr2=0;cl();time=millis();w=1;w2=1;if(menu<0){menu=2;}}// меню кнопка вниз
if(ir.value==0x2FDEA15){in++;gr1=0;gr2=0;cl();time=millis();w=1;w2=1;if(in>2){in=0;}audio();lcd.setCursor(0,0);lcd.print("IN ");lcd.print(in+1);delay(1000);}// кнопка IN
//////////////////////////////////////// Volume 0...63 дБ //////////////////////////////////////
if(menu==0){
if(ir.value==0x2FD906F){vol++;gr1=1;gr2=0;cl1();w2=1;if(vol<0){vol=0;}if(vol>63){vol=63;}audio();}// кнопка >
if(ir.value==0xFFFFFFFF and gr1==1){vol++;gr2=0;cl1();w2=1;if(vol<0){vol=0;}if(vol>63){vol=63;}audio();}// кнопка >>>>>>
if(ir.value==0x2FDF20D){vol--;gr1=0;gr2=1;cl1();w2=1;if(vol<0){vol=0;}if(vol>63){vol=63;}audio();}// кнопка <
if(ir.value==0xFFFFFFFF and gr2==1){vol--;gr1=0;cl1();w2=1;if(vol<0){vol=0;}if(vol>63){vol=63;}audio();}// кнопка <<<<<<
if (newPosition != oldPosition) {
oldPosition = newPosition;
vol=vol+newPosition;myEnc.write(0);newPosition=0;time=millis();w=1;w2=1;if(vol>63){vol=63;}if(vol<0){vol=0;}audio();}
lcd.setCursor(2,1);lcd.print("Volume ");
lcd.setCursor(9,1);lcd.print(-78.75+(float)vol*1.25,2);lcd.print(" ");lcd.setCursor(16,1);lcd.print("dB");vol_d=vol-15;
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+2,2);lcd.write((uint8_t)0);lcd.setCursor(z0+1+2,2);lcd.print(" ");}}
if(z1==3){lcd.setCursor(z0+2,2);lcd.write((uint8_t)1);}
if(z1==2){lcd.setCursor(z0+2,2);lcd.write((uint8_t)2);}w2=0;}
{lcd.setCursor(2, 3); lcd.print("----------------");lcd.setCursor(2, 0); lcd.print("----------------");
lcd.setCursor(1, 1); lcd.print("|");lcd.setCursor(1, 2); lcd.print("|");
lcd.setCursor(18, 1); lcd.print("|");lcd.setCursor(18, 2); lcd.print("|");
}
}
//////////////////////////////////////////////////////////////////////////////////////////////////////
/////////////////////// индикация тембр НЧ -14...14 дБ ///////////////////
if(menu==1){
if(ir.value==0x2FD906F){bass++;gr1=1;gr2=0;cl1();w2=1;if(bass>7){bass=7;}if(bass<-7){bass=-7;}audio();}// кнопка >
if(ir.value==0xFFFFFFFF and gr1==1){bass++;gr2=0;cl1();w2=1;if(bass>7){bass=7;}if(bass<-7){bass=-7;}audio();}// кнопка >>>>>>
if(ir.value==0x2FDF20D){bass--;gr1=0;gr2=1;cl1();w2=1;if(bass>7){bass=7;}if(bass<-7){bass=-7;}audio();}// кнопка <
if(ir.value==0xFFFFFFFF and gr2==1){bass--;gr1=0;cl1();w2=1;if(bass>7){bass=7;}if(bass<-7){bass=-7;}audio();}// кнопка <<<<<<
if (newPosition != oldPosition) {
oldPosition = newPosition;
bass=bass+newPosition;myEnc.write(0);newPosition=0;time=millis();w=1;w2=1;if(bass>7){bass=7;}if(bass<-7){bass=-7;}audio();}
lcd.setCursor(3,1);lcd.print("Bass ");
lcd.setCursor(10,1);lcd.print(" ");lcd.print(bass*2);lcd.print(" ");lcd.setCursor(15,1);lcd.print("dB");bass_d=bass*2+15;
if(w2==1){
for(z=0,z0=0,z1=0;z<=bass_d;z++,z1++){if(z1>2){z1=0;z0++;}
if(z1==1){lcd.setCursor(z0+5,2);lcd.write((uint8_t)0);lcd.setCursor(z0+1+5,2);lcd.print(" ");}}
if(z1==3){lcd.setCursor(z0+5,2);lcd.write((uint8_t)1);}
if(z1==2){lcd.setCursor(z0+5,2);lcd.write((uint8_t)2);}w2=0;}
{lcd.setCursor(2, 3); lcd.print("----------------");lcd.setCursor(2, 0); lcd.print("----------------");
lcd.setCursor(1, 1); lcd.print("|");lcd.setCursor(1, 2); lcd.print("|");
lcd.setCursor(18, 1); lcd.print("|");lcd.setCursor(18, 2); lcd.print("|");
}
}
/////////////////////////////////////////////////////////////////////////////////////
/////////////////////// индикация тембр ВЧ -14...14 дБ ///////////////////
if(menu==2){
if(ir.value==0x2FD906F){treb++;gr1=1;gr2=0;cl1();w2=1;if(treb>7){treb=7;}if(treb<-7){treb=-7;}audio();}// кнопка >
if(ir.value==0xFFFFFFFF and gr1==1){treb++;gr2=0;cl1();w2=1;if(treb>7){treb=7;}if(treb<-7){treb=-7;}audio();}// кнопка >>>>>>
if(ir.value==0x2FDF20D){treb--;gr1=0;gr2=1;cl1();w2=1;if(treb>7){treb=7;}if(treb<-7){treb=-7;}audio();}// кнопка <
if(ir.value==0xFFFFFFFF and gr2==1){treb--;gr1=0;cl1();w2=1;if(treb>7){treb=7;}if(treb<-7){treb=-7;}audio();}// кнопка <<<<<<
if (newPosition != oldPosition) {
oldPosition = newPosition;
treb=treb+newPosition;myEnc.write(0);newPosition=0;time=millis();w=1;w2=1;if(treb>7){treb=7;}if(treb<-7){treb=-7;}audio();}
lcd.setCursor(3,1);lcd.print("Treble ");
lcd.setCursor(10,1);lcd.print(" ");lcd.print(treb*2);lcd.print(" ");lcd.setCursor(15,1);lcd.print("dB");treb_d=treb*2+15;
if(w2==1){
for(z=0,z0=0,z1=0;z<=treb_d;z++,z1++){if(z1>2){z1=0;z0++;}
if(z1==1){lcd.setCursor(z0+5,2);lcd.write((uint8_t)0);lcd.setCursor(z0+1+5,2);lcd.print(" ");}}
if(z1==3){lcd.setCursor(z0+5,2);lcd.write((uint8_t)1);}
if(z1==2){lcd.setCursor(z0+5,2);lcd.write((uint8_t)2);}w2=0;}
{lcd.setCursor(2, 3); lcd.print("----------------");lcd.setCursor(2, 0); lcd.print("----------------");
lcd.setCursor(1, 1); lcd.print("|");lcd.setCursor(1, 2); lcd.print("|");
lcd.setCursor(18, 1); lcd.print("|");lcd.setCursor(18, 2); lcd.print("|");
}
}
/////////////////////////////////////////////////////////////////////////////////////
if(digitalRead(12)==HIGH){in++;cl();myEnc.write(0);time=millis();w=1;w2=1;if(in>2){in=0;}if(in<0){in=2;}audio();lcd.setCursor(0,0);lcd.print("IN ");lcd.print(in+1);delay(1000);if(menu<100){menu=0;}}
///////////////////////////////////// GAIN //////////////////////////////////////////
if(menu1==1){
if(in==0){gain=gain1;}
if(in==1){gain=gain2;}
if(in==2){gain=gain3;}
if (newPosition != oldPosition) {
oldPosition = newPosition;
gain=gain+newPosition;myEnc.write(0);newPosition=0;lcd.clear();time=millis();w=1;w2=1;if(gain>3){gain=3;}if(gain<0){gain=0;}audio();}
if(in==0){gain1=gain;}
if(in==1){gain2=gain;}
if(in==2){gain3=gain;}
lcd.setCursor(4,1);lcd.print("INPUT CH. ");lcd.print(in+1);
lcd.setCursor(3,2);lcd.print("Gain ");lcd.print((float)gain*3.75);lcd.setCursor(14,2);lcd.print(" dB ");
{lcd.setCursor(2, 3); lcd.print("----------------");lcd.setCursor(2, 0); lcd.print("----------------");
lcd.setCursor(1, 1); lcd.print("|");lcd.setCursor(1, 2); lcd.print("|");
lcd.setCursor(18, 1); lcd.print("|");lcd.setCursor(18, 2); lcd.print("|");
}
}
/////////////////////////////// LOUDNESS //////////////////////////////////////////
if(menu1==2){
if (newPosition != oldPosition) {
oldPosition = newPosition;
loud=loud+newPosition;myEnc.write(0);newPosition=0;lcd.clear();time=millis();w=1;w2=1;if(loud>1){loud=0;}if(loud<0){loud=1;}audio();}
lcd.setCursor(4,1);lcd.print("LOUDNESS ");if(loud==1){lcd.print("ON ");}else{lcd.print("OFF");}
{lcd.setCursor(2, 3); lcd.print("----------------");lcd.setCursor(2, 0); lcd.print("----------------");
lcd.setCursor(1, 1); lcd.print("|");lcd.setCursor(1, 2); lcd.print("|");
lcd.setCursor(18, 1); lcd.print("|");lcd.setCursor(18, 2); lcd.print("|");
}
}
////////////////////////////////// att LR //////////////////////////////////////////////
if(menu1==3){
if (newPosition != oldPosition) {
oldPosition = newPosition;
lr=lr-newPosition;myEnc.write(0);newPosition=0;time=millis();w=1;w2=1;if(lr>31){lr=31;}if(lr<0){lr=0;}audio();}
lcd.setCursor(2,1);lcd.print("Speaker ");lcd.print((float)-lr*1.25,2);lcd.print(" ");
lcd.setCursor(2,2);lcd.print("LR");lcd.setCursor(16,2);lcd.print("dB");
if(w2==1){
for(z=0,z0=0,z1=0;z<=-lr+31;z++,z1++){if(z1>2){z1=0;z0++;}
if(z1==1){lcd.setCursor(z0+5,2);lcd.write((uint8_t)0);lcd.setCursor(z0+1+5,2);lcd.print(" ");}}
if(z1==3){lcd.setCursor(z0+5,2);lcd.write((uint8_t)1);}
if(z1==2){lcd.setCursor(z0+5,2);lcd.write((uint8_t)2);}w2=0;}
{lcd.setCursor(2, 3); lcd.print("----------------");lcd.setCursor(2, 0); lcd.print("----------------");
lcd.setCursor(1, 1); lcd.print("|");lcd.setCursor(1, 2); lcd.print("|");
lcd.setCursor(18, 1); lcd.print("|");lcd.setCursor(18, 2); lcd.print("|");
}
}
////////////////////////////////////////////////////////////////////////////////////////
////////////////////////////////// att LF //////////////////////////////////////////////
if(menu1==4){
if (newPosition != oldPosition) {
oldPosition = newPosition;
lf=lf-newPosition;myEnc.write(0);newPosition=0;time=millis();w=1;w2=1;if(lf>31){lf=31;}if(lf<0){lf=0;}audio();}
lcd.setCursor(2,1);lcd.print("Speaker ");lcd.print((float)-lf*1.25,2);lcd.print(" ");
lcd.setCursor(2,2);lcd.print("LF");lcd.setCursor(16,2);lcd.print("dB");
if(w2==1){
for(z=0,z0=0,z1=0;z<=-lf+31;z++,z1++){if(z1>2){z1=0;z0++;}
if(z1==1){lcd.setCursor(z0+5,2);lcd.write((uint8_t)0);lcd.setCursor(z0+1+5,2);lcd.print(" ");}}
if(z1==3){lcd.setCursor(z0+5,2);lcd.write((uint8_t)1);}
if(z1==2){lcd.setCursor(z0+5,2);lcd.write((uint8_t)2);}w2=0;}
{lcd.setCursor(2, 3); lcd.print("----------------");lcd.setCursor(2, 0); lcd.print("----------------");
lcd.setCursor(1, 1); lcd.print("|");lcd.setCursor(1, 2); lcd.print("|");
lcd.setCursor(18, 1); lcd.print("|");lcd.setCursor(18, 2); lcd.print("|");
}
}
////////////////////////////////////////////////////////////////////////////////////////
////////////////////////////////// att RF //////////////////////////////////////////////
if(menu1==5){
if (newPosition != oldPosition) {
oldPosition = newPosition;
rf=rf-newPosition;myEnc.write(0);newPosition=0;time=millis();w=1;w2=1;if(rf>31){rf=31;}if(rf<0){rf=0;}audio();}
lcd.setCursor(2,1);lcd.print("Speaker ");lcd.print((float)-rf*1.25,2);lcd.print(" ");
lcd.setCursor(2,2);lcd.print("RF");lcd.setCursor(16,2);lcd.print("dB");
if(w2==1){
for(z=0,z0=0,z1=0;z<=-rf+31;z++,z1++){if(z1>2){z1=0;z0++;}
if(z1==1){lcd.setCursor(z0+5,2);lcd.write((uint8_t)0);lcd.setCursor(z0+1+5,2);lcd.print(" ");}}
if(z1==3){lcd.setCursor(z0+5,2);lcd.write((uint8_t)1);}
if(z1==2){lcd.setCursor(z0+5,2);lcd.write((uint8_t)2);}w2=0;}
{lcd.setCursor(2, 3); lcd.print("----------------");lcd.setCursor(2, 0); lcd.print("----------------");
lcd.setCursor(1, 1); lcd.print("|");lcd.setCursor(1, 2); lcd.print("|");
lcd.setCursor(18, 1); lcd.print("|");lcd.setCursor(18, 2); lcd.print("|");
}}
////////////////////////////////////////////////////////////////////////////////////////
////////////////////////////////// att RR //////////////////////////////////////////////
if(menu1==6){
if (newPosition != oldPosition) {
oldPosition = newPosition;
rr=rr-newPosition;myEnc.write(0);newPosition=0;time=millis();w=1;w2=1;if(rr>31){rr=31;}if(rr<0){rr=0;}audio();}
lcd.setCursor(2,1);lcd.print("Speaker ");lcd.print((float)-rr*1.25,2);lcd.print(" ");
lcd.setCursor(2,2);lcd.print("RR");lcd.setCursor(16,2);lcd.print("dB");
if(w2==1){
for(z=0,z0=0,z1=0;z<=-rr+31;z++,z1++){if(z1>2){z1=0;z0++;}
if(z1==1){lcd.setCursor(z0+5,2);lcd.write((uint8_t)0);lcd.setCursor(z0+1+5,2);lcd.print(" ");}}
if(z1==3){lcd.setCursor(z0+5,2);lcd.write((uint8_t)1);}
if(z1==2){lcd.setCursor(z0+5,2);lcd.write((uint8_t)2);}w2=0;}
{lcd.setCursor(2, 3); lcd.print("----------------");lcd.setCursor(2, 0); lcd.print("----------------");
lcd.setCursor(1, 1); lcd.print("|");lcd.setCursor(1, 2); lcd.print("|");
lcd.setCursor(18, 1); lcd.print("|");lcd.setCursor(18, 2); lcd.print("|");
}
}
////////////////////////////////////////////////////////////////////////////////////////
if(millis()-time>10000 && w==1){
EEPROM.update(0,vol);
EEPROM.update(1,bass+7);
EEPROM.update(2,treb+7);
EEPROM.update(3,in);
EEPROM.update(4,gain1);EEPROM.update(5,gain2);EEPROM.update(6,gain3);
EEPROM.update(7,loud);
EEPROM.update(8,lr)
;EEPROM.update(9,rr);
EEPROM.update(10,lf);
EEPROM.update(11,rf);
EEPROM.update(12,ek);
menu1=0;lcd.clear();w=0,w2=1;menu=100;spek=1;}
//////////////////////////////////////////////////////////
if(spek==1){
analyzeAudio(); // функция FHT, забивает массив fht_log_out[] величинами по спектру
for (int pos = 0; pos < 20; pos++) {
if (fht_log_out[posOffset[pos]] > maxValue) maxValue = fht_log_out[posOffset[pos]];
int posLevel = map(fht_log_out[posOffset[pos]], LOW_PASS, gain_sp, 0, 31);
posLevel = constrain(posLevel, 0, 31);
urr[pos] = posLevel;
if(urr[pos]<ur[pos]){ur[pos]=ur[pos]-1;}
else{
ur[pos] = posLevel;}
delay(1);
if(posLevel<7){
lcd.setCursor(pos, 0);lcd.print(" ");
lcd.setCursor(pos, 1);lcd.print(" ");
lcd.setCursor(pos, 2);lcd.print(" ");
lcd.setCursor(pos, 3);lcd.write((uint8_t)posLevel);}
if(posLevel>7&&posLevel<15){
lcd.setCursor(pos, 0);lcd.print(" ");
lcd.setCursor(pos, 1);lcd.print(" ");
lcd.setCursor(pos, 3);lcd.write((uint8_t)7);lcd.setCursor(pos, 2);lcd.write((uint8_t)posLevel-8);}
if(posLevel>15&&posLevel<23){
lcd.setCursor(pos, 0);lcd.print(" ");
lcd.setCursor(pos, 3);lcd.write((uint8_t)7);
lcd.setCursor(pos, 2);lcd.write((uint8_t)7);lcd.setCursor(pos, 1);lcd.write((uint8_t)posLevel-16);}
if(posLevel>23&&posLevel<31){
lcd.setCursor(pos, 3);lcd.write((uint8_t)7);
lcd.setCursor(pos, 2);lcd.write((uint8_t)7);
lcd.setCursor(pos, 1);lcd.write((uint8_t)7);lcd.setCursor(pos, 0);lcd.write((uint8_t)posLevel-24);}
}
if (AUTO_GAIN) {
maxValue_f = maxValue * k + maxValue_f * (1 - k);
if (millis() - gainTimer > 1500) { // каждые 1500 мс
// если максимальное значение больше порога, взять его как максимум для отображения
if (maxValue_f > VOL_THR) gain_sp = maxValue_f;
// если нет, то взять порог побольше, чтобы шумы вообще не проходили
else gain_sp = 100;
gainTimer = millis();
}
}else{gain_sp = DEF_GAIN;}
}
//////////////////////////////////
}
void cl(){ir.value=0;delay(300);spek=0;lcd.clear();}
void cl1(){ir.value=0;delay(100);spek=0;}
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,gain); // вход 0...2, тонкомпенсация 1 вкл 0 выкл, усиление 0...3
tda.setBass(bass); // тембр НЧ -7...+7
tda.setTreble(treb); // тембр ВЧ -7...+7
}
void analyzeAudio() {
while(i1 < FHT_N){i1++;
do{ADCSRA |= (1 << ADSC);}
while((ADCSRA & (1 << ADIF)) == 0);fht_input[i1] = (ADCL|ADCH << 8);}i1=0;
fht_window(); // window the data for better frequency response
fht_reorder(); // reorder the data before doing the fht
fht_run(); // process the data in the fht
fht_mag_log(); // take the output of the fht
}