Audio SmartLedBars

ACTUALIZACION DIC2023

En esta actualización, tenemos dos controladores, el de la placa roja y el controlador de pantalla que ahora interactuan, de forma que la ganancia de los amplificadores sera controlada por el controlador de pantalla, que a su vez nos dará información de importantes parametros como el timing y la secuencia, en este caso las salidas dac de la placa roja serviran para esto.

ACTUALIZACIÓN( OCTUBRE 2023)

Cuando diseñe este circuito con tres entradas de audio,la idea era de controlar tres salidas de pixel R,L y Sub, a sabiendas que solo disponemos de dos dac para el control de ganancia,nos faltaria otra para sub.

olvide coger mas entradas analogicas para potenciometros de lo que antes eran gain lpf y gain hpf.

Tambien quise disponer de una salida para pantalla tft que visualicen las lecturas,pero me estoy percatando de que puede enlentecer el proceso, asi que aunque no puedo variar el diseñoa no ser que quiera gastar mas,he pensado en utilizar otro esp 32 para la tft y por que no tambien para el control de la ganancia sub,Asi podremos liberar las salidas 2-5-23 y 18 para configurarlas como queramos.

Despues de un analisis de practicas anteriores vemos que necesitamos para cada canal (3), de un potenciometro de control de entrada de audio y un potenciometro de control de ganancia, y como en este diseño no tenemos dac para el tercer canal sub, podriamos mandar en paralelo la señal de audio convertida en nivel de tensión al esp32 dedicado al tft, pero veo que se volveria a ralentiar el proceso

asi que lo que probare es poner potenciometros dobles para controlar manualmente la ganancia de sub


Sketchs:

smartledbars salidas de bajo nivel-conexion simultanea altavoces con dos tarjetas de control
 
*/


#include <FastLED.h>
# define LPF_IN_PIN 34             // converter lpf 
# define HPF_IN_PIN 36            // converter hpf 
#define DATA_PIN_LPF    13
#define DATA_PIN_HPF    2
#define N_PIXELS    144
CRGB ledslpf[N_PIXELS];
CRGB ledshpf[N_PIXELS];
#define Inputlpf  (analogRead(LPF_IN_PIN))
#define Inputhpf  (analogRead(HPF_IN_PIN))
#define Input39  (analogRead(39))//gain lpf
#define Input35  (analogRead(35))
#define Input32  (analogRead(32))//gain hpf
#define pOne 19  //19HL 
#define switch (!digitalRead(pOne))
// some of this variables can no be in use

int  ctrl_brigthness;//255;
uint8_t hue,hue2,hue3,spd,spdchg,chg;
uint8_t inputlpf,inputhpf;
uint8_t lpf,hpf;


///////////////////////rythms ////////////////
int d,gainhpf,gainlpf,lspd,hspd,m_spd=1;
uint32_t v1,v2,w=1,m;
uint32_t input39,input32;


void setup() {
  Serial.begin(9600);
   pinMode(pOne,INPUT_PULLUP);
    Serial.begin(9600);
   FastLED.addLeds<NEOPIXEL, DATA_PIN_LPF>(ledslpf, N_PIXELS);
   FastLED.addLeds<NEOPIXEL, DATA_PIN_HPF>(ledshpf,N_PIXELS);
   FastLED.clear();
      FastLED.show();
        
  analogSetPinAttenuation (34, ADC_11db);
   analogSetPinAttenuation (36, ADC_11db);
  analogSetPinAttenuation (39, ADC_11db);
 analogSetPinAttenuation (32, ADC_11db);
}
 

void loop() {
 FastLED.setBrightness(ctrl_brigthness);
  ctrl_brigthness=200;
  Vumeter();

FastLED.show();
dacWrite(25, gainlpf);
 dacWrite(26, gainhpf);
 input32=map(Input32,0,4095,255,150);
      input39=map(Input39,0,4095,255,150);
    // para gain hpf zona exclusion 94-145,incrementa de 0 a 100 y de 255 a 145
//gainlpf exclusion 90-134, comportamiento igualque hpf en sus tramos
//tener en cuenta que depende de la entrada de adio si se puenteael condensador o no
 

     gainhpf=map(hpf,0,N_PIXELS,146,input32);//potenciometros controlan picos de audio con mayor o menor rango)
gainlpf=map(lpf,0,N_PIXELS,150,input39); //dac lpf 
 
    if (switch){w+=1;delay(500);if ( w>2){w=1;}}

  }
  void Vumeter(){
   
//Serial.println(gainhpf);
//Serial.println(gainlpf);
 inputlpf =map(Inputlpf,0,4095,0,N_PIXELS);
 inputhpf =map(Inputhpf,0,4095,0,N_PIXELS);
          
   
  if (inputlpf>lpf) {lpf+=1;}else if (inputlpf<lpf) {lpf-=1;}
  if (lpf < 1) {  lpf = 1;  } 
  if (lpf>N_PIXELS){lpf=N_PIXELS;}

  if (inputhpf>hpf) {hpf+=1;}else if (inputhpf<hpf) {hpf-=1;}
  if (hpf < 1) {  hpf = 0;  } 
  if (hpf>N_PIXELS){hpf=N_PIXELS;}
  

  
   
   

                /////////-----------W1 ------------/////////

if (w==1){
      
 hue=0;//rojo
hue2=160;//azul
hue3=128;//aqua

 int blur_value1=100;//map(output25,0,250,1,100);
  int blur_value2=100;//map(output25,0,250,1,100);
   ledslpf[lpf] = CHSV(hue2, 200, 130);
   ledshpf[hpf] = CHSV(hue3, 200, 130);
  for (int k1 = N_PIXELS; k1>lpf; k1--){ledslpf[k1] = CRGB::Black; }
 for (int k2 = N_PIXELS; k2>hpf; k2--){ledshpf[k2] = CRGB::Black; }
   blur1d(ledslpf, N_PIXELS, blur_value1);
     blur1d(ledshpf, N_PIXELS, blur_value2);
     if (lpf>5&&lpf<75){  for (int j1 = 0; j1<lpf; j1++){ledslpf[j1] = CHSV(hue, 255, 75);} }   
   if (lpf>130){  for (int j1 = 0; j1<lpf; j1++){ledslpf[j1] = CHSV(hue, 255, 75);} }
   if (hpf>5&&hpf<75){for (int j2 = 0; j2<hpf; j2++){ledshpf[j2] = CHSV(hue2, 255, 100);} }
      if (hpf>130){  for (int j2 = 0; j2<hpf; j2++){ledshpf[j2] = CHSV(hue2, 255, 75);} } 
 
                       
     
 

if (lpf+hpf<N_PIXELS){
  
v1=map (lpf,0,N_PIXELS,1,2);
v2=map (hpf,0,N_PIXELS,1,3);
  if(hpf<15){v1=1;}
  lspd=map(lpf,0,N_PIXELS,5,35);
   hspd=map(hpf,0,N_PIXELS,25,3)  ;
d=(lspd+hspd)/(v1+v2+((hpf+lpf)/100));}

   
if (lpf+hpf>N_PIXELS){

v1=map (lpf,0,N_PIXELS,1,3);
v2=map (hpf,0,N_PIXELS,4,2);
  lspd=map(hpf,0,N_PIXELS,35,10);
 hspd=map(lpf,0,N_PIXELS,10,45)  ;   
 
d=(lspd+hspd)/(v1+v2+((lpf+hpf)/20));}
 if (lpf>hpf&&(lpf<70)){d+=5;}
if (lpf>hpf&&(lpf>70)){d+=1;}
if(hpf>lpf&&hpf>input32/2){d=1;}
delay(d);}


                /////////-----------W2 ------------/////////
if (w==2){
  hue=0;//rojo
hue2=96;//verde
hue3=160;//azu


 

  
    ledslpf[lpf] = CHSV(hue, 255, 50+lpf);
  
 
  for (int k1 = N_PIXELS; k1>lpf; k1--){ledslpf[k1] = CRGB::Black;}
 for (int k2 = N_PIXELS; k2>hpf; k2--){ledshpf[k2] = CRGB::Black;}//se mueven y permanecen encendidos
 
  // if (lpf>N_PIXELS-22) {  for (int j1 = 0; j1<lpf; j1++){ledslpf[j1] = CHSV(hue3, 255, 100); }}
if(hpf>N_PIXELS-hpf){ledshpf[hpf] = CHSV(64, 255, 255);for (int j2 = 0; j2<hpf; j2++){ledshpf[j2] = CHSV(160, 255, hpf);}}
if(hpf<N_PIXELS-hpf){ledshpf[hpf] = CHSV(160, 255,255 );for (int j2 = 0; j2<hpf; j2++){ledshpf[j2] = CHSV(96, 255, hpf);}}
  // for (int j1 = 0; j1<lpf; j1++){ledslpf[j1] = CHSV(hue, 255, 75); }
   //for (int j2 = 0; j2<hpf; j2++){ledshpf[j2] = CHSV(hue2, 255, 100);}
blur1d(ledslpf, N_PIXELS,0);
     blur1d(ledshpf, 1, 100);
 FastLED.show();

if (hpf<60||lpf<60){d=map(hpf+lpf,0 ,N_PIXELS*2,25,0);}
if (hpf>600&&hpf<120){d=map(hpf+lpf,0 ,N_PIXELS*2,15,0);}
if (hpf>120||lpf>120){d=map(hpf+lpf,0 ,N_PIXELS*2,5,0);}
 delay(d);




}

  }

ACTUALIZACION SKETCHS NOV2023 DONDE SE INCLUYE CODIGO PLACA ROJA Y CODIGO DEPANTALLE TFT

           ///////////SMARTLEDBARS NOV2023 PLACA ROJA/////////////

#include <FastLED.h>
# define R_IN_PIN 36 
# define L_IN_PIN 39
# define S_IN_PIN 34   
#define DATA_PIN_R    21
#define DATA_PIN_L    19
#define DATA_PIN_S    17
#define N_PIXELS    144
#define InputR  (analogRead(R_IN_PIN))
#define InputL (analogRead(L_IN_PIN))
#define InputS (analogRead(S_IN_PIN))
#define PR (analogRead(15))// pot superior der
#define PL (analogRead(4))//pot superior izq
#define PM  (analogRead(2))//pot central centro
CRGB ledsR[N_PIXELS];
CRGB ledsL[N_PIXELS];
CRGB ledsS[N_PIXELS];
#define N_PIXELS_HALF (N_PIXELS / 2)
#define pOne 5// situado en panel 
#define switch (!digitalRead(pOne))


int peak_fallR,peak_fallL,peak_fallS;
int  ctrl_brigthness=200;
uint8_t hue,hue2,hue3,hue4,huevR,huevL,huev,sm,v1;
uint8_t inputR,inputL,inputS;
uint8_t R,L,S;
///////////////////////////////
static uint8_t dotCountR,dotCountL,dotCountS;
uint8_t peakRR,peakLL,peakSS;
uint8_t *peakR,*peakL,*peakS; //Pointer variable declaration 

int u,pl,pr,pm,pmm,sq,sqnce;
///////////////////////rythms ////////////////
int delta,delta2,DRL,DS,w=1,h=1,d,x,y,z,dac25,dac26,z1,z2,x1,sp;



void setup() {
  pinMode(pOne,INPUT_PULLUP);
 
 
 FastLED.addLeds<NEOPIXEL, DATA_PIN_R>(ledsR, N_PIXELS);
 FastLED.addLeds<NEOPIXEL, DATA_PIN_L>(ledsL,N_PIXELS);
   FastLED.addLeds<NEOPIXEL, DATA_PIN_S>(ledsS,N_PIXELS);
     FastLED.clear();
      FastLED.show();
    analogSetPinAttenuation (34, ADC_11db);
   analogSetPinAttenuation (36, ADC_11db);
    analogSetPinAttenuation (39, ADC_11db);
     analogSetPinAttenuation (4, ADC_11db);
 analogSetPinAttenuation (15, ADC_11db);
         
}
 //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

void loop() {

   FastLED.setBrightness(ctrl_brigthness);
//ctrl_brigthness=potm;
    Peak_Fall();
  Vumeter();
  
        EVERY_N_SECONDS(2){huev+=32,1000;}

////////////////////ALTERNATIVA SI SE QUIERE TRABAJAR EN MONO PARA VISUALIZACION SINCRÓNICA//////////////////////////
   // x=map(S,0,N_PIXELS,2000,100);
   // EVERY_N_MILLISECONDS(x){ sm++;if ( sm>2){sm=1;}}
//if (sm==1){h=1;L=R;huevL=huevR=hue3;}
//if (sm==2){h=1;R=L;huevR=huevL=hue4;}
//////////////////////////////////////////////////////////////////////////////////////////////////////////////
///////////////////////////////CONTROL AUTOMATICO DE GANANCIA///////////////////////////////////////////////

/*
 hay dos margenes de control, entre 0-110 y 255-140, siendo el intervalo 110-140 prohibido, opto por el de 255-140
 if (L<R){dacL-=10;dacR+=10;}if (L>R){dacR-=10;dacL+=10;}if (dacL<140||dacR<140){dacL=140;dacR=140;}
 */

  
  ///////////////////////////////////////////////////////////////////////////////////////////////////////////

  if (R>N_PIXELS-1) {R=N_PIXELS;}if (L>N_PIXELS-1) {L=N_PIXELS;}if (S>N_PIXELS-1) {S=N_PIXELS;}
  
 if (switch){w+=1;delay(500);if ( w>3){w=1;}}

 FastLED.show();


  }

///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////



  ////////////////////////////////////PEAK FALL//////////////////////////
void Peak_Fall(){
  //SI SE COMENTA LOS DOTS SE PARANdotCount
  ++dotCountR;
        if(dotCountR>=peak_fallR&&peakRR> 0){peakRR--;dotCountR=0; }
         ++dotCountL;
         if(dotCountL>=peak_fallL&&peakLL > 0){peakLL--;dotCountL=0; }
          ++dotCountS;
          if(dotCountS>=peak_fallS&&peakSS > 0){peakSS--;dotCountS=0; }
 }

                                         ///Vumeter ////
void Vumeter(){
   hue=0;//rojo
hue2=160;//azul
hue3=128;//aqua
hue4=64;//amarillo
huevR=hue3;
huevL=hue4;

  inputR = map(InputR,0,4095,0,N_PIXELS); 
    inputL = map(InputL,0,4095,0,N_PIXELS); 
      inputS = map(InputS,0,4095,0,N_PIXELS); 
      

 if (inputR>R) {R+=1;}else if (inputR<R) {R-=1;}
  if (R< 1) {  R = 0;  } 
  if (R>N_PIXELS){R=N_PIXELS;}


  if (inputL>L) {L+=1;}else if (inputL<L) {L-=1;}
  if (L< 1) {  L = 0;  } 
  if (L>N_PIXELS){L=N_PIXELS;}
  

    if (inputS>S) {S+=1;}else if (inputS<S) {S-=1;}
  if (S< 1) {  S = 0;  } 
  if (S>N_PIXELS){S=N_PIXELS;}

//if (R>L){L=R;}
     // if (L>R){R=L;}
 


                /////////-----------ESCENAS  h1--h2---h3------------/////////

            

 
 if (h==1){
  if (pm<=20){
  if (R>L){L=R;} if (L>R){R=L;}
  }
  
   peak_fallR=1;
   peak_fallL=1;
   peak_fallS=1;
   peakR=&peakRR;
 peakL=&peakLL;
 peakS=&peakSS;
    //R
   if (R>*peakR){ *peakR = R;  }
    if (*peakR>0&&*peakR <= N_PIXELS - 1){ ledsR[*peakR] = CHSV(huevR, 255, 150); }
   for (int k1 = N_PIXELS; k1>R; k1--){ledsR[k1] = CRGB::Black; } 
  blur1d(ledsR, N_PIXELS, R);

//L
   if (L>*peakL){ *peakL = L;  }
    if (*peakL>0&&*peakL <= N_PIXELS - 1){ ledsL[*peakL] = CHSV(huevL, 255, 150); }
       for (int k2 = N_PIXELS; k2>L; k2--){ledsL[k2] = CRGB::Black; } 
  blur1d(ledsL, N_PIXELS, L);

 //S
   if (S>*peakS){ *peakS = S;  }
      if (*peakS>0&&*peakS <= N_PIXELS - 1){ ledsS[*peakS] = CHSV(hue2, 255, 150); }
     for (int k3 = N_PIXELS; k3>S; k3--){ledsS[k3] = CRGB::Black; } 
  blur1d(ledsS, N_PIXELS, S);
 }


 if (h==2){if (R>L){L=R;} if (L>R){R=L;}
   peak_fallR=1;
   peak_fallL=1;
   peak_fallS=1;
 peakR=&peakRR;
 peakL=&peakLL;
 peakS=&peakSS;
   
    
   if (R> *peakR){    *peakR = R;  }
   for (int k1 = N_PIXELS; k1>R; k1--){ledsR[k1] = CRGB::Black; } 
 if (*peakR> 0 && *peakR <= N_PIXELS - 1){ ledsR[*peakR] = CHSV(huevR, 255, 130);ledsR[N_PIXELS-1-*peakR] = CHSV(huevR, 255, 130); }
   
  blur1d(ledsR, N_PIXELS,R);

 if (L>*peakL){ *peakL = L;  }
  for (int k2 = N_PIXELS; k2>L; k2--){ledsL[k2] = CRGB::Black; } //oj con elorden que ocupa esta linea
    if (*peakL>0&&*peakL <= N_PIXELS - 1){ ledsL[*peakL] = CHSV(huevL, 255, 130); ledsL[N_PIXELS-1-*peakL] = CHSV(huevL, 255, 130); }
  
  blur1d(ledsL, N_PIXELS, L);


   if (S>*peakS){ *peakS = S;  }
 for (int k3 = N_PIXELS; k3>S; k3--){ledsS[k3] = CRGB::Black; }
    if (*peakS>0&&*peakS <= N_PIXELS - 1) {ledsS[*peakS] = CHSV(hue2, 255, 150);ledsS[N_PIXELS-1-*peakS] = CHSV(hue2, 255, 130);  }
            
  blur1d(ledsS, N_PIXELS, S);

  } 


if (h==3){
 peakR=&peakRR;
 peakL=&peakLL;
 peakS=&peakSS;
peak_fallR=pm;
   peak_fallL=1;
   peak_fallS=2;
   peak_fallR=1;



  for (int j1 = 0; j1<R; j1++){ledsR[j1] = CHSV(huevR, 255, 75);}
   for (int k1 = N_PIXELS; k1>R; k1--){ledsR[k1] = CRGB::Black; }
 if (R> *peakR){    *peakR =R;  }
     if (*peakR > 0 && *peakR<= N_PIXELS - 1){  ledsR[*peakR] = CHSV(huev, 255, 150);}
     
    
 
 for (int k3 = N_PIXELS; k3>S; k3--){ledsS[k3] = CRGB::Black; }
  for (int j3 = 0; j3<S; j3++){ledsS[j3] = CHSV(hue2, 255, 100);}
     if (S>*peakS){ *peakS = S;  }  
       if (*peakS>0&&*peakS <= N_PIXELS - 1) {ledsS[*peakS] = CHSV(huev, 255, 150); } 


 
  for (int j2 = 0; j2<L; j2++){ledsL[j2] = CHSV(huevL, 255, 75);}
  for (int k2 = N_PIXELS; k2>L; k2--){ledsL[k2] = CRGB::Black; }
 if (L> *peakL){    *peakL =L;  }
     if (*peakL > 0 && *peakL<= N_PIXELS - 1){  ledsL[*peakL] = CHSV(huev, 255, 150);}
     
}



//if(w==4){ EVERY_N_SECONDS(5){h++;if (h>3){h=1;}}


if (w==1){h=1;}     if (w==2){h=2;} if (w==3){h=3;}
/////////////////////////////////////ritmo///////////////////////////////////////////////
//


//y=map(S,0,N_PIXELS,25,1);

/////////////////////////////////algoritmo para ajustar el ritmo///////////////////////////////////////
 

////////////////////////////////scene2////////////////////////////////////////
///
z1=map(PL,0,4095,1,8);
z2=map(PR,0,4095,1,12);
pl=sq*z1;//map(PL,0,4095,1,40);//ligado a z1
pr=sq*z2;//map(PR,0,4095,1,100);
pm=map(PM,0,4095,1,40);

  dacWrite(25,dac25); dac26=d*6;//TIMING
 dacWrite(26, dac26);dac25=sqnce;//
 DRL=N_PIXELS-(R+L)/2;
 DS=N_PIXELS-S;
 
if (DRL<DS){delta=DRL;}
if (DRL>DS) {delta=DS;}
  
sqnce=delta*1.7;

if (sqnce<50){sq=5;}if (sqnce>=50&&sqnce<100){sq=4;}if (sqnce>=100&&sqnce<150){sq=3;}if (sqnce>=150&&sqnce<200){sq=2;}if (sqnce>=200){sq=1;}
if (sqnce>250){sqnce=250;}
///////////////////////////////////cambio de scena
if (sq<=3){
if (R>S){delta2=R-S;}
if (S>R) {delta2=S-R;}
if (delta2==0){delta2=delta/5;} //para que aumente la velocidad con un d=5
if (delta2>pr){delta2=pr;}
if (delta2<pl){delta2=pl;}
 d=delta/delta2;
if (d>20){d=20;}
if (d<1){d=1;}
}
if (sq>3){
 if (R>S){delta2=R-S;}
if (S>R) {delta2=S-R;}
if (delta2==0){delta2=5;} //cuando sq=5 minimo d
if (delta2>pr){delta2=pr;}//VALORES  POSIBLES 1 A 100,,1/sq2,2/sq2,,3/sq2(VALORES<1 SER HARAN 1),,,,,maximo de 100 a 100/25=4
if (delta2<pl){delta2=pl;}
 d=delta2/sq;
if (d>20){d=20;}
if (d<1){d=1;}
}

/*
if (sq==1){d=sp;pl+=20;pr+=5;} 
if (sq==2){d=sp;pl-=1;}
if (sq==3){d=sp;pl+=1;}
if (sq==4){d=sp;pl+=1;}
if (sq==5){d=sp;pr-=1;}
*/


 

 

delay(d);

   }

CODIGO PANTALLA TFT SKETCH NOV2023


//NIVELES--EL NIVEL MAXIMO DE ENTRADA DE LOS CONVERTIDORES ES DE 3.6V,RESTANDO LA PERDIDA DE A RESISTENCIA DEL CABLE
//LO QUE LLEGARA AL CONTROLADOR DE PANTALLA SERAN UNOS 3.5V SUPERIOR A LOS 3.3V ADC DE  4095
//R
  

//GANANCIA--LA SALIDA MEDIDA DEL CONTROLADOR ESP32 ES DE 3.2V,CON UNA PEQUEÑA CAIDA DE TENSIÓN DEL CABLEADO HACE QUE 
//EN LA ENTRADA DE LOS PINES LLEGUE ENTRE 3.16.3.19V


#include <SPI.h>
#include <TFT_eSPI.h> // Hardware-specific library
#define TFT_GREY 0x5AEB
# define R_level 36           
# define L_level 39
# define S_level 34 
#define InputR  (analogRead(R_level))//R sample
#define InputL (analogRead(L_level))//L sample
#define InputS (analogRead(S_level))  //S sample
#define PL (analogRead(32))//EN PARALELO D4 PLACA ROJA pot izq superior
#define PM (analogRead(33))// pot central superior CONECTARDO EN PARALELO A PIN D2 PLACA ROJA
#define PR (analogRead(27))//EN PARALELO D15 PLACA ROJA pot derecho superior
//define POTM (analogRead(13)) //conectado a potenciometro volumen centro S
#define TIMING (analogRead(35))//PROCEDE DAC26 PLACA ROJA
#define SQNCE (analogRead(14))//PROCEDEDAC 25 PLACA ROJA
#define N_PIXELS    144    
TFT_eSPI tft = TFT_eSPI();       // Invoke custom library
#define pOne 15 //D15 
#define switch (!digitalRead(pOne))


float vRL,vS,vRLpre,vSpre;
float lvlR,lvlRpre,lvlS,lvlSpre,lvlL,lvlLpre;//los valores "pre" se definen para limpiar los datos secuenciales
int w=1,a=0,b=0,R,S,L,Rpre,Spre,Lpre,inputR,inputS,inputL,dacRL,dacRLpre,dacS,dacSpre;
int potm,potmpre,potl,potlpre,potr,potrpre,pl,pm,pr,plpre,prpre,pmpre,dac26,dac26pre,dac25,dac25pre,pmm,timingpre,timing, sqncepre,sqnce,sq,sqpre;
boolean dir;
void setup() {
           
  analogSetPinAttenuation (InputR, ADC_11db);
   analogSetPinAttenuation (InputL, ADC_11db);
  analogSetPinAttenuation (InputS, ADC_11db);
   analogSetPinAttenuation (13, ADC_11db);
   analogSetPinAttenuation (4, ADC_11db);
  analogSetPinAttenuation (35, ADC_11db);
  analogSetPinAttenuation (32, ADC_11db);
   analogSetPinAttenuation (33, ADC_11db);
  analogSetPinAttenuation (27, ADC_11db);
analogSetPinAttenuation (21, ADC_11db);
analogSetPinAttenuation (14, ADC_11db);

    pinMode(pOne,INPUT_PULLUP);
     

      tft.init();
  tft.setRotation(3);
   tft.setTextSize(2);
 tft.fillScreen(TFT_BLACK);
   
}


void loop(){
  dacWrite(25,dacS);//
 dacWrite(26, dacRL);//
 ///////////////////pot dobles asociados al voluen de entrad en secundario transformdores
//potm=map(POTM,0,4095,0,100); 


pl=map(PL,0,4095,1,8);
pr=map(PR,0,4095,1,12);
pm=map(PM,0,4095,1,2);//SCENE CHANGE NOW 1 AND 2

//if (pmm<25){pm=1;}if (pmm>25&&pmm<50){pm=1;}if (pmm>50&&pmm<75){pm=3;}if (pmm>75&&pmm<100){pm=4;}if (pmm>100){pm=5;}

//dacS=map(R+L,0,N_PIXELS*2,180,255);
//dacRL=map(S,0,N_PIXELS,pl,pr);
// PARA PODER VISUALIZAR VLORES BAJOS DE INFORMACION A TRAVES DE LA LINEA DAC QUE NO ES MAS QUE UNA SEÑAL DC DE 0 A 3,2 V
// EN LA FUENTE MULTIPLICAMOS LOS VALORES BAJOS -EN NUESTRO CASO DEL 1 AL 5 -POR 50, Y EN EL RECEPTOR DIVIMOS POR 50, DE FORMA
//QUE LOS VALORES DIGITALES 0-255 EN SIMILITUD A UNA PORTADORA DE RADIOFREQ, LOS VALORES BAJOS ES LA INFORMACION QUE SE ENVIA Y LUEGO
//QUEREMOS RECUPERAR.

 timing=map(TIMING,0,4095,0,255)/6; 
 sqnce=map(SQNCE,0,4095,0,255); 
if (sqnce<50){sq=5;}if (sqnce>=50&&sqnce<100){sq=4;}if (sqnce>=100&&sqnce<150){sq=3;}if (sqnce>=150&&sqnce<200){sq=2;}if (sqnce>=200){sq=1;}


if (sq==5){dir=1;}else {dir=0;}
if (!dir){
dacS=map(R+L,0,N_PIXELS*2,180,255);
dacRL=map(S,0,N_PIXELS,180,160);}
     if (dir){
dacS=map(S,0,N_PIXELS,180,255);
dacRL=map(R+L,0,N_PIXELS*2,165,190);

     }



  //CONTROL DE NIVELESDE ENTRADA (lvl) valores dentro del intervalo de tension 0 - 3.15v
  inputR =map(InputR,0,4095,0,N_PIXELS);
 inputL =map(InputL,0,4095,0,N_PIXELS);
  inputS =map(InputS,0,4095,0,N_PIXELS);
  lvlR=InputR*3.15/4095;
    lvlL=InputL*3.15/4095;
      lvlS=InputS*3.15/4095;
 // VOLTAJE PROPORCIONAL DAC APLICADO A LOS CONVERTIDORES
//RL=dacRL*(3.17/255);
//vS=dacS*(3.17/255);//se pone 1,33 p q es la proporcion digital de 106

  //if (L>R){R=L;}
    //  if (R>L){L=R;}
  
  if (inputR>R) {R+=5;}else if (inputR<R) {R-=5;}
  if (R< 1) {  R = 0;  } 
  if (R>N_PIXELS){R=N_PIXELS;}

  if (inputL>L) {L+=5;}else if (inputL<L) {L-=5;}
  if (L< 1) {  L = 0;  } 
  if (L>N_PIXELS){L=N_PIXELS;}



    if (inputS>S) {S+=5;}else if (inputS<S) {S-=5;}
  if (S< 1) {  S = 0;  } 
  if (S>N_PIXELS){S=N_PIXELS;}


  if (switch){w+=1;delay(500);if ( w>3){w=1;}}
  
//////////////////////////////////////////////////////////W1//////////////////////////////////////////////////
if (w==1&&a==0){tft.fillScreen(TFT_BLACK);a=1;}

if (w==1&&a==1){

 tft.setTextColor(TFT_WHITE);
 tft.setCursor(20,20);
 tft.println("pix-R");
//R
 tft.setTextColor(TFT_BLACK);
  tft.setCursor(40,50);
  tft.println(Rpre);
  tft.setTextColor(TFT_YELLOW);
  tft.setCursor(40,50);
  tft.println(R);
  Rpre=R;

tft.setTextColor(TFT_WHITE);
tft.setCursor(232,20);
 tft.println("pix-L");
 //L  
   tft.setTextColor(TFT_BLACK);
  tft.setCursor(252,50);
  tft.println(Lpre);
  tft.setTextColor(TFT_YELLOW);
  tft.setCursor(252,50);
  tft.println(L);
 Lpre=L;

tft.setTextColor(TFT_WHITE);
tft.setCursor(116,20);
 tft.println("pix-S");
//S
  tft.setTextColor(TFT_BLACK);
  tft.setCursor(136,50);
  tft.println(Spre);
  tft.setTextColor(TFT_YELLOW);
  tft.setCursor(136,50);
  tft.println(S);
  Spre=S;


////////////////////////////////////////////////CABECERA CENTRAL//////////////////////////////

//RL
 tft.setTextColor(TFT_WHITE);
 tft.setCursor(20,90);
 tft.println("DAC-RL");
 tft.setTextColor(TFT_BLACK);
  tft.setCursor(20,120);
  tft.println(dacRLpre);
  tft.setTextColor(TFT_BLUE);
  tft.setCursor(20,120);
  tft.println(dacRL);
  dacRLpre=dacRL;


//mode
  tft.setTextColor(TFT_WHITE);
   tft.setCursor(125,120);
 tft.println("MODE");
if (!dir){
    tft.setTextColor(TFT_BLACK);
     tft.setCursor(130,150);
     tft.println("DIR");
    tft.setTextColor(TFT_BROWN);
    tft.setCursor(130,150);
  tft.println("INV");}
  if (dir){
    tft.setTextColor(TFT_BLACK);
     tft.setCursor(130,150);
     tft.println("INV");
    tft.setTextColor(TFT_YELLOW);
    tft.setCursor(130,150);
  tft.println("DIR");}



//S
tft.setTextColor(TFT_WHITE);
tft.setCursor(232,90);
 tft.println("DAC-S");
 tft.setTextColor(TFT_BLACK);
  tft.setCursor(232,120);
  tft.println(dacSpre);
  tft.setCursor(232,120);
   tft.setTextColor(TFT_BLUE);
  tft.println(dacS);
  dacSpre=dacS;




                                          //cabecera inferior

  tft.setTextColor(TFT_WHITE);
 tft.setCursor(20,180);
 tft.println("-PL-");
tft.setTextColor(TFT_BLACK);
 tft.setCursor(30,210);
 tft.print(plpre);
 tft.setTextColor(TFT_YELLOW);
 tft.setCursor(30,210);
 tft.print(pl);
  plpre=pl;



 tft.setTextColor(TFT_WHITE);
tft.setCursor(232,180);
 tft.println("-PR-");
  tft.setTextColor(TFT_BLACK);
 tft.setCursor(242,210);
 tft.print(prpre);
 tft.setTextColor(TFT_YELLOW);
 tft.setCursor(242,210);
 tft.print(pr);
   prpre=pr;

 

 delay(100);





}

///////////////////////////////////////////////////////////////W2////////////////////////////////////////////////////////////////////


  if (w==2&&a==1){tft.fillScreen(TFT_BLACK);a=2;delay(100);}
        //cabecera superior
        if (w==2&&a==2){


 tft.setCursor(90,10);
   tft.setTextColor(TFT_BLUE);
 tft.print("SMARTLEDBARS");
 tft.setTextColor(TFT_RED);
 tft.setCursor(110,40);
  tft.print("NOV 2023");

  
 //circulos
 tft.setCursor(300,230);
 tft.setTextColor(TFT_BLACK); tft.println(Rpre); tft.println(R);  Rpre=R;
 tft.setTextColor(TFT_BLACK); tft.println(Spre); tft.println(S);  Spre=S;
 tft.setTextColor(TFT_BLACK);tft.println(Lpre); tft.println(L);  Lpre=L;
 
 tft.fillCircle(50, 145, R/2, TFT_BLACK);
  tft.fillCircle(50, 145, Rpre/3,TFT_GREEN);

   tft.fillCircle(155, 145,S/1.5, TFT_BLACK);
  tft.fillCircle(155, 145, Spre/3,TFT_BLUE);
  

   tft.fillCircle(260, 145,L/2, TFT_BLACK);
  tft.fillCircle(260, 145, Lpre/3, TFT_YELLOW);


}
///////////////////////////////////////////////////////////w3////////////////////////////////////////////////


if (w==3&&a==2){tft.fillScreen(TFT_BLACK);a=0;}


if (w==3&&a==0){


 //----------

 tft.setTextColor(TFT_WHITE);
 tft.setCursor(15,20);
 tft.println("PL");

 tft.setTextColor(TFT_BLACK);
  tft.setCursor(40,50);
  tft.println(plpre);
  tft.setTextColor(TFT_YELLOW);
  tft.setCursor(40,50);
  tft.println(pl);
  plpre=pl;

//-------
tft.setTextColor(TFT_WHITE);
tft.setCursor(125,20);
 tft.println("SCENE");

  tft.setTextColor(TFT_BLACK);
  tft.setCursor(136,50);
  tft.println(pmpre);
  tft.setTextColor(TFT_YELLOW);
  tft.setCursor(136,50);
  tft.println(pm);
  pmpre=pm;

//-------
tft.setTextColor(TFT_WHITE);
tft.setCursor(232,20);
 tft.println("PR");
 
   tft.setTextColor(TFT_BLACK);
  tft.setCursor(252,50);
  tft.println(prpre);
  tft.setTextColor(TFT_YELLOW);
  tft.setCursor(252,50);
  tft.println(pr);
 prpre=pr;




  //CENTRO



 //timing
  tft.setTextColor(TFT_WHITE);
 tft.setCursor(15,100);
 tft.println("TIMING");
 tft.setTextColor(TFT_BLACK);
  tft.setCursor(40,120);
  tft.println(timingpre);
  tft.setTextColor(TFT_GREEN);
  tft.setCursor(40,120);
  tft.println(timing);
  timingpre=timing;



//mode
tft.setTextColor(TFT_WHITE);
 tft.setCursor(125,100);
 tft.println("MODE");
 
  if (!dir){
    tft.setTextColor(TFT_BLACK);
     tft.setCursor(125,120);
     tft.println("DIR");
    tft.setTextColor(TFT_BROWN);
    tft.setCursor(125,120);
  tft.println("INV");}
 

  if (dir){
    tft.setTextColor(TFT_BLACK);
     tft.setCursor(125,120);
     tft.println("INV");
    tft.setTextColor(TFT_YELLOW);
    tft.setCursor(125,120);
  tft.println("DIR");
  }


//sqnce
 tft.setTextColor(TFT_WHITE);
tft.setCursor(232,100);
 tft.println("SQNCE");
  tft.setTextColor(TFT_BLACK);
  tft.setCursor(252,120);
  tft.println(sqpre);
  tft.setTextColor(TFT_GREEN);
  tft.setCursor(252,120);
  tft.println(sq);
  sqpre=sq;
 
 

 
 



  




//INFERIOR

  tft.setTextColor(TFT_WHITE);
 tft.setCursor(232,180);
 tft.println("pix-L");
tft.setCursor(124,180);
 tft.println("pix-S");
tft.setCursor(20,180);
 tft.println("pix-R");

 
 tft.setTextColor(TFT_BLACK);
 tft.setCursor(248,210);
 tft.print(Lpre);
 tft.setTextColor(TFT_YELLOW);
 tft.setCursor(248,210);
 tft.print(L);
 Lpre=L;

 
 tft.setTextColor(TFT_BLACK);
 tft.setCursor(135,210);
 tft.print(Spre);
 tft.setTextColor(TFT_YELLOW);
 tft.setCursor(135,210);
 tft.print(S);
   Spre=S;

 
 tft.setTextColor(TFT_BLACK);
 tft.setCursor(35,210);
 tft.print(Rpre);
 tft.setTextColor(TFT_YELLOW);
 tft.setCursor(35,210);
 tft.print(R);
 Rpre=R;
 delay(100);
}
}

PROYECTO ORIGINAL:

Generalidades-

Este proyecto es el fruto de una idea que empecé a desarrollarla tiempo atras con una primera expectativa de practicar con FastLed y hacerme mi propio vu-meter. Posteriormente fui desarrollando la idea de que se pudiese detectar y presentar luminicamente los cambios de ritmo -musicalmente hablando- de una forma autónoma y con una idea muy simple que se traducira en un sencillo algoritmo que expresa que cuando los niveles graves suben la velocidad baja y cuando se sobreponen los niveles de frecuencia mayor la velocidad sube.

Aqui presento toda la electrónica utilizada y el sketch de programacion para el Esp-32.

Para su desarrollo , necesito separar las señales audibles por medio de dos filtros pasivos muy basicos de bajas frecuencias (lpf) y altas frecuencias (hpf)…..

Primero convierto el audio procedente de un receptor BT o cableada en una señal mono que duplicare con una amplificación individualizada para cada filtro como se puede ver en el primer esquema de bloques.Los convertidores hpf y lpf son una fase de conversión a niveles DC controladas por las salidas DAC del Esp-32, papel muy importante para que el algoritmo funcione.

Esquema detallado con los valores probados de los componentes.

Tratamiento y proceso de audio

-Proceso de audio: la entrada de audio puede ser interna a traves de un módulo receptor BT VHM-314 o externa procedente de una salida de auriculares de otro dispositivo. La conmutación de uno a otro se hace con un simple interruptor.Al mismo tiempo en paralelo esta la salida de audio para un amplificador externo. De una u otra fuente, la señal stereo se convierte en mono a traves de una red de dos resistencias de 10K cuyo punto central con respecto al comun o tierra se dirigiran simultáneamente a dos amplificadores como se puede ver en este bloquede abajo.

Las señales de audio se conducen a dos redes pasivas de filtros HPF y LPF constituidas por un transformador de aislamiento 600:600 ohmios ,un potenciometro de ajuste multivueltas y un condensador Cx/Cy cuyos valores elegidos son; C47 uF para el LPF y C10 nF para el HPF. De ahi pasaremos a los convertidores de nivel (0-3.2V) . La ganancia/amplificación de estos convertidores esta controlada por las salidas DAC del ESP32 .

En este diagrama de bloques general podemos continuar con el flujo de señal a la salida de los convertidores que no es mas que un nivel de tensión que se conecta dos entradas analógicas del ESP32 H&L

Filtros HPF y LPF:

Una vez elegí los valores del filtro pasivo, y teniendo en cuenta la dependencia con los niveles de entrada de audio, esto es, el volumen utilizado , hago un pequeño estudio-que omito- tomando un volumen del 80% para al final encontrar los margenes de trabajo donde la salida de cada filtro alcanza sus valores minimo y maximo, valores digitales (0-255) para las salidas DAC (25,26) conectadas a los convertidores de nivel respectivos, y estos fueron;

  • VALORES LPF: 130-150
  • VALORES HPF; 97-132

Quiere decir, que voy a trabajar con los valores dentro de estos márgenes para controlar la ganancia de forma que;

dacWrite(25, gain_lpf);
dacWrite(26, gain_hpf);

El ajuste debe hacerse siempre con el mismo nivel de tensión ,5V, porque entre 4.5V y 5.5V los niveles lpf y hpf pueden variar mucho.

En el sketch vienen los margenes que uso dentro de estos valores que,repito dependen del nivel de audio y la tensión o voltaje usado como expreso mas arriba, valores críticos.

El estudio de las frecuencias de corte merecería un tutorial aparte. y prefiero guardarmelo para mi para no pecar de tedioso.

Ide Arduino:

Este cogigo es del 10ago23, y es una composicion de cuatro modos incluido el apagado que utilizo

incluido en fecha 27sep23

/*Software for the ESP32 module corresponding to the original project "AudioSmartLedBars" owned by f81@crisalctime.com. 
 
 
*/


#include <FastLED.h>
# define LPF_IN_PIN 34             // converter lpf 
# define HPF_IN_PIN 36            // converter hpf 
#define DATA_PIN_LPF    13
#define DATA_PIN_HPF    2
#define N_PIXELS    144
CRGB ledslpf[N_PIXELS];
CRGB ledshpf[N_PIXELS];
#define Inputlpf  (analogRead(LPF_IN_PIN))
#define Inputhpf  (analogRead(HPF_IN_PIN))
#define Input39  (analogRead(39))
#define Input35  (analogRead(35))
#define Input32  (analogRead(32))
#define pOne 19  //19HL 
#define switch (!digitalRead(pOne))
// some of this variables can no be in use

int  ctrl_brigthness;//255;
uint8_t hue,hue2,spd,spdchg,chg;
uint8_t inputlpf,inputhpf;
uint8_t lpf,hpf;


///////////////////////rythms ////////////////
int d,gainhpf,gainlpf,lspd,hspd,m_spd=1;
uint32_t v1,v2,w=1,m;
uint32_t input39;


void setup() {
   pinMode(pOne,INPUT_PULLUP);
    Serial.begin(9600);
   FastLED.addLeds<NEOPIXEL, DATA_PIN_LPF>(ledslpf, N_PIXELS);
   FastLED.addLeds<NEOPIXEL, DATA_PIN_HPF>(ledshpf,N_PIXELS);
   FastLED.clear();
      FastLED.show();
        
  analogSetPinAttenuation (34, ADC_11db);
   analogSetPinAttenuation (36, ADC_11db);
  analogSetPinAttenuation (39, ADC_11db);
  spd=30;
}
 

void loop() {
 FastLED.setBrightness(ctrl_brigthness);
  ctrl_brigthness=200;
  Vumeter();

FastLED.show();
dacWrite(25, gainlpf);
 dacWrite(26, gainhpf);

  }
  void Vumeter(){
    
 inputlpf =map(Inputlpf,0,4095,0,N_PIXELS);
 inputhpf =map(Inputhpf,0,4095,0,N_PIXELS);
          
   
  if (inputlpf>lpf) {lpf+=1;}else if (inputlpf<lpf) {lpf-=1;}
  if (lpf < 1) {  lpf = 1;  } 
  if (lpf>N_PIXELS){lpf=N_PIXELS;}

  if (inputhpf>hpf) {hpf+=1;}else if (inputhpf<hpf) {hpf-=1;}
  if (hpf < 1) {  hpf = 0;  } 
  if (hpf>N_PIXELS){hpf=N_PIXELS;}
  

  
   
   

                /////////-----------LedBar effects ------------/////////



 
hue=0;
hue2=160;
int hue3=128;
 int blur_value1=100;//map(output25,0,250,1,100);
  int blur_value2=100;//map(output25,0,250,1,100);
   ledslpf[lpf] = CHSV(hue2, 200, 130);
   ledshpf[hpf] = CHSV(hue3, 200, 130);
  for (int k1 = N_PIXELS; k1>lpf; k1--){ledslpf[k1] = CRGB::Black; }
 for (int k2 = N_PIXELS; k2>hpf; k2--){ledshpf[k2] = CRGB::Black; }
   blur1d(ledslpf, N_PIXELS, blur_value1);
     blur1d(ledshpf, N_PIXELS, blur_value2);
     if (lpf>10&&lpf<20){  for (int j1 = 0; j1<lpf; j1++){ledslpf[j1] = CHSV(hue, 255, 75);} }   
     if (lpf>70&&lpf<75){  for (int j1 = 0; j1<lpf; j1++){ledslpf[j1] = CHSV(hue, 255, 75);} }
   if (lpf>130){  for (int j1 = 0; j1<lpf; j1++){ledslpf[j1] = CHSV(hue, 255, 75);} }
   if (hpf>10&&hpf<20){for (int j2 = 0; j2<hpf; j2++){ledshpf[j2] = CHSV(hue2, 255, 100);} }
  if (hpf>70&&hpf<75){for (int j2 = 0; j2<hpf; j2++){ledshpf[j2] = CHSV(hue2, 255, 100);} } 
    if (hpf>130){  for (int j2 = 0; j2<hpf; j2++){ledshpf[j2] = CHSV(hue3, 255, 75);} } 
 
                       
               
  
                                              ////////////////////////////

                  
if (switch){w+=1;delay(500);if ( w>4){w=1;}}
 Serial.println(w);
 ////////////////////////////// rhythm algorithm////////////////////////////////////////////////////
//spdchg=map (Input39,0,4095,0,100);
if (w==1){


gainhpf=map(hpf,0,N_PIXELS,146,175);
gainlpf=map(lpf,0,N_PIXELS,250,140); //dac lpf

//v2=map (Input32,0,4095,1,6);
//int d_m=2*m_spd;//map (spdchg,0,100,15,1);//

 

if ((hpf+lpf)<100){
  lspd=map(lpf,0,N_PIXELS,30,20);
 hspd=map(hpf,0,N_PIXELS,30,20)  ;
if (lpf>hpf&&(lspd-hspd)<5){d=(lspd-hspd)+lspd/1;}
if (lpf>hpf&&(lspd-hspd)>5){d=(lspd-hspd)+lspd/2;}
if (hpf>lpf&&(hspd-lspd)<5){d=(hspd-lspd)+hspd/1;} 
if (hpf>lpf&&(hspd-lspd)>5){d=(hspd-lspd)+hspd/1;}}


 if ((hpf+lpf)>100&&(hpf+lpf)<150){
  lspd=map(lpf,0,N_PIXELS,20,28);
 hspd=map(hpf,0,N_PIXELS,20,28) ;
if (lpf>hpf&&(lspd-hspd)<5){d=(lspd-hspd)+lspd/2;}
if (lpf>hpf&&(lspd-hspd)>5){d=(lspd-hspd)+lspd/3;}
if (hpf>lpf&&(hspd-lspd)<5){d=(hspd-lspd)+hspd/2;} 
if (hpf>lpf&&(hspd-lspd)>5){d=(hspd-lspd)+hspd/2;}}

  

if ((hpf+lpf)>150){
  lspd=map(lpf,0,N_PIXELS,28,25);
 hspd=map(hpf,0,N_PIXELS,28,25)  ;
if (lpf>hpf){d=lspd/3;}
if (hpf>lpf){d=hspd/4;gainhpf-=1;}}

//if (hpf>lpf){d--;}
//if (lpf>hpf){gainhpf--;}

delay(d);


 
  }

  if (w==2){
    


gainhpf=165;//map(hpf,0,N_PIXELS,108,97);
gainlpf=180;//map(lpf,0,N_PIXELS,250,50); //dac lpf
//m=5;


if ((hpf+lpf)<12*m){gainhpf-=19;gainlpf+40;
  lspd=map(lpf,0,N_PIXELS,30,10);
 hspd=map(hpf,0,N_PIXELS,30,10)  ;
if (lpf>hpf&&(lspd-hspd)<5){d=(lspd-hspd)+lspd/1;}
if (lpf>hpf&&(lspd-hspd)>5){d=(lspd-hspd)+lspd/2;}
if (hpf>lpf&&(hspd-lspd)<5){d=(hspd-lspd)+hspd/1;} 
if (hpf>lpf&&(hspd-lspd)>5){d=(hspd-lspd)+hspd/1;}}


 if ((hpf+lpf)>12*m&&(hpf+lpf)<30*m){
  lspd=map(lpf,0,N_PIXELS,20,30);
 hspd=map(hpf,0,N_PIXELS,20,30) ;
if (lpf>hpf&&(lspd-hspd)<5){d=(lspd-hspd)+lspd/2;gainhpf+=7;}
if (lpf>hpf&&(lspd-hspd)>5){d=(lspd-hspd)+lspd/2;gainlpf-=25;}
if (hpf>lpf&&(hspd-lspd)<5){d=(hspd-lspd)+hspd/1;gainhpf-=1;gainlpf+=50;} 
if (hpf>lpf&&(hspd-lspd)>5){d=(hspd-lspd)+hspd/2;gainhpf+=3;gainlpf+=50;}}
if ( (hpf+lpf)<100) {m=10;}
if( (hpf+lpf)>100&&(hpf+lpf)<180){m=8;}  
if( (hpf+lpf)>180){m=6;}

  
if ((hpf+lpf)>30*m){
v1=map (lpf,0,N_PIXELS,30,10);
v1=map (hpf,0,N_PIXELS,30,10);
if (hpf>60||lpf>60){
  lspd=map(lpf,0,N_PIXELS,30,v1);
 hspd=map(hpf,0,N_PIXELS,30,v1)  ;
if (lpf>hpf){d=lspd/2;gainlpf-=10;}
if (hpf>lpf){d=hspd/2;gainhpf+=10;gainlpf+=50;}}}



delay(d);

 
  }
 
if (w==4){
  ctrl_brigthness=0;
}




if (w==3){
                  
 
 gainhpf=map(hpf,0,N_PIXELS,146,175);
gainlpf=map(lpf,0,N_PIXELS,210,90); //dac lpf
  


  
if (lpf<80){
  
v1=map (lpf,0,N_PIXELS,1,2);
v2=map (hpf,0,N_PIXELS,1,3);
  if(hpf<15){v1=1;}
  lspd=map(lpf,0,N_PIXELS,5,35);
   hspd=map(hpf,0,N_PIXELS,25,3)  ;
d=(lspd+hspd)/(v1+v2);}

   
if (hpf>80&&lpf<100&&hpf<90&&lpf>80){

v1=map (lpf,0,N_PIXELS,1,3);
v2=map (hpf,0,N_PIXELS,4,2);
  lspd=map(hpf,0,N_PIXELS,35,10);
 hspd=map(lpf,0,N_PIXELS,10,45)  ;   
 
d=(lspd+hspd)/(v1+v2);}

if (lpf>100&&hpf>90){

v1=map (lpf,0,N_PIXELS,15,3);
v2=map (hpf,0,N_PIXELS,5,1);
  //lspd=map(hpf,0,N_PIXELS,30,5);
 //hspd=map(lpf,0,N_PIXELS,35,5)  ;   
 
d=((v2/v1)+v2);}

 

delay(d);

}
}


  
        
   
   

ACTUALIZACIÓN( 31 DIC 2023)

Codigo PRINCIPIO

////////////////////////////////////////

if (sq==1){d=sp;pl+=20;pr+=5;} 
if (sq==2){d=sp;pl-=1;}
/*Software for the ESP32 module corresponding to the original project "AudioSmartLedBars" owned by f81@10.18.2.21. 
 * This project is open and you can use it freely.
more details in http://10.18.2.21/wordpress/audio-smartledbars/
 
*/


#include <FastLED.h>
# define LPF_IN_PIN 34             // converter lpf 
# define HPF_IN_PIN 36            // converter hpf 
#define DATA_PIN_LPF    13
#define DATA_PIN_HPF    2
#define N_PIXELS    144
CRGB ledslpf[N_PIXELS];
CRGB ledshpf[N_PIXELS];
#define Inputlpf  (analogRead(LPF_IN_PIN))
#define Inputhpf  (analogRead(HPF_IN_PIN))
#define Input12  (analogRead(12)) //12HL in electronic board (H5)(EN PARALELO CON H6 QUE ES EL MANUAL LPF GAIN),NOT USED

// some of this variables can no be in use

int  ctrl_brigthness;//255;
uint8_t hue,hue2,spd,spdchg,chg;
uint8_t inputlpf,inputhpf;
uint8_t lpf,hpf;


///////////////////////rythms ////////////////
int d,gainhpf,gainlpf,lspd,hspd,m_lpf;
uint32_t v1,v2;
uint32_t input12;


void setup() {
    
   FastLED.addLeds<NEOPIXEL, DATA_PIN_LPF>(ledslpf, N_PIXELS);
   FastLED.addLeds<NEOPIXEL, DATA_PIN_HPF>(ledshpf,N_PIXELS);
   FastLED.clear();
      FastLED.show();
        
  analogSetPinAttenuation (34, ADC_11db);
   analogSetPinAttenuation (36, ADC_11db);
  analogSetPinAttenuation (12, ADC_11db);
  spd=30;
}
 

void loop() {
 FastLED.setBrightness(ctrl_brigthness);
  ctrl_brigthness=200;
  Vumeter();

FastLED.show();
dacWrite(25, gainlpf);
 dacWrite(26, gainhpf);

  }
  void Vumeter(){
    
 inputlpf =map(Inputlpf,0,4095,0,N_PIXELS);
 inputhpf =map(Inputhpf,0,4095,0,N_PIXELS);
          
   
  if (inputlpf>lpf) {lpf+=1;}else if (inputlpf<lpf) {lpf-=1;}
  if (lpf < 1) {  lpf = 1;  } 
  if (lpf>N_PIXELS){lpf=N_PIXELS;}

  if (inputhpf>hpf) {hpf+=1;}else if (inputhpf<hpf) {hpf-=1;}
  if (hpf < 1) {  hpf = 0;  } 
  if (hpf>N_PIXELS){hpf=N_PIXELS;}
  

  
   
   

                /////////-----------LedBar effects ------------/////////



 
hue=0;
hue2=160;
int hue3=128;
 int blur_value1=100;//map(output25,0,250,1,100);
  int blur_value2=100;//map(output25,0,250,1,100);
   ledslpf[lpf] = CHSV(hue2, 200, 130);
   ledshpf[hpf] = CHSV(hue3, 200, 130);
  for (int k1 = N_PIXELS; k1>lpf; k1--){ledslpf[k1] = CRGB::Black; }
 for (int k2 = N_PIXELS; k2>hpf; k2--){ledshpf[k2] = CRGB::Black; }
   blur1d(ledslpf, N_PIXELS, blur_value1);
     blur1d(ledshpf, N_PIXELS, blur_value2);
     if (lpf>10&&lpf<20){  for (int j1 = 0; j1<lpf; j1++){ledslpf[j1] = CHSV(hue, 255, 75);} }   
     if (lpf>70&&lpf<75){  for (int j1 = 0; j1<lpf; j1++){ledslpf[j1] = CHSV(hue, 255, 75);} }
   if (lpf>130){  for (int j1 = 0; j1<lpf; j1++){ledslpf[j1] = CHSV(hue, 255, 75);} }
   if (hpf>10&&hpf<20){for (int j2 = 0; j2<hpf; j2++){ledshpf[j2] = CHSV(hue2, 255, 100);} }
  if (hpf>70&&hpf<75){for (int j2 = 0; j2<hpf; j2++){ledshpf[j2] = CHSV(hue2, 255, 100);} } 
    if (hpf>130){  for (int j2 = 0; j2<hpf; j2++){ledshpf[j2] = CHSV(hue3, 255, 75);} } 
 
                       
               
  /////////////////////// rhythm algorithm/////////////////////////////

spdchg=map(Input12,0,4095,0,100);
gainhpf=map(hpf,0,N_PIXELS,120,105);
m_lpf=map (spdchg,0,100,100,145);//
gainlpf=map(lpf,0,N_PIXELS,145,m_lpf); //dac lpf

 if ((hpf+lpf)>N_PIXELS/2){
   lspd=map(lpf,0,N_PIXELS,5,spd);
 hspd=map(hpf,0,N_PIXELS,5,spd)  ;
if (lpf>hpf){d=(lspd-hspd)+lspd/2;spd=25;}
if (hpf>lpf){d=(hspd-lspd)+hspd/3;spd=18;} }

if ((hpf+lpf)<N_PIXELS/2){d=spd;}
 

delay(d);

 


}


  
        
   
   

Deja una respuesta

Tu dirección de correo electrónico no será publicada. Los campos obligatorios están marcados con *