1

Тема: Serial Port tda7719

#include <Wire.h> 
#include <TDA7719.h>
#include <EEPROM.h>
  TDA7719 tda;
  
  byte a1,a2,b1,b2,param,data;
  byte w,i,vol,treb,treb_f,mid,mid_f,bas,bass_f,in,eeprom,loun,loun_f,vol_att,vol0,vol1,att_RF,att_LF,att_RR,att_LR;
  unsigned long time;

void setup(){
   Serial.begin(115200);Wire.begin();
 if(EEPROM.read(100)!=0){for(int i=0;i<101;i++){EEPROM.update(i,0);}}// очистка памяти при первом включении 
   vol = EEPROM.read(0);treb = EEPROM.read(1);mid = EEPROM.read(2);bas = EEPROM.read(3);in = EEPROM.read(4);
   loun = EEPROM.read(5);loun_f = EEPROM.read(6);
   vol0=EEPROM.read(7);vol1=EEPROM.read(8);treb_f=EEPROM.read(9);mid_f=EEPROM.read(10);bass_f=EEPROM.read(11);
   att_RF=EEPROM.read(12);att_LF=EEPROM.read(13);att_RR=EEPROM.read(14);att_LR=EEPROM.read(15);
   in_att();audio();
}
 
void loop(){
  /////////// Serial Port - получение данных //////////////////////////////////////////////////////////
  if(Serial.available()){w++;time=millis(); delay(10);
    switch(i){
      case 0: a1 = Serial.read()-48;
      case 1: a2 = Serial.read()-48;
      case 2: b1 = Serial.read()-48;
      case 3: b2 = Serial.read()-48;}
      param = a1*10+a2;data = b1*10+b2;// получение кода команды и значение
    switch(param){
      case 10: vol=data;break;                                    // передаем переменной vol  значение byte = 79...0 === громкость от -79 до 0 дБ === 1079...1000
      case 11: treb=data;break;                                   // передаем переменной treb  значение byte = 0...30 === тебр ВЧ от -15 до +15 дБ === 1100...1130
      case 12: mid=data;break;                                    // передаем переменной mid  значение byte = 0...30 === тебр СЧ от -15 до +15 дБ === 1200...1230
      case 13: bas=data;break;                                    // передаем переменной bas  значение byte = 0...30 === тебр НЧ от -15 до +15 дБ === 1300...1330
      case 14: in=data;break;                                     // передаем переменной in  значение byte = 0...5 === выбор входа от 0 до 5 === 1400...1405
      case 15: loun=data;break;                                   // передаем переменной loun  значение byte = 0...15 === тонкомпенсация ослабление от -15 до 0 дБ === 1500...1515
      case 16: loun_f=data;break;                                 // передаем переменной loun_f  значение byte = 0...3 === тонкомпенсация центральная частота FLAT 400 800 2400 Гц === 1600...1603
      case 17: vol0=data;break;                                   // аттенюатор входа 1 от -15 до +15 дБ  === 1700...1730
      case 18: vol1=data;break;                                   // аттенюатор входа 2 от -15 до +15 дБ  === 1800...1830
      case 19: treb_f=data;break;                                 // передаем переменной treb_f  значение byte = 0...3 === ВЧ центральная частота 10 12.5 15 17.5 кГц === 1900...1903
      case 20: mid_f=data;break;                                  // передаем переменной mid_f  значение byte = 0...3 === CЧ центральная частота 0.5 1 1.5 2.5 кГц === 2000...2003
      case 21: bass_f=data;break;                                 // передаем переменной bass_f  значение byte = 0...3 === НЧ центральная частота 60 80 100 200 Гц === 2100...2103
        //// attenuator output
      case 22: att_RF=data;break;                                 // 2215...2200
      case 23: att_LF=data;break;                                 // 2315...2315
      case 24: att_RR=data;break;                                 // 2415...2400
      case 25: att_LR=data;break;                                 // 2515...2500
      
      case 99: eeprom=data;break; // EEPROM === 9901 отправить в данные в EEPROM
      i++;}}i=0;
  //////////////////////////////////////////////////////////////////////////////////////////////////////    

   in_att();
  
  //////////// EEPROM ////////////////////////////////////////////////////////////////////////////////////
  if(eeprom==1){eeprom=0;
     EEPROM.update(0,vol);EEPROM.update(1,treb);EEPROM.update(2,mid);EEPROM.update(3,bas);EEPROM.update(4,in);
     EEPROM.update(5,loun);EEPROM.update(6,loun_f);EEPROM.update(7,vol0);EEPROM.update(8,vol1);
     EEPROM.update(9,treb_f);EEPROM.update(10,mid_f);EEPROM.update(11,bass_f);
     EEPROM.update(12,att_RF);EEPROM.update(13,att_LF);EEPROM.update(14,att_RR);EEPROM.update(15,att_LR);
    }
  ///////////////////////////////////////////////////////////////////////////////////////////////////////   
     
  //////////// Отправка данных в минитор порта и аудиопроцессор /////////////////////////////////////////   
  if(w==1){audio();
  Serial.print(vol);Serial.print(" ");Serial.print(treb);Serial.print(" ");Serial.print(mid);Serial.print(" ");Serial.print(bas);
  Serial.print(" ");Serial.print(in);Serial.print(" ");Serial.print(loun);Serial.print(" ");Serial.print(loun_f);
  Serial.print(" ");Serial.print(vol0);Serial.print(" ");Serial.print(vol1);Serial.print(" ");Serial.print(treb_f);Serial.print(" ");
  Serial.print(mid_f);Serial.print(" ");Serial.print(bass_f);Serial.println(" ");
   w=0;}
  /////////////////////////////////////////////////////////////////////////////////////////////////////// 

   

}//LOOP

void audio(){
tda.setInput(in,1,1,7); // 0...7, 0...1, 0...1, 0...7
tda.setInput_2(2,1,1,1,1,1); // 0...7, 0...1, 0...1, 0...1, 0...1, 0...1 
tda.setMix_source(7,0); // 0...7, 0...-31
tda.setMix_cont(1,1,1,1,1,1,1,1); // all 0...1
tda.setMute(1,0,0,1,1,1,1); // 0...1, 0...1, 0...3, 0...1, 0...1, 0...1, 0...1
tda.setSoft_1(1,1,1,1,1,1,1,1); //all 0...1
tda.setSoft_2(1,1,1,1,0,3); // 0...1, 0...1, 0...1, 0...1, 0...2, 0...3
tda.setLoudness(-loun,loun_f,1,1); // 0...-15, 0...3, 0...1, 0...1 
tda.setVol(vol_att-15,1,1); // -15...+15, 0...1, 0...1
tda.setTreble(treb-15,treb_f,1); // -15...+15, 0...3, 0...1
tda.setMiddle(mid-15,3,1); // -15...+15, 0...3, 0...1
tda.setBass(bas-15,3,1); // -15...+15, 0...3, 0...1
tda.setSMB(0,1,mid_f,bass_f,1); // 0...3, 0...1, 0...3, 0...3, 0...1
tda.setVol_LF(vol-att_LR,1); // 0...-79, 0...1
tda.setVol_RF(vol-att_RF,1); // 0...-79, 0...1
tda.setVol_LR(vol-att_LR,1); // 0...-79, 0...1
tda.setVol_RR(vol-att_RR,1); // 0...-79, 0...1
tda.setVol_SUB_L(vol,1); // 0...-79, 0...1
tda.setVol_SUB_R(vol,1); // 0...-79, 0...1
tda.setTest1(0,14,1,1); // 0...1, 0...15, 0...1, 0...1
tda.setTest2(0,1,1,3); // 0...1, 0...1, 0...1, 0...3
}

void in_att(){
  switch(in){
     case 0: vol_att = vol0;break;
     case 1: vol_att = vol1;break;
     }
  }

2

Re: Serial Port tda7719

с энкодером
D8 D9 подключение энкодера CLK, DT

#include <Wire.h> 
#include <TDA7719.h>
#include <EEPROM.h>
#include <Encoder.h>
#include <MsTimer2.h>
  TDA7719 tda;
  Encoder myEnc(9, 8);//CLK, DT подключение энкодера
  byte a1,a2,b1,b2,param,data;
  int w,i,vol,treb,treb_f,mid,mid_f,bas,bass_f,in,eeprom,loun,loun_f,vol_att,vol0,vol1,att_RF,att_LF,att_RR,att_LR;
  unsigned long newPosition,time,oldPosition  = -999;

void setup(){
   Serial.begin(115200);Wire.begin();
   pinMode(8, INPUT_PULLUP);
   pinMode(9, INPUT_PULLUP);
 if(EEPROM.read(100)!=0){for(int i=0;i<101;i++){EEPROM.update(i,0);}}// очистка памяти при первом включении 
   vol = EEPROM.read(0);treb = EEPROM.read(1);mid = EEPROM.read(2);bas = EEPROM.read(3);in = EEPROM.read(4);
   loun = EEPROM.read(5);loun_f = EEPROM.read(6);
   vol0=EEPROM.read(7);vol1=EEPROM.read(8);treb_f=EEPROM.read(9);mid_f=EEPROM.read(10);bass_f=EEPROM.read(11);
   att_RF=EEPROM.read(12);att_LF=EEPROM.read(13);att_RR=EEPROM.read(14);att_LR=EEPROM.read(15);
   MsTimer2::set(3, to_Timer);MsTimer2::start();
   in_att();audio();
}
 
void loop(){
  /////////// Serial Port - получение данных //////////////////////////////////////////////////////////
  if(Serial.available()){w++;time=millis(); delay(10);
    switch(i){
      case 0: a1 = Serial.read()-48;
      case 1: a2 = Serial.read()-48;
      case 2: b1 = Serial.read()-48;
      case 3: b2 = Serial.read()-48;}
      param = a1*10+a2;data = b1*10+b2;// получение кода команды и значение
    switch(param){
      case 10: vol=data;break;                                    // передаем переменной vol  значение byte = 79...0 === громкость от -79 до 0 дБ === 1079...1000
      case 11: treb=data;break;                                   // передаем переменной treb  значение byte = 0...30 === тебр ВЧ от -15 до +15 дБ === 1100...1130
      case 12: mid=data;break;                                    // передаем переменной mid  значение byte = 0...30 === тебр СЧ от -15 до +15 дБ === 1200...1230
      case 13: bas=data;break;                                    // передаем переменной bas  значение byte = 0...30 === тебр НЧ от -15 до +15 дБ === 1300...1330
      case 14: in=data;break;                                     // передаем переменной in  значение byte = 1...2 === выбор входа от 0 до 1 === 1401...1402
      case 15: loun=data;break;                                   // передаем переменной loun  значение byte = 0...15 === тонкомпенсация ослабление от -15 до 0 дБ === 1500...1515
      case 16: loun_f=data;break;                                 // передаем переменной loun_f  значение byte = 0...3 === тонкомпенсация центральная частота FLAT 400 800 2400 Гц === 1600...1603
      case 17: vol0=data;break;                                   // аттенюатор входа 0 от -15 до +15 дБ  === 1700...1730
      case 18: vol1=data;break;                                   // аттенюатор входа 1 от -15 до +15 дБ  === 1800...1830
      case 19: treb_f=data;break;                                 // передаем переменной treb_f  значение byte = 0...3 === ВЧ центральная частота 10 12.5 15 17.5 кГц === 1900...1903
      case 20: mid_f=data;break;                                  // передаем переменной mid_f  значение byte = 0...3 === CЧ центральная частота 0.5 1 1.5 2.5 кГц === 2000...2003
      case 21: bass_f=data;break;                                 // передаем переменной bass_f  значение byte = 0...3 === НЧ центральная частота 60 80 100 200 Гц === 2100...2103
        //// attenuator output
      case 22: att_RF=data;break;                                 // 2200...2215
      case 23: att_LF=data;break;                                 // 2300...2315
      case 24: att_RR=data;break;                                 // 2400...2415
      case 25: att_LR=data;break;                                 // 2500...2515
      
      case 99: eeprom=data;break; // EEPROM === 9901 отправить в данные в EEPROM
      i++;}}i=0;
  //////////////////////////////////////////////////////////////////////////////////////////////////////    

   in_att();

    if (newPosition != oldPosition) {
    oldPosition = newPosition;
    vol=vol-newPosition;myEnc.write(0);newPosition=0;w=1;if(vol<0){vol=0;}if(vol>79){vol=79;}audio();}
  
  //////////// EEPROM ////////////////////////////////////////////////////////////////////////////////////
  if(eeprom==1){eeprom=0;
     EEPROM.update(0,vol);EEPROM.update(1,treb);EEPROM.update(2,mid);EEPROM.update(3,bas);EEPROM.update(4,in);
     EEPROM.update(5,loun);EEPROM.update(6,loun_f);EEPROM.update(7,vol0);EEPROM.update(8,vol1);
     EEPROM.update(9,treb_f);EEPROM.update(10,mid_f);EEPROM.update(11,bass_f);
     EEPROM.update(12,att_RF);EEPROM.update(13,att_LF);EEPROM.update(14,att_RR);EEPROM.update(15,att_LR);
    }
  ///////////////////////////////////////////////////////////////////////////////////////////////////////   
     
  //////////// Отправка данных в минитор порта и аудиопроцессор /////////////////////////////////////////   
  if(w==1){audio();
  Serial.print("vol= ");Serial.print(vol);Serial.print(" treb= ");Serial.print(treb);Serial.print(" mid= ");Serial.print(mid);Serial.print(" bas= ");Serial.print(bas);
  Serial.print(" in= ");Serial.print(in);Serial.print(" loun= ");Serial.print(loun);Serial.print(" loun_f= ");Serial.print(loun_f);
  Serial.print(" vol0= ");Serial.print(vol0);Serial.print(" vol1= ");Serial.print(vol1);Serial.print(" treb_f");Serial.print(treb_f);Serial.print(" mid_f= ");
  Serial.print(mid_f);Serial.print(" bass_f= ");Serial.print(bass_f);Serial.print(" rf= ");
  Serial.print(att_RF);Serial.print(" lf= ");Serial.print(att_LF);Serial.print(" rr= ");Serial.print(att_RR);Serial.print(" lr= ");Serial.print(att_LR);
  Serial.print(" vol_att=");Serial.print(vol_att);Serial.print(" общая гром= ");Serial.print(vol+15-att_LR);Serial.println("");
   w=0;}
  /////////////////////////////////////////////////////////////////////////////////////////////////////// 

   

}//LOOP

void audio(){
tda.setInput(in,1,1,7); // 0...7, 0...1, 0...1, 0...7
tda.setInput_2(2,1,1,1,1,1); // 0...7, 0...1, 0...1, 0...1, 0...1, 0...1 
tda.setMix_source(7,0); // 0...7, 0...-31
tda.setMix_cont(1,1,1,1,1,1,1,1); // all 0...1
tda.setMute(1,0,0,1,1,1,1); // 0...1, 0...1, 0...3, 0...1, 0...1, 0...1, 0...1
tda.setSoft_1(1,1,1,1,1,1,1,1); //all 0...1
tda.setSoft_2(1,1,1,1,0,3); // 0...1, 0...1, 0...1, 0...1, 0...2, 0...3
tda.setLoudness(-loun,loun_f,1,1); // 0...-15, 0...3, 0...1, 0...1 
tda.setVol(vol_att-15,1,1); // -15...+15, 0...1, 0...1
tda.setTreble(treb-15,treb_f,1); // -15...+15, 0...3, 0...1
tda.setMiddle(mid-15,3,1); // -15...+15, 0...3, 0...1
tda.setBass(bas-15,3,1); // -15...+15, 0...3, 0...1
tda.setSMB(0,1,mid_f,bass_f,1); // 0...3, 0...1, 0...3, 0...3, 0...1
tda.setVol_LF(vol+15-att_LR,1); // 0...-79, 0...1
tda.setVol_RF(vol+15-att_RF,1); // 0...-79, 0...1
tda.setVol_LR(vol+15-att_LR,1); // 0...-79, 0...1
tda.setVol_RR(vol+15-att_RR,1); // 0...-79, 0...1
tda.setVol_SUB_L(vol,1); // 0...-79, 0...1
tda.setVol_SUB_R(vol,1); // 0...-79, 0...1
tda.setTest1(0,14,1,1); // 0...1, 0...15, 0...1, 0...1
tda.setTest2(0,1,1,3); // 0...1, 0...1, 0...1, 0...3
}

void in_att(){
  switch(in){
     case 1: vol_att = vol0;break;
     case 2: vol_att = vol1;break;
     }
  }

void to_Timer(){newPosition = myEnc.read()/4;}

3

Re: Serial Port tda7719

#include <Wire.h> 
#include <BD37033FV.h>
BD37033FV tda; 
 
int buff[2], w,w0,i,param,data;
unsigned long times;
 
int vol;
 
void setup(){Serial.begin(115200);
  audio();
}
 
void loop(){
 
/////// ПРИЕМ ДАННЫХ С SERIAL PORT /////////////////////////
 while (Serial.available()>0){ 
   for (i=0;i<1;i++) { 
     buff[0] = Serial.parseInt(); 
     buff[1] = Serial.parseInt();}    
     w=1;w0=1;times=millis();}
 
if(w==1){w=0;
 
param = buff[0]/100;
data = buff[0]-(buff[0]/100)*100;
 
switch(param){
  case 10: vol = data;audio();break; // 1000...1094 vol громкость
  
  
  }
  
// ОТПРАВКА В МОНИТОР ПОРТА
//Serial.println(param);
//Serial.println(data);
 
Serial.print(vol);Serial.println(" ");
  
 
}
}// loop
 
void audio(){
        tda.setInitial();
        tda.setSub_setup(0,0,0); // off 55hz 85hz 120hz 160hz pass = int sub_f(0...5) || LPF front rear sub = int sub_out(0...3) 0 - default || 0 180 = int faza(0...1)
        tda.setLoud_f(3,0,0,0); // mix_in off || 400hz 800hz 2400hz Prohibition = int loud_f(0...3) || MIXING 1ch 2ch -- on off = mix_ch1(0...1) mix_ch2(0..1)
        tda.setIn(0); // in1 in2 in3 = int in(0...2)
        tda.setIn_gain(0,0); // 0...16 dB = int in_gain(0...16) || off on = int mute(0...1)
        tda.setVol(-vol+15); // -79...+15 dB = int vol(-79...15)
        tda.setFront_1(0); // -79...+15 dB = int -79...15
        tda.setFront_2(0); // -79...+15 dB = int -79...15
        tda.setRear_1(0); // -79...+15 dB = int -79...15
        tda.setRear_2(0); // -79...+15 dB = int -79...15
        tda.setSub1(0); // -79...+15 dB = int -79...15
        tda.setSub2(0); // -79...+15 dB = int -79...15
        tda.setBass_setup(0,0); // 0.5 1.0 1.5 2.0 --- int 0...3, 60Hz 80Hz 100Hz 120Hz --- int 0...3
        tda.setMiddle_setup(0,0); // 0.75 1.0 1.25 1.5 --- int 0...3, 500Hz 1kHz 1.5kHz 2.5kHz --- int 0...3
        tda.setTreble_setup(0,0); // 0.75 1.25  --- int 0...1, 7.5kHz 10kHz 12.5kHz 15kHz --- int 0...3
        tda.setBass_gain(0); // --15 ... +15 dB = int -15 ... 15 
        tda.setMiddle_gain(0); // --15 ... +15 dB = int -15 ... 15
        tda.setTreble_gain(0); // --15 ... +20 dB = int -15 ... 15
        tda.setLoudness_gain(0); // 0 ... 15 dB = int 0 ... 15 
  }
 

4

Re: Serial Port tda7719

#include "TEF6686.h"

int frequency;
int volume;

uint8_t isRDSReady;

char programTypePrevious[17] = " ";
char programServicePrevious[9];
char radioTextPrevious[65];

boolean isFmSeekMode;
boolean isFmSeekUp;

int buff[2], w,w0,i,param,data,www,f,f1,w2=1;
unsigned long times,newPosition,oldPosition  = -999;

TEF6686 radio;
RdsInfo rdsInfo;

void setup() {
delay(1000);
Serial.begin(115200);
while (!Serial);
Serial.println("Begin");
radio.init();
radio.powerOn();
radio.setFrequency(10210);
frequency = radio.getFrequency(); 
}

void loop() {
   /////// ПРИЕМ ДАННЫХ С SERIAL PORT /////////////////////////
 while (Serial.available()>0){ 
   for (i=0;i<1;i++) { 
     buff[0] = Serial.parseInt(); 
     buff[1] = Serial.parseInt();}    
     w=1;w0=1;times=millis();}


     if(w==1){w=0;
 
param = buff[0]/100;
data = buff[0]-(buff[0]/100)*100;
 
switch(param){
  case 30: 
   if(data==1){w2=1;frequency = radio.seekUp();readRds();showFmSeek();} 
   if(data==2){w2=1;frequency = radio.seekDown();readRds();showFmSeek();} 
   if(data==3){w2=1;frequency = radio.tuneUp();readRds();showFmSeek();} 
   if(data==4){w2=1;frequency = radio.tuneDown();readRds();showFmSeek();} 
   if(data==5){w2=1;isFmSeekMode = true;isFmSeekUp = true;readRds();showFmSeek();} 
   if(data==6){w2=1;isFmSeekMode = true;isFmSeekUp = false;readRds();showFmSeek();}
   break; 
  
  case 31: w2=1;volume = data;radio.setVolume(volume-60);readRds();showFmSeek();break; // 3100...3184
  

  case 50: f=data;break; // 5000...5040 === 60 + 0...50 = 60...110 MHz
  case 51: f1=data;www=1;break; // 5100...5099 === f+f1
  }}

  if(www==1){www=0;w2=1;radio.setFrequency( (f+60)*100 + f1 );frequency = radio.getFrequency();}// 5041 = 101 5150 = 50 ==== 10150 

  if(w2==1){w2=0;displayInfo();}

   
}// loop

void readRds() {
isRDSReady = radio.readRDS(); 
radio.getRDS(&rdsInfo);

showPTY();
showPS();
showRadioText(); 
}

void showPTY() {
if ((isRDSReady == 1) && !strcmp(rdsInfo.programType, programTypePrevious, 16)) { 
Serial.print(rdsInfo.programType);
strcpy(programTypePrevious, rdsInfo.programType);
Serial.println(); 
} 
}

void showPS() {
if ((isRDSReady == 1) && (strlen(rdsInfo.programService) == 8) && !strcmp(rdsInfo.programService, programServicePrevious, 8)) {
Serial.print("-=[ ");
Serial.print(rdsInfo.programService);
Serial.print(" ]=-");
strcpy(programServicePrevious, rdsInfo.programService);
Serial.println();
}
}

void showRadioText() {
if ((isRDSReady == 1) && !strcmp(rdsInfo.radioText, radioTextPrevious, 65)){
Serial.print(rdsInfo.radioText);
strcpy(radioTextPrevious, rdsInfo.radioText);
Serial.println(); 
}
}

bool strcmp(char* str1, char* str2, int length) {
for (int i = 0; i < length; i++) {
if (str1[i] != str2[i]) {
return false;
} 
} 
return true;
}

void showFmSeek() {
if (isFmSeekMode) {
if (radio.seekSync(isFmSeekUp)) {
isFmSeekMode = false;
Serial.println("Seek stopped");
frequency = radio.getFrequency();
}
}
}

void displayInfo() {
   delay(10);
   Serial.print("Frequency:"); 
   Serial.print(frequency); 
   Serial.print(" Volume:"); 
   Serial.println(volume);
   Serial.print("Level:"); 
   Serial.println(radio.getLevel() / 10);
   Serial.print("Stereo:"); 
   Serial.println(radio.getStereoStatus());
}

5

Re: Serial Port tda7719

#include <Wire.h> 

#include <EEPROM.h>
#include <BD37033FV.h>
#include <FlexiTimer2.h> // http://forum.rcl-radio.ru/misc.php?action=pan_download&item=298&download=1
#include <Encoder.h>
 BD37033FV tda; 
 Encoder myEnc(9, 8);//CLK, DT подключение энкодера
 
int buff[2], w,w0,i,param,data;
unsigned long times,newPosition,oldPosition  = -999;
 
int vol,treb,mid,bas,lon,mix,bas_f,mid_f,treb_f,lon_f, att_f1,att_f2,att_r1,att_r2,in,set_in,save;
 
void setup(){Serial.begin(115200);Wire.begin();
    FlexiTimer2::set(3, flash);  FlexiTimer2::start();
    if(EEPROM.read(100)!=0){for(int i=0;i<101;i++){EEPROM.update(i,0);}}// очистка памяти при первом включении
    vol = EEPROM.read(0);treb = EEPROM.read(1);mid = EEPROM.read(2);bas = EEPROM.read(3);in = EEPROM.read(4);
    lon = EEPROM.read(5);mix = EEPROM.read(6);bas_f = EEPROM.read(7);mid_f = EEPROM.read(8);treb_f = EEPROM.read(9);
    lon_f = EEPROM.read(10);att_f1 = EEPROM.read(11);att_f2 = EEPROM.read(12);att_r1 = EEPROM.read(13);att_r2 = EEPROM.read(14);
    set_in = EEPROM.read(15);
    audio();
}
 
void loop(){
 
/////// ПРИЕМ ДАННЫХ С SERIAL PORT /////////////////////////
 while (Serial.available()>0){ 
   for (i=0;i<1;i++) { 
     buff[0] = Serial.parseInt(); 
     buff[1] = Serial.parseInt();}    
     w=1;w0=1;times=millis();}
 
if(w==1){w=0;
 
param = buff[0]/100;
data = buff[0]-(buff[0]/100)*100;
 
switch(param){
  case 10: vol = data;audio();break; // 1000...1094 vol громкость
  case 11: treb = data;audio();break; // 1100...1130 treb тембр  ВЧ
  case 12: mid = data;audio();break; // 1200...1230 mid тембр  CЧ
  case 13: bas = data;audio();break; // 1300...1330 bas тембр  НЧ
  case 14: lon = data;audio();break; // 1400...1415 lon loudness
  
  case 15: set_in = data;if(set_in == 0){in = 0,mix = 2;} 
                         if(set_in == 1){in = 1,mix = 0;}
           audio();break; // 1500 или 1501 0 = 2.0.0.0 in 0 | 1 = 0.0.0.0 in 1
  
  case 16: bas_f = data;audio();break; // 1600...1603 bas_f центральная частота НЧ
  case 17: mid_f = data;audio();break; // 1700...1703 mid_f центральная частота CЧ
  case 18: treb_f = data;audio();break; // 1800...1803 treb_f центральная частота BЧ
  case 19: lon_f = data;audio();break; // 1900...1903 lon_f центральная частота loudness

  case 20: att_f1 = data;audio();break; // 2000...2015 att_f1 front 1
  case 21: att_f2 = data;audio();break; // 2100...2115 att_f2 front 2
  case 22: att_r1 = data;audio();break; // 2200...2215 att_r1 rear 1
  case 23: att_r2 = data;audio();break; // 2300...2315 att_r2 rear 2

  case 50: save = data;break; // 5001 - save запись в EEPROM
  }
  
// ОТПРАВКА В МОНИТОР ПОРТА
  Serial.println(vol);
 
Serial.print(vol);Serial.println(" ");

//////////// EEPROM ////////////////////////////////////////////////////////////////////////////////////
  if(save==1){save=0;  
     EEPROM.update(0,vol);EEPROM.update(1,treb);EEPROM.update(2,mid);EEPROM.update(3,bas);EEPROM.update(4,in);
     EEPROM.update(5,lon);EEPROM.update(6,mix);EEPROM.update(7,bas_f);EEPROM.update(8,mid_f);EEPROM.update(9,treb_f);
     EEPROM.update(10,lon_f);EEPROM.update(11,att_f1);EEPROM.update(12,att_f2);EEPROM.update(13,att_r1);EEPROM.update(14,att_r2);
     EEPROM.update(15,set_in);
    }
///////////////////////////////////////////////////////////////////////////////////////////////////////  
}
 if (newPosition != oldPosition) {
    oldPosition = newPosition;
    vol=vol-newPosition;myEnc.write(0);newPosition=0;w=1;if(vol<0){vol=0;}if(vol>94){vol=94;}audio();}
}// loop
 
void audio(){
        tda.setInitial();
        tda.setSub_setup(0,0,0); // off 55hz 85hz 120hz 160hz pass = int sub_f(0...5) || LPF front rear sub = int sub_out(0...3) 0 - default || 0 180 = int faza(0...1)
        tda.setLoud_f(mix,lon_f,0,0); // mix_in off || 400hz 800hz 2400hz Prohibition = int loud_f(0...3) || MIXING 1ch 2ch -- on off = mix_ch1(0...1) mix_ch2(0..1)
        tda.setIn(in); // in1 in2 in3 = int in(0...2)
        tda.setIn_gain(0,0); // 0...16 dB = int in_gain(0...16) || off on = int mute(0...1)
        tda.setVol(-vol+15); // -79...+15 dB = int vol(-79...15)
        tda.setFront_1(att_f1); // -79...+15 dB = int -79...15
        tda.setFront_2(att_f2); // -79...+15 dB = int -79...15
        tda.setRear_1(att_r1); // -79...+15 dB = int -79...15
        tda.setRear_2(att_r2); // -79...+15 dB = int -79...15
        tda.setSub1(0); // -79...+15 dB = int -79...15
        tda.setSub2(0); // -79...+15 dB = int -79...15
        tda.setBass_setup(0,bas_f); // 0.5 1.0 1.5 2.0 --- int 0...3, 60Hz 80Hz 100Hz 120Hz --- int 0...3
        tda.setMiddle_setup(0,mid_f); // 0.75 1.0 1.25 1.5 --- int 0...3, 500Hz 1kHz 1.5kHz 2.5kHz --- int 0...3
        tda.setTreble_setup(0,treb_f); // 0.75 1.25  --- int 0...1, 7.5kHz 10kHz 12.5kHz 15kHz --- int 0...3
        tda.setBass_gain(bas); // --15 ... +15 dB = int -15 ... 15 
        tda.setMiddle_gain(mid-15); // --15 ... +15 dB = int -15 ... 15
        tda.setTreble_gain(treb-15); // --15 ... +15 dB = int -15 ... 15
        tda.setLoudness_gain(lon); // 0 ... 15 dB = int 0 ... 15 
  }

void flash(){newPosition = myEnc.read()/2;}  

6

Re: Serial Port tda7719

Данный контент доступен только зарегистрированным пользователям.


#include "TEF6686.h"
#include <Wire.h> 

#include <EEPROM.h>
#include <BD37033FV.h>
#include <FlexiTimer2.h> // http://forum.rcl-radio.ru/misc.php?action=pan_download&item=298&download=1
#include <Encoder.h>
  Encoder myEnc(9, 8);//CLK, DT подключение энкодера
  BD37033FV tda; 

int frequency;
int volume;

uint8_t isRDSReady;

char programTypePrevious[17] = " ";
char programServicePrevious[9];
char radioTextPrevious[65];

boolean isFmSeekMode;
boolean isFmSeekUp;

int vol,treb,mid,bas,lon,mix,bas_f,mid_f,treb_f,lon_f, att_f1,att_f2,att_r1,att_r2,in,set_in,save;
int buff[2], w,w0,i,param,data,www,f,f1,w2=1;
unsigned long times,newPosition,oldPosition  = -999;

TEF6686 radio;
RdsInfo rdsInfo;

void setup() {
    Serial.begin(115200);
    Wire.begin();
    FlexiTimer2::set(3, flash);  FlexiTimer2::start();
    if(EEPROM.read(100)!=0){for(int i=0;i<101;i++){EEPROM.update(i,0);}}// очистка памяти при первом включении
    vol = EEPROM.read(0);treb = EEPROM.read(1);mid = EEPROM.read(2);bas = EEPROM.read(3);in = EEPROM.read(4);
    lon = EEPROM.read(5);mix = EEPROM.read(6);bas_f = EEPROM.read(7);mid_f = EEPROM.read(8);treb_f = EEPROM.read(9);
    lon_f = EEPROM.read(10);att_f1 = EEPROM.read(11);att_f2 = EEPROM.read(12);att_r1 = EEPROM.read(13);att_r2 = EEPROM.read(14);
    set_in = EEPROM.read(15);
    
    radio.init();
    radio.powerOn();
    radio.setFrequency(10210);
    frequency = radio.getFrequency();
    displayInfo();
    audio();delay(100);
}

void loop() {
    /////// ПРИЕМ ДАННЫХ С SERIAL PORT /////////////////////////
  while (Serial.available()>0){
    for (i=0;i<1;i++) {
      buff[0] = Serial.parseInt();
      buff[1] = Serial.parseInt();}
      w=1;w0=1;times=millis();}


      if(w==1){w=0;

param = buff[0]/100;
data = buff[0]-(buff[0]/100)*100;

switch(param){
  case 10: vol = data;audio();break; // 1000...1094 vol громкость
  case 11: treb = data;audio();break; // 1100...1130 treb тембр  ВЧ
  case 12: mid = data;audio();break; // 1200...1230 mid тембр  CЧ
  case 13: bas = data;audio();break; // 1300...1330 bas тембр  НЧ
  case 14: lon = data;audio();break; // 1400...1415 lon loudness
  
  case 15: set_in = data;if(set_in == 0){in = 0,mix = 2;} 
                         if(set_in == 1){in = 1,mix = 0;}
           audio();break; // 1500 или 1501 0 = 2.0.0.0 in 0 | 1 = 0.0.0.0 in 1
  
  case 16: bas_f = data;audio();break; // 1600...1603 bas_f центральная частота НЧ
  case 17: mid_f = data;audio();break; // 1700...1703 mid_f центральная частота CЧ
  case 18: treb_f = data;audio();break; // 1800...1803 treb_f центральная частота BЧ
  case 19: lon_f = data;audio();break; // 1900...1903 lon_f центральная частота loudness

  case 20: att_f1 = data;audio();break; // 2000...2015 att_f1 front 1
  case 21: att_f2 = data;audio();break; // 2100...2115 att_f2 front 2
  case 22: att_r1 = data;audio();break; // 2200...2215 att_r1 rear 1
  case 23: att_r2 = data;audio();break; // 2300...2315 att_r2 rear 2

  case 50: save = data;break; // 5001 - save запись в EEPROM
  
  case 30:
    if(data==1){w2=1;frequency = radio.seekUp();readRds();showFmSeek();}
    if(data==2){w2=1;frequency = radio.seekDown();readRds();showFmSeek();}
    if(data==3){w2=1;frequency = radio.tuneUp();readRds();showFmSeek();}
    if(data==4){w2=1;frequency = radio.tuneDown();readRds();showFmSeek();}
    if(data==5){w2=1; radio.powerOn();showFmSeek();}
    if(data==6){w2=1;radio.powerOff();showFmSeek();}
    break;

   case 31: w2=1;volume = data;radio.setVolume(volume-60);readRds();showFmSeek();break; // 3100...3184

   case 60: f=data;break; // 5000...5040 === 60 + 0...50 = 60...110 MHz
   case 51: f1=data;www=1;break; // 5100...5099 === f+f1
   }}

   if(www==1){www=0;w2=1;radio.setFrequency( (f+55)*100 + f1 );frequency 
= radio.getFrequency();}// 5041 = 101 5150 = 50 ==== 10150

   if(w2==1){w2=0;displayInfo();}

//Serial.print(vol);Serial.println(" ");

//////////// EEPROM ////////////////////////////////////////////////////////////////////////////////////
  if(save==1){save=0;  
     EEPROM.update(0,vol);EEPROM.update(1,treb);EEPROM.update(2,mid);EEPROM.update(3,bas);EEPROM.update(4,in);
     EEPROM.update(5,lon);EEPROM.update(6,mix);EEPROM.update(7,bas_f);EEPROM.update(8,mid_f);EEPROM.update(9,treb_f);
     EEPROM.update(10,lon_f);EEPROM.update(11,att_f1);EEPROM.update(12,att_f2);EEPROM.update(13,att_r1);EEPROM.update(14,att_r2);
     EEPROM.update(15,set_in);
    }
///////////////////////////////////////////////////////////////////////////////////////////////////////  

 if (newPosition != oldPosition) {
    oldPosition = newPosition;
    vol=vol-newPosition;myEnc.write(0);newPosition=0;w=1;if(vol<0){vol=0;}if(vol>94){vol=94;}audio();}
}// loop
 
void audio(){
        tda.setInitial();
        tda.setSub_setup(0,0,0); // off 55hz 85hz 120hz 160hz pass = int sub_f(0...5) || LPF front rear sub = int sub_out(0...3) 0 - default || 0 180 = int faza(0...1)
        tda.setLoud_f(mix,lon_f,0,0); // mix_in off || 400hz 800hz 2400hz Prohibition = int loud_f(0...3) || MIXING 1ch 2ch -- on off = mix_ch1(0...1) mix_ch2(0..1)
        tda.setIn(in); // in1 in2 in3 = int in(0...2)
        tda.setIn_gain(0,0); // 0...16 dB = int in_gain(0...16) || off on = int mute(0...1)
        tda.setVol(-vol+15); // -79...+15 dB = int vol(-79...15)
        tda.setFront_1(att_f1); // -79...+15 dB = int -79...15
        tda.setFront_2(att_f2); // -79...+15 dB = int -79...15
        tda.setRear_1(att_r1); // -79...+15 dB = int -79...15
        tda.setRear_2(att_r2); // -79...+15 dB = int -79...15
        tda.setSub1(0); // -79...+15 dB = int -79...15
        tda.setSub2(0); // -79...+15 dB = int -79...15
        tda.setBass_setup(0,bas_f); // 0.5 1.0 1.5 2.0 --- int 0...3, 60Hz 80Hz 100Hz 120Hz --- int 0...3
        tda.setMiddle_setup(0,mid_f); // 0.75 1.0 1.25 1.5 --- int 0...3, 500Hz 1kHz 1.5kHz 2.5kHz --- int 0...3
        tda.setTreble_setup(0,treb_f); // 0.75 1.25  --- int 0...1, 7.5kHz 10kHz 12.5kHz 15kHz --- int 0...3
        tda.setBass_gain(bas); // --15 ... +15 dB = int -15 ... 15 
        tda.setMiddle_gain(mid-15); // --15 ... +15 dB = int -15 ... 15
        tda.setTreble_gain(treb-15); // --15 ... +15 dB = int -15 ... 15
        tda.setLoudness_gain(lon); // 0 ... 15 dB = int 0 ... 15 
  }

void flash(){newPosition = myEnc.read()/2;} 
 
void readRds() {
isRDSReady = radio.readRDS();
radio.getRDS(&rdsInfo);
showPTY();
showPS();
showRadioText();
}

void showPTY() {
if ((isRDSReady == 1) && !strcmp(rdsInfo.programType, 
programTypePrevious, 16)) {
Serial.print(rdsInfo.programType);
strcpy(programTypePrevious, rdsInfo.programType);
Serial.println();
}}

void showPS() {
if ((isRDSReady == 1) && (strlen(rdsInfo.programService) == 8) && 
!strcmp(rdsInfo.programService, programServicePrevious, 8)) {
Serial.print("-=[ ");
Serial.print(rdsInfo.programService);
Serial.print(" ]=-");
strcpy(programServicePrevious, rdsInfo.programService);
Serial.println();
}}

void showRadioText() {
if ((isRDSReady == 1) && !strcmp(rdsInfo.radioText, radioTextPrevious, 65)){
Serial.print(rdsInfo.radioText);
strcpy(radioTextPrevious, rdsInfo.radioText);
Serial.println();
}}

bool strcmp(char* str1, char* str2, int length) {
for (int i = 0; i < length; i++) {
if (str1[i] != str2[i]) {
return false;}}
return true;}

void showFmSeek() {
if (isFmSeekMode) {
if (radio.seekSync(isFmSeekUp)) {
isFmSeekMode = false;
Serial.println("Seek stopped");
frequency = radio.getFrequency();
}}}

void displayInfo() {
    delay(10);
    Serial.print("Frequency:");
    Serial.println("<FREQ:"+String(frequency*0.01)+">");
    Serial.print(" Volume:");
    Serial.println(volume);
    Serial.print("Level:");
    Serial.println(radio.getLevel() / 10);
    Serial.print("Stereo:");
    Serial.println(radio.getStereoStatus());
}