Skip to content

Instantly share code, notes, and snippets.

@hpwit
Created July 19, 2019 15:40
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 hpwit/335f3dc633e4ea3130c1f32ede6bde7d to your computer and use it in GitHub Desktop.
Save hpwit/335f3dc633e4ea3130c1f32ede6bde7d to your computer and use it in GitHub Desktop.
multiple leds array on one strip
#include "FastLED.h"
#define LED_TYPE WS2812B
#define DATA_PIN 7
#define COLOR_ORDER GRB
#define MASTER_BRIGHTNESS 255
#define NUM_LEDS 36
//Note: numA thru numD values must add up to NUM_LEDS
#define numA 8 //pixels 0-7
#define numB 8 //pixels 8-15
#define numC 10 //pixels 16-25
#define numD 10 //pixels 26-35
CRGB leds[NUM_LEDS]; //what actually gets displayed
CRGB *ledsA; //numA thru numD are "working" arrays
CRGB *ledsB;
CRGB *ledsC;
CRGB *ledsD;
void setup()
{
ledsA=leds;
ledsB=&leds[numA]; //ie 8
ledsC=&leds[numA+numB]; //ie 16
ledsD=&leds[numA+numB+numC]; //ie 26
//now you defined 4 pointers to 4 different part of the strip
Serial.begin(115200); //allow for output to serial monitor
delay(2500); //power up delay
FastLED.addLeds<LED_TYPE, DATA_PIN, COLOR_ORDER>(leds, NUM_LEDS);
FastLED.setBrightness(MASTER_BRIGHTNESS);
FastLED.clear();
ledsA[0]=CHSV(96, 225, 255);
ledsB[0]=CHSV(96, 225, 255);
ledsC[0]=CHSV(96, 225, 255);
ledsD[0]=CHSV(96, 225, 255);
FastLED.show(); //the first led of each 'part' is light up only
delay(1500);
}
int k=0;
void loop()
{
//it's like declaring 4 strips but as your are directly pointing to the leds you do not need to update leds
//example
//for pixel chase at different speed
FastLED.clear();
ledsA[k%numA]=CRGB::Yellow;
ledsB[(k/2)%numB]=CRGB::Blue;
ledsC[(k/3)%numC]=CRGB::Green;
ledsD[(k/4)%numD]=CRGB::Red;
FastLED.show();
delay(200);
k++;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment