Skip to content

Instantly share code, notes, and snippets.

@Blink515
Last active November 15, 2017 20:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Blink515/08adcce86bf30f5ba8c31042865bf6f2 to your computer and use it in GitHub Desktop.
Save Blink515/08adcce86bf30f5ba8c31042865bf6f2 to your computer and use it in GitHub Desktop.
FastLED 1 Array multiple strips + Map
#include "FastLED.h"
#define NUM_LEDS_PER_STRIP 10
#define NUM_LEDS 20
int mappedLEDs [] {
9,8,7,6,5,4,3,2,1,0,10,11,12,13,14,15,16,17,18,19
};
CRGBArray<NUM_LEDS> leds;
void setup() {
// tell FastLED there's 10 NEOPIXEL leds on pin 10, starting at index 0 in the led array
FastLED.addLeds<NEOPIXEL, 10>(leds, 0, NUM_LEDS_PER_STRIP);
// tell FastLED there's 10 NEOPIXEL leds on pin 11, starting at index 10 in the led array
FastLED.addLeds<NEOPIXEL, 11>(leds, NUM_LEDS_PER_STRIP, NUM_LEDS_PER_STRIP);
}
void loop() {
for(int i = 0; i < NUM_LEDS; i++) {
leds[mappedLEDs[i]] = CRGB::Red;
FastLED.show();
leds[mappedLEDs[i]] = CRGB::Black;
delay(100);
}
}
@marmilicious
Copy link

If you have an strip with 159 pixels you might not want to type all those numbers out though! Here's a way to fill that array with a for loop:

uint8_t mappedLEDs[NUM_LEDS];
for (int x=0; x<NUM_LEDS; x=x+1) { mappedLEDs[x]=x; } //this fills the array with range 0 to NUM_LEDS-1

Adjust your for loop as needed to fill numbers in reverse order. Can use two loops, one to fill reverse numbers and a second to continue filling, putting in the forward counting numbers.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment