Multiple LED "dots" moving along a strip?

Im trying to move multiple LED dots along an WS2812B strip at random speeds and intervals. I have got one dot to move (one direction) along the strip at random speeds and random intervals between cycles. Done with a simple for loop and tuening on/off LEDs with FastLED. How would i add a second or third dot that could be moving along the strip at a different speed as the other(s). Im new to arduino, and programming. Be gentle. LOL

Thanks,
Scot

Please post your current sketch

If it uses delay() for timing in the for loop then you will need to make changes to implement non blocking timing using millis()

See Using millis() for timing. A beginners guide, Several things at the same time and the BlinkWithoutDelay example in the IDE

Something like this?

Try FastLED examples:

Adafruit_NeoPixel examples:

As I stated, I'm not a programmer, I'm a hacker at minimum. So my sketch is probably garbage & much better ways to do it. And there is probably stuff in it I tried that didnt work, but I didnt remove it.

// Use if you want to force the software SPI subsystem to be used for some reason (generally, you don't)
// #define FASTLED_FORCE_SOFTWARE_SPI
// Use if you want to force non-accelerated pin access (hint: you really don't, it breaks lots of things)
// #define FASTLED_FORCE_SOFTWARE_SPI
// #define FASTLED_FORCE_SOFTWARE_PINS
#include <FastLED.h>

//
// Move a white dot along the strip of leds. This program simply shows how to configure the leds,
// and then how to turn a single pixel white and then off, moving down the line of pixels.
//

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

// For led chips like WS2812, which have a data line, ground, and power, you just
// need to define DATA_PIN. For led chipsets that are SPI based (four wires - data, clock,
// ground, and power), like the LPD8806 define both DATA_PIN and CLOCK_PIN
// Clock pin only needed for SPI based chipsets when not using hardware SPI
#define DATA_PIN 2
#define CLOCK_PIN 13

// 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);  // GRB ordering is typical

}

// This function runs over and over, and is where you do the magic to light
// your leds.
void loop() {
int PauseDelay=rand() % 30;
int StartLED = rand() % 25;
int LEDSpeed = (rand() % 20);
int LEDPower = (rand() % 200)+50;
int B = 0;
int C = rand()%20;
delay(PauseDelay*100);
// Move a single white led
for(int A = (StartLED); A < NUM_LEDS/2; A = A + 1)
{
B = (NUM_LEDS-A);
// Turn our current led on to white, then show the leds

  leds[A] = CRGB::White;
  leds[B] = CRGB::White;

if (C > 15) {
        leds[A] = CRGB::Cyan;
        leds[B] = CRGB::Cyan;
            } 


  FastLED.setBrightness(LEDPower);
   
  FastLED.show(); // Show the leds (only one of which is set to white, from above)

  // Wait a little bit
  delay(LEDSpeed);

  // Turn our current led back to black for the next loop around
  leds[A] = CRGB::Black;
  leds[B] = CRGB::Black;

}
FastLED.clear(); // clear all pixel data
FastLED.show();

}

Your sketch works

does not "move a white dot along the strip" and starts with a bunch of pauses... remove them... let the show begin.

And... "LEDSpeed" is never above 20, so your LEDs barely light up... try a simpler random LEDSpeed, like:

LEDSpeed = random(200, 500); // random value (milliseconds) between 200 and 500
Here is your sketch with many comments removed. I also commented-out the pauses and printed LEDSpeed.

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 < CODE/ > icon above the compose window) to make it easier to read and copy for examination

https://forum.arduino.cc/t/how-to-get-the-best-out-of-this-forum

Not what I wanted, but thanks for trying.

"Moving" too fast
Delay too short
want it going in one direction, not from both ends.

I want multiple dots on the string, going in same direction, at different speeds, one dot may catch up to another & "pass" it.

Given that, you should shop this over to
Latest Community/Jobs and Paid Consultancy topics - Arduino Forum

1 Like

Yes something similar at the 1:35 point.. One direction, with random speeds, & random intervalls between each, random brightnesses, all one color.

The sim is YOUR CODE. Draw a picture of what you want. Coding is the easy part.

Code associated with the simulation is not how my code worked. Not sure what you are referring to.

I'm sure you don't. Seems I am the confused one. Still, I'm done.

"I'm sure you don't"........?

You won't be able to do this with a simple for loop. For each dot, you will need to store the color, brightness, speed, etc, and then each iteration of loop check to see if it is time for any of the dots to move to a new location.
Helps if you can set a maximum number of dots you want to be illuminated at any given time, otherwise memory can become an issue.

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