Go Down

Topic: Need Some Help Segmenting a WS2811 Strip (Read 29 times) previous topic - next topic


Greetings, I need some help.  What I've been toying with for a while now is some code that flashes a WS2811 strip with color changes. etc using a MSGEQ7.  What I'm trying to do is segment leds i.e. 1,4,7,10 etc. for one color that corresponds to a frequency band from the MSGEQ7,  2,5,8,11 for another frequency band.  I've dug through numerous posts and code trying to find something that fits what I'm needing. But, I keep coming up short. Here's my code draft that I've been working with. The code works really well for flashing to music, but I'm trying to take it to the next level.  Once I get the segmenting figured out, my next step is some patterns that the strip cycles through when no music is playing.  I've got some "cases" for that, I'm just stuck at this step.  Any help is appreciated.

Code: [Select]

#include "FastLED.h"
#define NUM_LEDS 100     
#define DATA_PIN 4     
#define BRIGHTNESS  255  // reduce power consumption
#define LED_DITHER  0 // try 0 to disable flickering

#include "MSGEQ7.h"
#define pinAnalogLeft A4
#define pinAnalogRight A5
#define pinReset 10
#define pinStrobe 9
#define MSGEQ7_INTERVAL ReadsPerSecond(500)
#define MSGEQ7_BASS 0
#define MSGEQ7_MID 3
#define MSGEQ7_HIGH 6
#define MSGEQ7_SMOOTH 0// Range: 0-255

CMSGEQ7<MSGEQ7_SMOOTH, pinReset, pinStrobe, pinAnalogLeft, pinAnalogRight> MSGEQ7;

long COLOR[6]= { 0x00ff00, 0xff0000, 0x0000ff, 0xFFFF00, 0xFF00FF , 0x00ffff}; //green , red , blue , yellow , pink , paleblue

unsigned long interval=10000;     // the time we need to wait
unsigned long previousMillis=0;  // millis() returns an unsigned long.

int ledState = 0; // state variable for the LED
int colorIndex = 0;
void setup() {
  FastLED.addLeds<WS2811, DATA_PIN, BRG>(leds, NUM_LEDS);
  FastLED.setBrightness( BRIGHTNESS );
  FastLED.show(); // needed to reset leds to zero

  // This will set the IC ready for reading

void loop() {

    unsigned long currentMillis = millis(); // grab current time

    if ((unsigned long)(currentMillis - previousMillis) >= interval) {
   ledState = !ledState; // "toggles" the state
   digitalWrite(13, ledState); // sets the LED based on ledState
   // save the "current" time
   previousMillis = millis();
  // Analyze without delay
  bool newReading = MSGEQ7.read(MSGEQ7_INTERVAL);
  // Led strip output
  if (newReading) {
    // visualize the average bass of both channels
    uint8_t x = MSGEQ7.get(MSGEQ7_BASS);
    uint8_t z = MSGEQ7.get(MSGEQ7_HIGH);
    //int x = MSGEQ7.get(MSGEQ7_BASS);
    //int y = MSGEQ7.get(MSGEQ7_MID);
    //int z = MSGEQ7.get(MSGEQ7_HIGH);

    // Reduce noise
      x = mapNoise(x);
      z = mapNoise(z);
    // Visualize leds to the beat

    CRGB color = CRGB::Blue;
    fill_solid(leds, NUM_LEDS, color);


    if(ledState > 0){
       colorIndex = colorIndex + 1;
       ledState = 0;

    if(colorIndex > 5) {
        colorIndex = 0;
    CRGB color1 = COLOR[colorIndex];       
    fill_solid(leds+5, NUM_LEDS, color1);

Go Up