Hi I have a WS2812B, 144pixel/meter strip.

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

Could someone help me to create the code.

Thanks

below is my code
it stuck in the end then it restarts

#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;

}

}
}

Take a look at this, you should be able to adjust it will a couple of minor changes in the initialization section to get it to do what you want.

Hi
Thank you . I will check and revert back.

Hi

I have done modification as below.
But the code is not giving the running light effect.
Also I wanted the light rotation speed should gradually increases on time and then the speed decreases

Could you Please advise

Thanks in advance

#include <FastLED.h>

#define NUM_LEDS 144
#define DATA_PIN 22
#define FRAME_DELAY 100
int colorBarLength = 25;
int colorBarPosition = 1;
int frameCounter = 0;
const int numberofColors = 1;
long colorPallet[numberofColors] = {CRGB::White};
int palletPosition = 0;
bool clearLEDS = false;

CRGBArray<NUM_LEDS> leds;

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

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 ();

}

You need to put the CRGB::Black back in as the first color and set the number of colors to 2.

To change the speed while running you need to add code to change frame delay on a regular interval.

Fix the numbers of colors first and confirm operation before starting on the changing speed.

Hi

Thank you

Please look at the video below
The front frame shows two blue color bar running with variable speed (my application requires white )

I made a similar frame with total pixels counting 1060.
The frame is slitted diagonally into two channel. Each channel having 530 pixels and both are synced. Channel 1 pixel data input is left top corner and channel 2 pixel data input is right bottom corner.(will be connected to two output of arduino). Now I would like to write the code

I appreciate if you can assist.

The video is only for led bar chaser animation reference
Currently I am working on the code you have provided.
Please let me know your comments and advise
Thank you

Hi Richard
I have tested it. Led bar is running but when it is coming to the end of the strip I can see there is a break in the loop
I mean I can see a break in between the end of first cycle and starting of next cycle.

When the bar is moving to the end there is a wiping effect which shouldn’t happen. It should smoothly rotate.

Could you please help
Thank you

The code that I wrote does a color bar of the defined length for each color in the list, then it does the clear code and starts over. That means it renders a black bar at the start of each cycle. This is by design for my project.

Hi Richard
Is it possible you to edit the code for my application
I really stuck

Please help
Thank you

@Richard_Bailey
Hi Richard
Is it possible you to edit the code for my application
I really stuck

I really appreciate If you can edit the code to circle the bare continuously and do some speed animation

Please help
Thank you

I do not have the time right now for another project right now. I wish you luck with the project.

Hi
If you can edit the code only for the continuous rotation also fine.

It will really help
Thank you

Hi Richard
I would be thankful If you could just edit your code for simple rotation without break
As I couldn’t make it so far
Still struggling with it.
Please help
Thanks

@Richard_Bailey
Hi Richard
Please look at the YouTube video

This is the result of the code

Could you please edit the code and help
Thank you

That is exactly what my code is supposed to do and as I said, I DO NOT have time for another project right now.

@Neo_Maximus ​. Read about “modulo” in the Arduino references area:
https://www.arduino.cc/en/Reference/Modulo
It’s a convenient way to wrap things around from the end to the beginning again.

Here are two examples that use modulo so things wrap around smoothly.

@marmil
Hi
Thank you for your reply

I hope that I can do something with you post
Will revert with the result
Regards

@marmil

Thank you very much for your help.

Hi I have managed to rotate 3 led at a time endlessly.
Below is the code. Could you please advise how to change the speed automatically (like gradually increase and decrease on time).

The code i have added ledspeed () is not working.

Please advise

#include “FastLED.h”

long loopspeed =0;
long loops =0;
int count =0;
long CurrentMillis =0;
long LastMillis =0;
int LED_BAR =3;
int total =0;

// How many leds are in the strip?
#define NUM_LEDS 144
#define MAX_BRIGHTNESS 150 // watch the power!

// Data pin that led data will be written out over
#define DATA_PIN1 22
#define DATA_PIN2 52

int16_t position1 = 0; // Set initial start position of Red pixel
int16_t position2 = 1; // Set initial start position of White pixel
int16_t position3 = 2; // Set initial start position of Blue pixel
int8_t delta = 1; // Using a negative value will move pixels backwards.
uint16_t holdTime = 10; // Milliseconds to hold position before advancing

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

}

void ledspeed() {

CurrentMillis =millis();
if (CurrentMillis - LastMillis >100) {

holdTime = loopspeed + 10;
LastMillis = CurrentMillis;
if (loopspeed > 100) {loopspeed =10;}

}

}
void setup() {

delay(2000);

  FastLED.setBrightness(MAX_BRIGHTNESS);
  FastLED.addLeds<WS2812B, DATA_PIN1, GRB>(leds, NUM_LEDS);
  FastLED.addLeds<WS2812B, DATA_PIN2, GRB>(leds, NUM_LEDS);
  
  Serial.begin(57600);  

}

void loop() { // START MAIN LOOP

EVERY_N_MILLISECONDS(holdTime) {

// Set pixel color

leds[position1] = CRGB::White;
leds[position2] = CRGB::White;
leds[position3] = CRGB::White;

// Show the pixels
FastLED.show();

//delay(holdTime);  // Delay for a bit.

// Set pixels back to Black for the next loop around.


leds[position1] = CRGB::Black;
leds[position2] = CRGB::Black;
leds[position3] = CRGB::Black;

// Set new position, moving (forward or backward) by delta.
// NUM_LEDS is added to the position before doing the modulo
// to cover cases where delta is a negative value.

position1 = (position1 + delta + NUM_LEDS) % NUM_LEDS;
position2 = (position2 + delta + NUM_LEDS) % NUM_LEDS;
position3 = (position3 + delta + NUM_LEDS) % NUM_LEDS;

// Print out position values to see what's happening.
//Serial.print("pos R = "); Serial.print(positionRed);
//Serial.print("\t  pos W = "); Serial.print(positionWhite);
//Serial.print("\t  pos B = "); Serial.println(positionBlue);

}

ledspeed();

} // END MAIN LOOP