I have a FastLed project that is making NO SENSE.
I have 2 strips one of 240 LEDs and one of 120, both are APA102C strips. Both strips are starting in the middle and running to the opposite ends, strip start/end. A simple 4 LED cylon effect
The large strip preforms like it should (sort of, more later)
The small strip will run until it hits the beginning/end of the strip and dies. The first/last 4 LEDS stay lit and stop doing anything. The large strip hits the first/last LEDs and merrily changes direction back to the middle and reverse ad infinitum as they should.
Question 1: Why the heck does the small strip just die?
This program was modified from a program that was running under Adafruit on a Giga where I was getting acceptable performance and both strips were bouncing back and forth correctly. Because the Giga runs at 3.3V and doesn't work with 5V Arduinos, without adding yet more circuitry I switched over to an UNO which ran the program at about 1/10th the speed of the Giga. So I rewrote the prgram using FastLed which while slower was still usable UNTIL the small strip started dying.
I've played with using SPI and have seen virtually no difference so I am baffled about WHY this is happening.
Question 2: Why does FastLed not seem to work with user defined colors. In Adafruit if I defined Red as 0x0000FF and dim Red as0x000001 I got a vibrant Red block which then left behind a very dim Red. I fastLed the same definition results in a very bright Yellow Orange color.
Any ideas?????
FastLed code:
#include <FastLED.h>
#define NUM_LEDS1 240
#define NUM_LEDS2 120
#define DATA_PIN1 4
#define CLOCK_PIN1 5
#define DATA_PIN2 6
#define CLOCK_PIN2 7
#define c_red CRGB::Red
#define b_red CRGB::Black
#define c_blu CRGB::Blue
#define b_blu CRGB::Black
#define c_grn CRGB::Green
#define b_grn CRGB::Black
#define c_wht CRGB::White
#define b_wht CRGB::Black
#define low_p 10
#define mid_p 11
#define high_p 12
#define fly_p 13
int del = 30;
bool flag = true;
int lb = 121;//large back end rev counter l in the for loop is the large counter
int s = 61; //small counter
int sb = 61; //small back end counter
CRGB curColor = c_red;
CRGB curBcolor = b_red;
int curDelay = 12;
// Define the array of leds
CRGB l_leds[NUM_LEDS1];
CRGB u_leds[NUM_LEDS2];
void checkButtons(){
if (digitalRead(low_p)){
curColor = c_red;
curBcolor = b_red;
curDelay = 8;
}
else if (digitalRead(mid_p)){
curColor = c_grn;
curBcolor = b_grn;
curDelay = 6;
}
else if (digitalRead(high_p)){
curColor = c_blu;
curBcolor = b_blu;
curDelay = 4;
}
else if (digitalRead(fly_p)){
curColor = c_wht;
curBcolor = b_wht;
curDelay = 0;
}
}
void cylon(CRGB frgd, CRGB bkgd, uint16_t del){
//backward
flag = true;
lb = 121;
s = 61;
sb = 61;
for(int l = 120;l > 0;l--){
l_leds[l] = frgd;
l_leds[lb] = frgd;
l_leds[l+4] = bkgd;
l_leds[lb-4] = bkgd;
if (flag){
u_leds[s] = frgd;
u_leds[sb] = frgd;
u_leds[s+4] = bkgd;
u_leds[sb-4] = bkgd;
flag = !flag;
sb++;
s--;
} else flag = true;
FastLED.show();
lb++;
delay(del);
}
//foward
flag = true;
lb = 240;
s = 0;
sb = 120;
for(int l=0;l<121;l++){
l_leds[l] = frgd;
l_leds[lb] = frgd;
l_leds[l-4] = bkgd;
l_leds[lb+4] = bkgd;
if (flag){
u_leds[s] = frgd;
u_leds[sb] = frgd;
u_leds[s-4] = bkgd;
u_leds[sb+4] = bkgd;
flag = !flag;
s++;
sb--;
} else flag = true;
FastLED.show();
lb--;
delay(del);
}
}
void setup() {
pinMode(low_p, INPUT);
pinMode(mid_p, INPUT);
pinMode(high_p, INPUT);
pinMode(fly_p, INPUT);
curColor = c_red;
curBcolor = b_red;
curDelay = 8;
FastLED.addLeds<APA102, DATA_PIN1, CLOCK_PIN1, BGR, DATA_RATE_MHZ(24)>(l_leds, NUM_LEDS1);
FastLED.addLeds<APA102, DATA_PIN2, CLOCK_PIN2, BGR, DATA_RATE_MHZ(24)>(u_leds, NUM_LEDS2);
}
void loop() {
checkButtons();
cylon(curColor,curBcolor,curDelay);
}
Adafruiit Code:
#include <Adafruit_DotStar.h>
#define clkspd 8000000
#define pix1 240
#define data1 4
#define clock1 5
Adafruit_DotStar strip1(pix1, data1, clock1, DOTSTAR_BRG);
#define pix2 120
#define data2 6
#define clock2 7
Adafruit_DotStar strip2(pix2, data2, clock2, DOTSTAR_BRG);
#define c_red 0x00FF00
#define b_red 0x000100
#define c_blu 0x0000FF
#define b_blu 0x000001
#define c_grn 0xFF0000
#define b_grn 0x010000
#define c_wht 0xFFFFFF
#define b_wht 0x010101
#define low_p 5
#define mid_p 6
#define high_p 8
#define fly_p 12
int del = 30;
bool flag = true;
int color = 1;
int bcolor = 1;
int curColor = c_red;
int curBcolor = b_red;
int curDelay = 12;
void checkButtons(){
if (digitalRead(low_p)){
curColor = c_red;
curBcolor = b_red;
curDelay = 12;
}
else if (digitalRead(mid_p)){
curColor = c_grn;
curBcolor = b_grn;
curDelay = 8;
}
else if (digitalRead(high_p)){
curColor = c_blu;
curBcolor = b_blu;
curDelay = 4;
}
else if (digitalRead(fly_p)){
curColor = c_wht;
curBcolor = b_wht;
curDelay = 0;
}
}
void cylonR(uint32_t frgd, uint32_t bkgd, uint16_t del){
//reverse
flag = true;
int lb = 121;//large back end rev counter l in the for loop is the large counter
int s = 61; //small counter
int sb = 61; //small back end counter
for (int l = 120;l > 0; l--){
strip1.setPixelColor(l, frgd);
strip1.setPixelColor(lb, frgd);
if (l<121){
strip1.setPixelColor(l+9,bkgd);
strip1.setPixelColor(lb-9,bkgd);
}
strip1.show();
if (flag) {
strip2.setPixelColor(s,frgd);
strip2.setPixelColor(sb,frgd);
if (l<121){
strip2.setPixelColor(s+9,bkgd);
strip2.setPixelColor(sb-9,bkgd);
}
flag = !flag;
s--;
sb++;
strip2.show();
} else flag = true;
lb++;
delay(del);
}
//forward
flag = true;
lb = 240;
s = 0;
sb = 120;
for (int l = 0;l < 121; l++){
strip1.setPixelColor(l,frgd);
strip1.setPixelColor(lb,frgd);
if (l>8){
strip1.setPixelColor(l-9,bkgd);
strip1.setPixelColor(lb+9,bkgd);
}
strip1.show();
lb--;
if (flag) {
strip2.setPixelColor(s,frgd);
strip2.setPixelColor(sb,frgd);
if (l>8){
strip2.setPixelColor(s-9,bkgd);
strip2.setPixelColor(sb+9,bkgd);
}
flag = !flag;
s++;
sb--;
strip2.show();
} else flag = true;
delay(del);
}
delay(del);
}
void setup() {
pinMode(low_p, INPUT_PULLUP);
pinMode(mid_p, INPUT_PULLUP);
pinMode(high_p, INPUT_PULLUP);
pinMode(fly_p, INPUT_PULLUP);
curColor = c_red;
curBcolor = b_red;
curDelay = 12;
strip1.begin() ;
strip1.show() ;
strip2.begin() ;
strip2.show() ;
}
void loop() {
checkButtons();
cylonR(curColor,curBcolor, curDelay);
}
//>
Thanks,
Joe B