Hi there! I posted a bit earlier asking for help with my led strip.

fastled-support
gplus
(friends 4life) #1

Hi there! I posted a bit earlier asking for help with my led strip. However I’ve now decided to add functionality.

So basically I want this code to be somewhat interchangeable (i might want to reuse again in strips of other length) so this is why I’ve decided to go with logical operators (ie the if statement to decipher between even and odd leds) even given my small strip (23 leds).

I want the first loop to play 3 times total and for the leds to fade/pulse.

My second loop is essentially a spinning rainbow cycle. played 3 times.

Here is my code so far:

#include <FastLED.h>

#define PIN 9

#define NUM_LEDS 23 //my strip has 23 leds total

#define LED_TYPE WS2812B

#define COLOR_ORDER GRB

int fadeAmount = 5;

int brightness = 0;

CRGB leds[NUM_LEDS]; //this is the array of leds

void setup() {

delay(1000); //1000 millisecond delay

FastLED.addLeds<WS2812B, PIN, COLOR_ORDER> (leds, NUM_LEDS).setCorrection( TypicalLEDStrip );

}

void loop() {

for (int i = 0; i < NUM_LEDS*3; i++) //I want this loop to run 3 times

{

if (i % 2 == 0)

{

leds[i].setRGB(12,223,156); //even numbers play this color

leds[i].fadeLightBy(brightness); //this is what makes the lights fade

}

else

{

leds[i].setRGB(110,231,58); //odd numbers play this color

leds[i].fadeLightBy(brightness);

}

FastLED.show();

brightness = brightness + fadeAmount;

//reverses direction of fade

if(brightness == 0 || brightness == 255)

{

fadeAmount = -fadeAmount ;

}

delay(15);

}`

//fill rainbow loop

void rainbow()

{

rainbowCycle (14);

}

void rainbowCycle(int SpeedDelay) {

byte *c;

uint16_t i, j;

for(j=0; j<256*3; j++) { // 3 cycles of all colors on wheel

for(i=0; i< NUM_LEDS; i++) {

c=Wheel(((i * 256 / NUM_LEDS) + j) & 255);

setPixel(i, *c, *(c+1), *(c+2));

}

FastLED.show();

delay(SpeedDelay);

}

}

byte * Wheel(byte WheelPos) {

static byte c[3];

if(WheelPos < 85) {

c[0]=WheelPos * 3;

c[1]=255 - WheelPos * 3;

c[2]=0;

} else if(WheelPos < 170) {

WheelPos -= 85;

c[0]=255 - WheelPos * 3;

c[1]=0;

c[2]=WheelPos * 3;

} else {

WheelPos -= 170;

c[0]=0;

c[1]=WheelPos * 3;

c[2]=255 - WheelPos * 3;

}

return c;

(Andrew Tuline) #2

Hi, I responded to your Reddit post. In the meantime, please post your code to http://gist.github.com instead of directly on the forums (either here OR Reddit).