I'm trying to put LED's into a bookshelf, but I want each of the shelfs to glow a different solid color. I'm having trouble writing a code where for example first 10 LEDS are Green and the next 10 are Red and stay static. This is variable since my shelf sizes are all different. I imagine I'll need like 16 colors over like 32ft. I'm currently experimenting with UNO R3 and 16ft of WS2812B. The code I've been attempting to write is below
#include <FastLED.h>
#define NUM_LEDS 20
#define LED_PIN 7
CRGB leds[NUM_LEDS];
void setup() {
FastLED.addLeds<WS2812B, LED_PIN, GRB>(leds, NUM_LEDS);
FastLED.setBrightness(50);
}
void loop() {
for(int i = NUM_LEDS; i <= 10;i--){
fill_solid (leds, i, CRGB::Red);
FastLED.show();
}
for(int i = NUM_LEDS; i >= 10;i++){
fill_solid(leds, i, CRGB::Green);
FastLED.show();
}
}
it was a place holder since I planned to use expand this code to more LEDs. So you’ll have to change the #define NUM_LEDs to 30 for this to work for all 30 in the code.
Try the sketch in Post #5. See how it does what your friend suggested in three lines? This method (fill_solid()) is called pixel-plaining, used for large-scale, high-speed graphics, where you define an area, color-in the area, then move to the next plain.
Here is Post #5, where all you need to do is change the NUM_LEDS and the 1/2, 1/4, 1/4 is done for you...