Advance LEDstrip 2 at a time

So I am looking to run a light sequence, one by one is too slow, so two by two would be faster. I am using the following now to advance it:

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

Modifying it to this:

for (int i=0; i<NUM_LEDS; i = i + 2){

Skips every other led. So how to you advance two at a time?

Mindreader broken. Show more of your code, preferrably all, and please use code tags. Don't know what those are? Then please, read this:

C

Fine.

#include <FastLED.h>
#define LED_PIN 13
#define NUM_LEDS 432

CRGB leds[NUM_LEDS];


void setup() {
  FastLED.addLeds<WS2812, LED_PIN, GRB>(leds, NUM_LEDS);
  FastLED.clear();
  FastLED.show();
 
}

void loop() {
  // Turn lights from green to blue from left to right   R G B 
  for (int i=0; i<NUM_LEDS; i++){
    leds[i] = CRGB::White;
    FastLED.setBrightness(255);
    FastLED.show();
    delay(1);
  }

  // Turn lights from green to blue from left to right   R G B 
  for (int i=0; i<NUM_LEDS; i++){
    leds[i] = CRGB::Black;
    FastLED.setBrightness(255);
    FastLED.show();
    delay(1);
  }
  
  
}

Ok. So let's pick that apart a bit. Since you don't know what to modify to make it work, I'll presume you didn't write any of it, so I'll take it slow.
Each loop is setting a new state for exactly 1 LED, then calling .show, then pausing, then doing the next one. Do you think maybe setting a new state for 2 LEDs, then calling .show, would do what you want? Maybe, try this: (I haven't tried this, but don't see what could be wrong with it).

  for (int i=0; i<NUM_LEDS; i++){
    leds[i] = CRGB::White; 
    i=i+1;
    leds[i] = CRGB::White;
    FastLED.setBrightness(255);
    FastLED.show();
    delay(1);
  }

There, that wasn't too painful, eh? Thanks for playing along.
C

That does what I said in my original post, it skips every other one. I need 2 LEDs to be illuminated at a time down the length of the strip.

I'm skeptical of that. Did you notice the extra increment of i in the middle? Did you try it, or just look at it and not see a difference? Not being snarky, but every element in the array will get updated with the loop structured that way, so I don't see how it could skip them. I don't have any WS2812 to try this with.
C

I did try it, but I didn't see the extra

leds[i] = CRGB::White;

That did it. Much appreciated!

:+1:

Hello,
See if this code meets your need.

#include <FastLED.h>
#define LED_PIN 13
#define NUM_LEDS 432

CRGB leds[NUM_LEDS];

//----------------------------------------------
void setup() {
  FastLED.addLeds<WS2812, LED_PIN, GRB>(leds, NUM_LEDS);
  FastLED.clear();
  FastLED.show();
}
//----------------------------------------------
void loop() {
  // Turn lights from green to blue from left to right   R G B 
  for (int i=0; i<NUM_LEDS; i++){
    leds[i] = CRGB::White;
    i++;
    leds[i] = CRGB::White;
    FastLED.setBrightness(255);
    FastLED.show();
    i -= 2;
    leds[i] = CRGB::Black;
    i++;
    leds[i] = CRGB::Black;
    FastLED.setBrightness(255);
    FastLED.show();
    delay(1);
  }
}

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