int color_set = 0; //set to red first
int wait_fade = 1000 // delay time in ms. 1000ms is equal to 1sec
// set the color for all the LEDs based on the color code
void setcolor(int colorcode) {
for (int i = 0; i < LED_COUNT; i++) {
// instead of setting the color all at once we're going to step through each LED to show how to set them individually
switch(colorcode) {
// We're going to pass a CRGB here,
case 0: leds[i] = CRGB(255, 0 , 0); break; // red
case 1: leds[i] = CRGB(255, 127, 0); break; // orange
case 2: leds[i] = CRGB(255, 255, 0); break; // yellow
case 3: leds[i] = CRGB(0, 255, 0); break; // green
case 4: leds[i] = CRGB(0, 255, 255); break; // cyan
case 5: leds[i] = CRGB(0, 0, 255); break; // blue
case 6: leds[i] = CRGB(75, 0, 130); break; // indigo
case 7: leds[i] = CRGB(148, 0, 211); break; // violet
}
}
LEDS.show();
}
// we'll make the color fade in and out by setting the brightness
void pulse(int wait_fade) {
// let's fade up by scaling the brightness - in general, brightness shouldn't go above 93, so the strip won't draw too much power.
// Oh, and 93 is plenty bright!
for(int scale = 0; scale < 93; scale++) {
LEDS.setBrightness(scale);
LEDS.show();
delay(wait_fade);
}
// now let's fade down by scaling the brightness
for(int scale = 93; scale > 0; scale--) {
LEDS.setBrightness(scale);
LEDS.show();
delay(wait_fade);
}
}
// this is the main loop where we call the other functions.
void loop() {
int waiting_time = 10; //time in ms for color scaling
setcolor(color_set); //we call our color-set routine
pulse(waiting_time); //now we make it fade in and out
color_set++; //next color
color_set = color_set % 8; // number of color modulus, remember it's 0 based.
}
because there are so many different microcontrollers, i left it basic, and you only need to define color_set
as a integer and then the setcolor()
loop, as you can see in the main loop we pass the parameter color_set from our integral 8 colors. here is my complete arduino setup:
#include <FastLED.h>
#define LED_COUNT 96 // number of LEDs!
struct CRGB leds[LED_COUNT]; // this struct contains 60 CRGB values.
#define PIN_BUTTON 10
#define PIN_IO_A 7
#define PIN_IO_B 11
#define PIN_SIGNAL 13
#define PIN_INPUT 10
int color_set = 0; // set to red
int wait_fade = 1000 // delay time in ms. 1000ms is equal to 1sec
// first, let's get ready to blink using some FastLED routines
// take a look at the FastLED example called Fast2Dev for more usage info
void setup()
{
LEDS.addLeds<WS2812B, PIN_SIGNAL, GRB>(leds, LED_COUNT); // this configures the Board - leave as is.
LEDS.showColor(CRGB(0, 0, 0)); // set the color for the strip all at once.
LEDS.setBrightness(0); // start out with LEDs off
LEDS.show(); // you'll always need to call this function to make your changes happen.
}
// set the color for all the LEDs based on the color code
void setcolor(int colorcode) {
for (int i = 0; i < LED_COUNT; i++) {
// instead of setting the color all at once we're going to step through each LED to show how to set them individually
switch(colorcode) {
// We're going to pass a CRGB here,
case 0: leds[i] = CRGB(255, 0 , 0); break; // red
case 1: leds[i] = CRGB(255, 127, 0); break; // orange
case 2: leds[i] = CRGB(255, 255, 0); break; // yellow
case 3: leds[i] = CRGB(0, 255, 0); break; // green
case 4: leds[i] = CRGB(0, 255, 255); break; // cyan
case 5: leds[i] = CRGB(0, 0, 255); break; // blue
case 6: leds[i] = CRGB(75, 0, 130); break; // indigo
case 7: leds[i] = CRGB(148, 0, 211); break; // violet
}
}
LEDS.show();
}
// we'll make the color fade in and out by setting the brightness
void pulse(int wait_fade) {
// let's fade up by scaling the brightness - in general, brightness shouldn't go above 93, so the strip won't draw too much power.
// Oh, and 93 is plenty bright!
for(int scale = 0; scale < 93; scale++) {
LEDS.setBrightness(scale);
LEDS.show();
delay(wait_fade);
}
// now let's fade down by scaling the brightness
for(int scale = 93; scale > 0; scale--) {
LEDS.setBrightness(scale);
LEDS.show();
delay(wait_fade);
}
}
// this is the main loop where we call the other functions.
void loop() {
int waiting_time = 10; //time in ms for color scaling
setcolor(color_set); //we call our color-set routine
pulse(waiting_time); //now we make it fade in and out
color_set++; //next color
color_set = color_set % 8; // number of color modulus, remember it's 0 based.
}
A lot of the code is commented. I use FastLED too. If you have any questions please let me know.