WS2812B

Hi

I have a WS2812B, 144pixel/meter strip. In my application it is formed to make a ring.
I would like to rotate 25 PIXELS around the ring (white only ) like a running light effect.
I am using FASTLED library.

Could someone help me to create the code.

the code i have is stuck at the end and then it restarts
below is my code

#include “FastLED.h”

int LED_BAR =25;
int total =0;

// How many leds are in the strip?
#define NUM_LEDS 144

// Data pin that led data will be written out over
#define DATA_PIN 22

// Clock pin only needed for SPI based chipsets when not using hardware SPI
//#define CLOCK_PIN 8

// This is an array of leds. One item for each led in your strip.
CRGB leds[NUM_LEDS];

// This function sets up the ledsand tells the controller about them
void setup() {
// sanity check delay - allows reprogramming if accidently blowing power w/leds
delay(2000);

FastLED.addLeds<WS2812B, DATA_PIN, GRB>(leds, NUM_LEDS);

}

// This function runs over and over, and is where you do the magic to light
// your leds.
void loop() {
// Move a 25 pixels white led

for (int t=0; t < NUM_LEDS; t++) {

total =t;
LED_BAR++;

for(int whiteLed = total; whiteLed < LED_BAR; whiteLed = whiteLed + 1) {
// Turn our current led on to white, then show the leds

leds[whiteLed] = CRGB::White;

}

FastLED.show();
delay(10);

// Wait a little bit

for (int blackLed = total; blackLed < LED_BAR; blackLed++) {
// Turn our current led back to black for the next loop around

leds[blackLed] = CRGB::Black;

}

}
}

Thanks

Please read this:- How to use this forum Because your post is breaking the rules about posting code.

Have a for loop and just set all the LEDs to black then set the LED given by the loop index to white. Show the buffer and then have a delay. Should be a lot simpler than what you have.

Hi

I have a WS2812B, 144pixel/meter strip. In my application it is formed to make a ring.
I would like to rotate 25 PIXELS around the ring (white only ) like a running light effect.
I am using FASTLED library and using arduino mega 2560

I used the below code from github (Mr.Richard - Thanks to him)

It is working fine. But when the bar is moving to the end of the strip it is providing a wiping effect. So the running visual cycle is not continuous . I need a continuous led bar running effect around the strip.

Could someone help me to edit the code.

Thanks

#include <FastLED.h>

#define NUM_LEDS 144
#define DATA_PIN 22
#define FRAME_DELAY 10

long loops =0;
long CurrentMillis =0;
long LastMillis =0;

int colorBarLength = 25;
int colorBarPosition = 1;
int frameCounter = 0;
const int numberofColors = 2;
long colorPallet[numberofColors] = {CRGB::Black,CRGB::White};
int palletPosition = 0;
bool clearLEDS = false;

CRGBArray<NUM_LEDS> leds;


void showfps() {

CurrentMillis =millis();
loops++;
if (CurrentMillis - LastMillis >1000) {

  Serial.println(loops);
  LastMillis = CurrentMillis;
  loops =0;
  
}
  
}


void setup()
{
  delay(3000);
  FastLED.addLeds<WS2812B, DATA_PIN, GRB>(leds, NUM_LEDS);
  FastLED.clear();
  FastLED.setBrightness (128);
  FastLED.show();
  Serial.begin(57600);
}

void loop()
{
  EVERY_N_MILLISECONDS(FRAME_DELAY)
  {
    
    for (int x=0; x<NUM_LEDS-1; x++)
    {
      leds[x] = leds[x+1];
    }
    if (clearLEDS)
    {
      leds[NUM_LEDS-1] = colorPallet[palletPosition];
    }
    
    if ((colorBarPosition <= colorBarLength) && !clearLEDS)
    {
      leds[NUM_LEDS-1] = colorPallet[palletPosition];
      colorBarPosition++;
    }
    if ((palletPosition == numberofColors-1) && (colorBarPosition > colorBarLength) && !clearLEDS)
    {
      leds[NUM_LEDS-1]=colorPallet[palletPosition];
      palletPosition = 0;
      colorBarPosition = 1;
      clearLEDS= true;
      
    }
    if ((colorBarPosition > colorBarLength) && !clearLEDS)
    {
      colorBarPosition = 1;
      palletPosition = palletPosition+1;
    }
    if (clearLEDS && !leds(0,NUM_LEDS-1))
    {
      clearLEDS = false;
    }
  }

  FastLED.show ();
  showfps();           //shows flips per second on serial port
  
}
leds[x] = leds[x+1];

You have to look at the value of x, and when it exceeds the maximum LED number, which is NUM_LEDS-1, then you set x to zero. As x is being used as a loop counter you need to make a copy before you do this.

copyX = x;
if(copyX >= NUM_LEDS-1) {
copyX -= NUM_LEDS-1;
}
leds[copyX] = leds[copyX+1];

Dear

Thank you for your reply.

Could you please look at the code. Still the running light effect is the same.

please watch the video @ https://youtu.be/4IVie96mwfg

This is the result of the code. But i wanted the preset number of pixels should run around
the ring without wiping effect.

Am i doing something wrong with the code you sent

Or if you can provide me any other code which will
Work for my application also fine.

Please advise

Thank you

#include <FastLED.h>

#define NUM_LEDS 144
#define DATA_PIN 22
#define FRAME_DELAY 10
#define MAX_BRIGHTNESS 150 // watch the power!

long loops =0;
long CurrentMillis =0;
long LastMillis =0;
long copyX =0;
int colorBarLength = 50;
int colorBarPosition = 1;
int frameCounter = 0;
const int numberofColors = 2;
long colorPallet[numberofColors] = {CRGB::Black,CRGB::White};
int palletPosition = 0;
bool clearLEDS = false;

CRGBArray<NUM_LEDS> leds;


void showfps() {

CurrentMillis =millis();
loops++;
if (CurrentMillis - LastMillis >1000) {

  Serial.println(loops);
  LastMillis = CurrentMillis;
  loops =0;
  
}
  
}


void setup()
{
  FastLED.setBrightness(MAX_BRIGHTNESS);
  delay(3000);
  FastLED.addLeds<WS2812B, DATA_PIN, GRB>(leds, NUM_LEDS);
  FastLED.clear();
  FastLED.show();
  Serial.begin(57600);
}

void loop()
{
    EVERY_N_MILLISECONDS(FRAME_DELAY)
  {
    
    for (int x=0; x<NUM_LEDS-1; x++)
    {
      leds[x] = leds[x+1];
     
         copyX = x;
         if(copyX >= NUM_LEDS-1) {
         copyX -= NUM_LEDS-1;
    }
leds[copyX] = leds[copyX+1];
    }
    if (clearLEDS)
    {
      leds[NUM_LEDS-1] = colorPallet[palletPosition];
    }
    
    if ((colorBarPosition <= colorBarLength) && !clearLEDS)
    {
      leds[NUM_LEDS-1] = colorPallet[palletPosition];
      colorBarPosition++;
    }
    if ((palletPosition == numberofColors-1) && (colorBarPosition > colorBarLength) && !clearLEDS)
    {
      leds[NUM_LEDS-1]=colorPallet[palletPosition];
      palletPosition = 0;
      colorBarPosition = 1;
      clearLEDS= true;
      
    }
    
    if ((colorBarPosition > colorBarLength) && !clearLEDS)
    {
      colorBarPosition = 1;
      palletPosition = palletPosition+1;
    }

    
    if (clearLEDS && !leds(0,NUM_LEDS-1))
    {
      clearLEDS = false;
    }
  }

  FastLED.show ();
  showfps();           //shows flips per second on serial port
  
}

OK you are going to say exactly what you want to do. Yes run around the ring but how many LEDs are on at any one time?

I am a new bee.

So does that prevent you from reading the rules and editing your first post to comply with them?

Could you please provide a sample code for my application above.

No. This forum is all about helping you learn. If I just give you the code then I am doing your project for you.

If you don't understand what I am saying then ask about it.

If you want someone to write code for you then post in the gigs and collaboration section and say how much you are willing to pay.

Last but by no means least cross posting is frowned upon here. Do not do it.

For anyone else wanting to help this ungrateful member then see here http://forum.arduino.cc/index.php?topic=457534.msg3145209#new

@neomax is currently enjoying a brief forum timeout to give him/her the opportunity to read the posting guidelines, particularly with respect to cross-posting and the use of code tags.