Question about running led dots(ws2812b)

hello friends,
i,m newbie and my english is not so good hope you guys undersatnd me, i just run single red dot back to forth with this code, my question is how can i run two led dots with same behaviour ?

#include <FastLED.h>
#define NUM_LEDS 7
CRGB leds[NUM_LEDS];
#define PIN 2
void setup() {
  FastLED.addLeds<WS2812B, PIN, GRB>(leds, NUM_LEDS).setCorrection( TypicalLEDStrip );
}
void loop() {
  for (int i = 0; i < NUM_LEDS; i++) {
    leds[i] = CRGB::Red;
    FastLED.show();
    delay(100);
    leds[i] = CRGB::Black;
  }
  for (int i = NUM_LEDS - 1; i >= 0; i--) {
    leds[i] = CRGB::Red;
    FastLED.show();
    delay(100);
    leds[i] = CRGB::Black;
  }
}

Do you want the 2 dots to run at he same speed or at different speeds ? If at the same speed then how far apart should they be ?

If

leds[i] = CRGB::Red;

turns on one LED then what would

leds[i] = CRGB::Red;
leds[i + 1] = CRGB::Red;

do ?

1 Like

yes i want 2 dots at same speed. and run together back to forth.

Start by answering the question in my previous post

much thanks mate. :smiling_face:

I gather that it worked

HOWEVER I suspect that you are now writing outside of the memory belonging to the LEDs. Did you take precautions to prevent that I wonder ?

Please post your working sketch, using code tags when you do

#include <FastLED.h>
#define NUM_LEDS 7
CRGB leds[NUM_LEDS];
#define PIN 2
void setup() {
  FastLED.addLeds<WS2812B, PIN, GRB>(leds, NUM_LEDS).setCorrection( TypicalLEDStrip );
}
void loop() {
  for (int i = 0; i < NUM_LEDS; i++) {
    leds[i] = CRGB::Red;
    leds[i + 1] = CRGB::Red;
    FastLED.show();
    delay(100);
    leds[i] = CRGB::Black;
    leds[i + 1] = CRGB::Black;
  }
  for (int i = NUM_LEDS - 1; i >= 0; i--) {
    leds[i] = CRGB::Red;
    leds[i + 1] = CRGB::Red;
    FastLED.show();
    delay(100);
    leds[i] = CRGB::Black;
    leds[i + 1] = CRGB::Black;
  }
}

Which LED is being written to when i equals 6 and you do

    leds[i + 1] = CRGB::Red;
  }

bearing in mind that the leds array has 7 levels numbered 0 to 6

1 Like

At the ends of the neopixel strand (pix zero and and pix "n") you will want to ensure data is not written to "n+1" or "zero-1" which might result in no neopixels lighting.

Which might result in any number of exciting things happening you don't want to.
Have happening.

Worse, this kind of error may sit harmless and silent whilst you build out your idea to several hundred lines of code, and when inexplicable things start impeding your progress, you'll have long forgotten where the errors might be coming from, or where even to start looking.

Ask me how I know. Wait, no, don't. :expressionless:

a7

"I heard from a friend who had those problems." - that's my story

1 Like

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