Hello,
first of all I would like to let you guys know that I'm pretty new to arduino programming and electronics.
So I'm currently playing with a WS28128B/Neopixel LED strip and I'm trying to figure out how to light 18 LEDs in a specific order. For example I would like the first 6 LEDs to light up and then jump to the 10th and light the next 8 LEDs and so on. Basically this is the order of LEDs I'm trying to achieve: 1 2 3 4 5 6 10 11 12 13 14 15 16 17 18 7 8 9.
I have managed to succed with adding three "for loops" but I know this is somehow inefficient or the least elegant way to code this:
#include<FastLED.h>
#define NUM_LEDS 18
#define DATA_PIN 7
#define BRIGHTNESS 50
#define delayValue 500
CRGB leds[NUM_LEDS];
void setup() {
FastLED.addLeds<NEOPIXEL, DATA_PIN>(leds, NUM_LEDS);
FastLED.setBrightness(BRIGHTNESS);
}
void loop() {
for(int i = 0; i < 6; i++){
leds[i] = CHSV(0, 255, 255);
FastLED.show();
delay(delayValue);
}
for(int i = 9; i < 18; i++){
leds[i] = CHSV(0, 255, 255);
FastLED.show();
delay(delayValue);
}
for(int i = 6; i < 9; i++){
leds[i] = CHSV(0, 255, 255);
FastLED.show();
delay(delayValue);
}
}
I have also tried to declare the order of the LEDs in the CRGB array like this:
CRGB leds[NUM_LEDS] = {0, 1, 2, 3, 4, 5, 9, 10, 11, 12, 13, 14, 15, 16, 17, 6, 7, 8};
and then just add one "for loop" thinking this would call the LEDs in the specified order:
for(int i = 0; i < NUM_LEDS; i++){
leds[i] = CHSV(0, 255, 255);
FastLED.show();
delay(delayValue);
}
As you might have already knew it this didn't work and at this point I'm pretty sure the numbers I've added in {} brackets are just values of the array and not the LEDs positions.
I'm missing out on something and/or my approach is wrong and I would like to ask you guys for help with this problem. Thank you!