0

I can manually set a bunch of LED's line by line, but would like to be able to do it with an array declaration and for statement. The code that works is here:

#include <FastLED.h>
#define LED_PIN 2
#define NUM_LEDS 50

CRGB leds[NUM_LEDS];

void setup() {
  FastLED.addLeds<WS2811, LED_PIN, RGB>(leds, NUM_LEDS);
  FastLED.setMaxPowerInVoltsAndMilliamps(12,1500);
  FastLED.clear();
  FastLED.show();

}

void loop() {
  // Create a small Christmas Tree
    FastLED.clear();
    leds[4] = CRGB(0, 255, 0);
    leds[11] = CRGB(0, 255, 0);
    leds[17] = CRGB(0, 255, 0);
    leds[18] = CRGB(0, 255, 0);
    leds[19] = CRGB(0, 255, 0);
    FastLED.setBrightness(255);
    FastLED.show();
    delay(5000);
}

The effort to turn this into an array is shown here - and it doesn't work. How do I fix this?

#include <FastLED.h>
#define LED_PIN 2
#define NUM_LEDS 50

CRGB leds[NUM_LEDS];
int array[10];

void setup() {
  FastLED.addLeds<WS2811, LED_PIN, RGB>(leds, NUM_LEDS);
  FastLED.setMaxPowerInVoltsAndMilliamps(12,1500);
  FastLED.clear();
  FastLED.show();
  }

void loop() {
  int n;
  int i;
  int arr1[] = {4, 11, 17, 18, 19};

//  FastLED.clear();

  for (i=0; i<5; i++); {
    n = arr1[i];
    leds[n] = CRGB::Green;
    FastLED.show();
    delay(200);
    }

  }
GregT
  • 1

1 Answers1

0

There is a semicolon after your for condition.

James Risner
  • 5,451
  • 11
  • 25
  • 47
Piscesky
  • 13
  • 4