WS2812B single row scrolling Help needed

Hello, I have almost no experience with WS2812b light strips and the only guides I can find are for making multi row scrolling text while I am only looking to use one row. I am currently integrating a WS2812B light strip into a tradeshow display to showcase flow by making the light scroll and change colors at certain points. I have only been able to get a single LED point to scroll using an if statement for the LED # and I will need to have every 6th or so LED scrolling to better show flow.

I am using the fast LED library and my current code is attached.

#include <FastLED.h>

#define LED_PIN     5
#define NUM_LEDS    60
#define LED_TYPE    WS2811
#define COLOR_ORDER GRB
CRGB leds[NUM_LEDS];

#define UPDATES_PER_SECOND 100



void setup() {
 FastLED.addLeds<WS2812B,LED_PIN, GRB> (leds,NUM_LEDS);   
 FastLED.setBrightness(50);


}
void loop(){
  for(int dot = 0; dot <NUM_LEDS; dot++){
    if(dot <= 30){
      leds[dot] = CRGB::Red;
    
    leds[dot+1] = CRGB::Red;
    leds[dot+2] = CRGB::Red;
    //delay(30);
    }
    else if (dot > 30){
    leds[dot] = CRGB::Blue;
    leds[dot+1] = CRGB::Blue;
    leds[dot+2] = CRGB::Blue; 
    //delay(5);
    }
  

    FastLED.show();
    leds[dot] = CRGB::Black;
    leds[dot+1] = CRGB::Black;
    leds[dot+2] = CRGB::Black;
    delay(30);
  }
  }

How would you make this code to run multiple LEDs at a time scrolling in the same direction?

Welcome to the forum

Please follow the advice given in the link below when posting code, in particular the section entitled 'Posting code and common code problems'

Use code tags (the </> icon above the compose window) to make it easier to read and copy for examination

Thank You for the info!

You write outside the array, never a good idea.

What is that unused wishful-thinking define for?

There are libraries that support matrix setups that include scrolling.

I don't really understand what you want to do, you already scroll three leds.

I want to scroll multiple sets of 3 LEDs at the same time but if I set dot =15 after 60 it exits the loop

I think what you want is for three out of each 6 LEDs to be RED and the rest to be BLACK. And you want the pattern to shift left. That means there are six different patterns.

#include <FastLED.h>

#define LED_PIN     5
#define NUM_LEDS    60
#define LED_TYPE    WS2811
#define COLOR_ORDER GRB
CRGB leds[NUM_LEDS];

void setup()
{
  FastLED.addLeds<WS2812B, LED_PIN, GRB> (leds, NUM_LEDS);
  FastLED.setBrightness(50);
}

void loop()
{
  // Each of the pattern positions
  for (int shift = 0; shift < 6; shift++)
  {
    for (int dot = 0; dot < NUM_LEDS; dot++)
    {
      if (dot <= 30)
      {
        // Red side
        if (((dot + shift) % 6) < 3) // Three dots of color
          leds[dot] = CRGB::Red;
        else // The rest are black
          leds[dot] = CRGB::Black;

      }
      else // >30
      {
        // Blue side
        if (((dot + shift) % 6) < 3)
          leds[dot] = CRGB::Blue;
        else
          leds[dot] = CRGB::Black;
      }
    }
    // All of the dots are full so show them
    FastLED.show();
    delay(30);  // This sets the rate of motion
  }
}
1 Like

That is exactly what I was looking to do except I was hoping to have it go left to right. How would you change the for loop to change direction?

The classic way to reverse a 'for' loop is to count down instead of up:

  for (int shift = 5; shift >= 0; shift--)
  {
1 Like

Thank You so much for your help!

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