I have a functioning NeoPixel array I modified from the FastLED example sketch. I'm trying to modify it to function with some new DotStar strips. I haven't been able to get it working. I'm attaching a very basic version of the original sample sketch with my attempts to address the DotStars. I'm getting an error because I'm not calling the strips properly.
If anyone could point me in the right direction it would be greatly appreciated. If I'm doing twenty things wrong, don't be shy about telling me. I'm trying to figure it all out.
When you encounter an error you'll see a button on the right side of the orange bar "Copy error messages". Click that button. Paste the error in a message here USING CODE TAGS (</> button on the forum toolbar). If the text exceeds the forum's 9000 character limit, save it to a text file and post it as an attachment. If you click the "Reply" button here, you will see an "Attachments and other settings" link.
That makes sense, I've been jumbling things together trying to make something work. I suppose the simpler question I could have asked is how do I change the Neopixel lines in this basic FastLED example sketch to address multiple DotStar strips. I haven't found anything in their documentation beyond statements that DotStars are supported.
If it is more appropriate I could ask this question in the FastLED forum. They use a G+ forum which I find less enjoyable than this one, but I am happy to direct myself where best suited.
// MultipleStripsInOneArray - see https://github.com/FastLED/FastLED/wiki/Multiple-Controller-Examples for more info on
// using multiple controllers. In this example, we're going to set up four NEOPIXEL strips on three
// different pins, each strip will be referring to a different part of the single led array
#include "FastLED.h"
#define NUM_STRIPS 3
#define NUM_LEDS_PER_STRIP 60
#define NUM_LEDS NUM_LEDS_PER_STRIP * NUM_STRIPS
CRGB leds[NUM_STRIPS * NUM_LEDS_PER_STRIP];
// For mirroring strips, all the "special" stuff happens just in setup. We
// just addLeds multiple times, once for each strip
void setup() {
// tell FastLED there's 60 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 60 NEOPIXEL leds on pin 11, starting at index 60 in the led array
FastLED.addLeds<NEOPIXEL, 11>(leds, NUM_LEDS_PER_STRIP, NUM_LEDS_PER_STRIP);
// tell FastLED there's 60 NEOPIXEL leds on pin 12, starting at index 120 in the led array
FastLED.addLeds<NEOPIXEL, 12>(leds, 2 * NUM_LEDS_PER_STRIP, NUM_LEDS_PER_STRIP);
}
void loop() {
for(int i = 0; i < NUM_LEDS; i++) {
leds[i] = CRGB::Red;
FastLED.show();
leds[i] = CRGB::Black;
delay(100);
}
}
I suppose the simpler question I could have asked is how do I change the Neopixel lines in this basic FastLED example sketch to address multiple DotStar strips.
That is exactly what that code does. It has three different strips on three different pins.
All those strips are treated as one array in the software. They are all 60 LEDs long, but you can make them any length you want.
The first strip on pin 10 uses LED numbers 0 to 59 in the array called "leds"
The second strip on pin 11 uses LED numbers 60 to 119 in the array called "leds"
The third strip on pin 12 uses LED numbers 120 to 179 in the array called "leds"
If you don't want all the LEDs in the same array then see the "ArrayOfLedArrays" example.
Here is a quick example I wrote to show two independent strips doing different things. I had previously written a version for the Adafruit Libiary but here it is for the fast LED libiary.
Note it shows two things:-
How to use more than one strip.
How to use a state machine so that there is no blocking code ( delays ) in the animation.
// using a state machine to drive two patterns on two strings at the same time
// By Mike Cook Jan 2019
// see https://github.com/FastLED/FastLED/wiki/Multiple-Controller-Examples for full discussion
#include "FastLED.h"
#define PIN_FOR_1 6 // pin connected to NeoPixels strip 1
#define PIN_FOR_2 7 // pin connected to NeoPixels strip 2
#define NUM_LEDS1 5 // number of LEDs in strip 1
#define NUM_LEDS2 6 // number of LEDs in strip 1
#define NUM_STRIPS 2 // how many strips you have
CRGB strip1[NUM_LEDS1];
CRGB strip2[NUM_LEDS2];
CLEDController *controllers[NUM_STRIPS];
// how often each pattern updates
unsigned long pattern1Interval = 400;
unsigned long pattern2Interval = 900;
// for millis() when last update occurred
unsigned long lastUpdateP1 = 0;
unsigned long lastUpdateP2 = 0;
// state variables for patterns
int p1State = 0 ;
int p2State = 0 ;
uint8_t gBrightness = 255;
void setup() {
controllers[0] = &FastLED.addLeds<WS2812,PIN_FOR_1>(strip1, NUM_LEDS1);
controllers[1] = &FastLED.addLeds<WS2812,PIN_FOR_2>(strip2, NUM_LEDS2);
// wipes the LED buffers
wipe1(0,0,0);
wipe2(0,0,0);
}
void loop(){
if(millis() - lastUpdateP1 > pattern1Interval) updatePattern1();
if(millis() - lastUpdateP2 > pattern2Interval) updatePattern2();
}
// Note both patterns are essentially the same sort of display for simplicity - change to suite
void updatePattern1(){ // pattern 1 a walking red led
strip2[p1State].setRGB(128,0,0); // turn on next led in pattern
int lastLed = p1State -1; // find LED to turn off
if (lastLed < 0) { // wrap round count
lastLed = NUM_LEDS1 -1;
}
strip1[lastLed] = 0x00; // turn off last LED we set
p1State ++; // move on state variable for the next time we enter this
if(p1State >= NUM_LEDS1){ // wrap round the state
p1State = 0;
}
controllers[0]->showLeds(gBrightness); // update display
lastUpdateP1 = millis(); // to calculate next update
}
void updatePattern2(){ // pattern 2 a walking green LED
strip2[p2State].setRGB(0,128,0); // turn on next led in pattern
int lastLed = p2State -1; // find LED to turn off
if (lastLed < 0) { // wrap round count if needed
lastLed = NUM_LEDS2 -1;
}
strip2[lastLed] = 0x00; // turn off last LED we set
p2State ++; // move on state variable for the next time we enter this
if(p2State >= NUM_LEDS2){ // wrap round the state
p2State = 0;
}
controllers[1]->showLeds(gBrightness); // update display
lastUpdateP2 = millis(); // to calculate next update
}
void wipe1(byte r,byte g, byte b){
for(int i=0;i<NUM_LEDS1;i++){
strip1[i].setRGB(r,g,b);
}
}
void wipe2(byte r,byte g, byte b){
for(int i=0;i<NUM_LEDS2;i++){
strip2[i].setRGB(r,g,b);
}
}
That solved things. I was struggling to figure out how to define the clock pin for the DotStars. In previous sketches with single DotStars I was required to #define the clock pin, but doing that with multiple data and clock pins had an obvious logical flaw.
I can rebuild what I had working with the Neopixels from this.