FastLED + SEN-12642 SparkFun MUSIC VISUALIZER

Hello,

I am trying to create a sort of music visualizer with a WS2811B LED Strip and a SEN-12642 SparkFun sensor.

My general idea would be to use the the "beatsin16()" function of FastLED lib to generate a sin wave that pulse in two direction (from the middle of the led strip) accordingly to the music.
I was thinking of using the gate output of the sensor to sample the BPM of the music using some functions with millis() and then the envelope gate to determine the amplitute of the sin wave.

  void ledSinWaveMusic{
  // To keep colors within a determined range
  static byte gHueToken = 0;
  static byte gHue = 192;
  if (gHueToken == 0) { EVERY_N_MILLISECONDS( 5 ) { gHue++; }}
  if (gHueToken == 1) { EVERY_N_MILLISECONDS( 5 ) { gHue--; }}
  if (gHue == 255) {gHueToken = 1;}
  if (gHue == 192) {gHueToken = 0;}
  
  // Functions to run the LEDs Strip
  fadeToBlackBy( leds, NUM_LEDS, 5);
  int pos1 = beatsin16( 60 /*TO BE REPLACED BY SAMPLED BPM*/, (NUM_LEDS/2), NUM_LEDS-1);
  int pos2 = NUM_LEDS-pos1-1; 
  leds[pos1] += CHSV( gHue, 255, 255);
  leds[pos2] += CHSV( gHue, 255,255);
  FastLED.show();
  }

Do you think it is a feasible idea?

One question: I don't get why, as highest value for the beatsin16() I shall put NUM_LEDS-1 and not NUM_LEDS (which seems to be more reasonable but surely it's not...). If I put NUM_LEDS-1 it correctly lights all the LEDs while if I put NUM_LEDS the code freeze...

Also, I am going crazy to fade the sin wave once it at reached its peak: I'd like the sin wave to run ONLY from the center of the led strip outward but not back to the center (basically as the music "beat" a stream of light should run, more or less accordingly to the envelope signal, towards the ends of the led strip and fade away).
I am trying to reset it with some IF statement but probably I don't get how it works...

I have checked here how the function is made in the library and another thing I don't understand (sorry I am new to this) is the following, accordingly to the link the function accepts many different input values:

LIB8STATIC uint16_t beatsin16( accum88 beats_per_minute, uint16_t lowest = 0, uint16_t highest = 65535, uint32_t timebase = 0, uint16:t phase_offset = 0)
  • beats_per_minute;
  • lowest;
  • highest;
  • timebase;
  • phase_offset
    But I have always seen it used just like beatsin16( beats, lowest, highest); does it mean that I could just add the two variable within () to modify the timebase and phase_offset while if I don't write anything they are set to "0"?
    Thank you very much for your help and I apology if I may have said something silly but I'm new to this...!

Alessandro

This topic was automatically closed 120 days after the last reply. New replies are no longer allowed.