Hello, I just startet my first arduino / programming project ever.

Hello,
I just startet my first arduino / programming project ever.

I am planing to put some WS2812B in my kitchen cabinets, which have diffused glass fronts. I got 3 Cabinets. 2 with double doors, 1 with only 1 door. I want to use a singe stripe for all three cabinets. I will connect the three stripe pieces through holes in the sidewall. So cabinet setup looks like this:
[ .|. ][ .][ .||. ]

Besides putting in some cool random color changing I plan to make things happen when you step in the Kitchen (Motion sensor) opening or closing a cabinet door (door switches) and even adjust brightness depending on light in the kitchen.

But for know i think i managed to make some code which:
Defines number of leds (stripe lenght) in each cabinet. so I can easily change colors for each cabinet.

Generate a random color for every cabinet every “x” minutes

I cannot confirm the code works since i dont have the hardware on me right now, but i don’t get any errors compiling the code (which only took the whole day for this little bit of code since this is my really first contact with this kind of sorcery)

I would really appreciate if some could give me a feedback or advises how to improve this code.

Thanks, Jonas

Code looks like this:

#include <FastLED.h>

#define LED_PIN 6
#define COLOR_ORDER RGB
#define CHIPSET WS2812B
#define NUM_LEDS 109

#define BRIGHTNESS 200
#define FRAMES_PER_SECOND 120

CRGBArray < NUM_LEDS > leds;//CRGB all[NUM_LEDS];
CRGBSet left(leds(1,46)); //set custom ranges
CRGBSet middle(leds(47,62));
CRGBSet right(leds(63,109));

void setup(){
}

void loop() {

int random1 = random8 (); // generate Random Numbers (0…255) for random hue
int random2 = random8 ();
int random3 = random8 ();

for (int i=0;i<1;) // Check if colors are not to similar (only check 1;2 and 2;3. so 1;3 could be the same)
{
int colordif1 = abs(random1-random2); // absolute value of color
int colordif2 = abs(random2-random3);
if(colordif1<20)
{
random2 = random8();
}
else if(colordif2<20)
{
random2 = random8();
}
else
{
i+1;
}
}

CHSV color1(random1,255,255); //write colors with max saturation ; brightness
CHSV color2(random2,255,255);
CHSV color3(random3,255,255);

left = color1;
middle = color2;
right = color3;
FastLED.show();
delay(6*1000);
}

I Have the same question;
Does any one know if it exist… or … how the get access to a “simulator” for fast led library; like this video

This Video is by Marc Miller. The code is on github

Awesome thanks

My Code simpliy does nothing, while i dont get any error when uploading the Sketch. It simply holds all the LEDs as they were before uploading the Sketch.

Anyone got an idea why?

Your setup Part is empty. You need to define which led Strip you are using. Like
http://FastLED.addLeds<NEOPIXEL, DATA_PIN>(leds, NUM_LEDS);

See also https://github.com/FastLED/FastLED/wiki/Basic-usage

Thanks for the answer. Did that, nothing happens. Cant access Internet right now on Laptop sorry. Will continue tomorrow.

e1de0e30201016266eed5ad9bb6a4655.jpeg

Hi @Jonas_Kunzel , welcome to this world of LED sorcery! Those will be some sweet kitchen cabinets when you get this going. Looking forward to pics.

When posting code please use http://pastebin.com or http://gist.github.com as it makes it much easier to read the code and call out line numbers in discussion.

In the setup() section, in addition to the FastLED.addLeds info that Stefan pointed out, you should also add this line for setting the master brightness:
FastLED.setBrightness(BRIGHTNESS);

Your program isn’t doing anything because it gets stuck in the for loop and never gets down to the FastLED.show() part.

Did you run some of the example scripts that come with FastLED? If this is your first exploration into Arduino, programing, and FastLED try running some of the examples out first (since we know the code part will work). This will allow you to confirm your LED strip and wiring is working before diving into making your own custom code. In particular, try running FirstLight, RGBCalibrate, and Cylon.

Note how the Cylon example has a Serial.print statement in there which can provide some feedback in the serial monitor. Using Serial.print to print out variable values or even a message like “Random color assignments finished!” can be extremely useful when debugging things and trying to figure out what your code is actually doing, what values are being assigned to something, or where it might be getting stuck.

Btw, what microcontroller are you using?

Your for() loop isn’t complete and doesn’t appear necessary. You need something like for(int i = 0; i < 1; i++). That would run once, for i = 0. The next time around, i is not <1, so it will move on. Thus, it’s just a loop that runs once, so you can remove it. You might also consider defining the other colors based on some spacing in the hue range vs. randomly generating them and then making sure they’re significantly different. Something like:

random1 = random8();
random2 = ramdom1 + random(min, max);
random3 = random2 + random(min, max);

By setting min/max you can make sure that random1 + (2*max) isn’t “back around the rainbow” and you should get three randomly spaced hues. As an example, maybe a min of 30 and a max of 100. Since FastLED can “wrap”, you shouldn’t have any issues rolling over 255.

Like others are indirectly suggestions, start simple. Just get an LED blinking, or use something easy like:

void loop()
{
fill_rainbow(leds, NUM_LEDS, 0, 5);
FastLED.show();
}

Last comment: learn a bit about millisecond timers (like EVERY_N_MILLISECONDS(delay), as you’re going to run into big time problems if you have something like a 6sec delay. That delay() statement will hang all other operations, so when you eventually get some sensors going, they won’t be able to read during that full 6 seconds! Using EVERY_N_MILLISECONDS, they will.

@John_Hendy I like your idea of how to pick the random colors and keep them always nicely spaced out.

Hey, finaly i got time to answer back. Thanks for all the tips and tricks! Both Serial.println and EVERY_N_MILLISECONDS helping alot. When I googled it i found another thing. Instead of EVERY_N_MILLISECONDS I use

unsigned long currentmillis = millis()
if (currentmillis - lastchangemillis >= interval) {
lastchangemillis = currentmillis;
(…)

I also implemented John Hendrys random(min, max) method. :slight_smile:

Right now i managed to split up my strip in 3 spaces. Generate random colors (or hopefully even other effects) after a specific time.

Next step will be to work out some fade effects when i change to a new color. for now I didn´t manage to do that successfully.

After that I will start to implement my switches and change stuff as soon as a switch changes turns on or off.

My code so far looks like this: (NOTE not tested yet. But random color change should work)

I will write after i tested it and run into new problems :slight_smile:

Cheers
Jonas

I Have a Problem that i cant find out myself:

When is use:
-------------------------------
CRGBArray < NUM_LEDS > leds;
CRGBSet left(leds(0,44)); //set custom ranges
CRGBSet middle(leds(45,65));
CRGBSet right(leds(66,111));

CHSV color1hsv(X, Y, Z);
CHSV color2hsv(X, Y, Z);
CHSV color3hsv(X, Y, Z);

left = color1hsv;
middle = color2hsv;
right = color3hsv;
FastLED.show();

delay(1000);

fill_gradient(leds, 0, CHSV(X, Y, Z), NUM_LEDS, CHSV(X, Y, Z), SHORTEST_HUES);
FastLED.show();
-----------------------------------

I get errors like
/
note: mismatched types ‘T*’ and ‘CRGBArray<111>’

fill_gradient(leds, 0, CHSV(random1, randomvat1, brightness), NUM_LEDS, CHSV(random2, randomvat2, brightness), SHORTEST_HUES);

ote: template void fill_gradient(T*, uint16_t, const CHSV&, const CHSV&, const CHSV&, const CHSV&, TGradientDirectionCode)

void fill_gradient( T* targetArray, uint16_t numLeds,
/

How do i use fill_gradient with CRGB Array?

There’s two versions.
fill_gradient (when using HSV format)
and
fill_gradient_RGB (when using RGB format)

Ohh, okay i think i know what you mean. So the questions comes up: can i make something like a Chsv Array? I like the hue / vat thing more for effects.

Or another way: use fill Gradient hsv for a rgb Array with some Kind of conversion?

When you use HSV format FastLED will automatically convert to RGB behind the scenes for you. Here’s an example:

CHSV gradStartColor(0,255,255); // Gradient start color.
CHSV gradEndColor(161,255,255); // Gradient end color.

fill_gradient(leds, 0, gradStartColor, NUM_LEDS, gradEndColor, SHORTEST_HUES);

Post your full code to pastebin if you’re still having problems.

Okay, so I need to use it with RGB then right? Because when i use leds with fill_gradient i get an error. With fill_gradient_RGB i dont. But if i upload the sketch and look at the serial monitor it resets the whole sketch as soon as it gets to fill_gradient_RGB:
CHSV gradStartColor(0,255,255); // Gradient start color.
CHSV gradEndColor(161,255,255); // Gradient end color.

fill_gradient_RGB(leds, 0, gradStartColor, NUM_LEDS, gradEndColor, SHORTEST_HUES);

full code here:

Also tried:
CHSV gradStartColorCHSV(random1, randomvat1, brightness); // Gradient start color.
CHSV gradEndColorCHSV(random2, randomvat2, brightness); // Gradient end color.

CRGB gradStartColorCRGB;
CRGB gradENDColorCRGB;
hsv2rgb_rainbow( gradStartColorCHSV, gradStartColorCRGB);
hsv2rgb_rainbow( gradEndColorCHSV, gradENDColorCRGB);

fill_gradient_RGB(leds, 0, gradStartColorCRGB, NUM_LEDS, gradENDColorCRGB, SHORTEST_HUES);

Serial monitor just prints points as soon as it reaches fill_gradient_RGB

Hello Jonas. Sorry, I gave you a bit of bad info earlier. I forgot that if you want to fill all the way to the end of the strip you must use NUM_LEDS-1 as the end point otherwise it breaks things.

Also, if you chose to use fill_gradient_RGB then you can’t use SHORTEST_HUES on the end as that will also break things.

Here’s a file will fill_gradient examples. I know you will get it now!

Hey Marc, I really appreciate your help and are glad you are Helping! Even a not so detailed Info gives me new ideas and helpe me google stuff :). Thanks for the fill_gradient_examples, I got a better understanding of it now.

Anyway, even with the NUM_LEDS-1 the sketch just hangs up as soon as it reaches fill_gradient.

I think the Problem is how I can adress the leds in the first parameter of fill_gradient.

When i use
CRGB leds[NUM_LEDS];
fill_gradient(leds, X,Y,Z);

It works fine, but i cant use CRGB leds[]; AND CRGBArray <> leds; at the same time.

When I use:
CRGBArray < NUM_LEDS > leds;
fill_gradient(leds, X,Y,Z);

I get the error “no matching function for call to 'fill_gradient”.

I think the solution is a conversion from CSHVcolorto CRGBcolor.
BUT when i do that the sketch hangs up.
Conversion would look like this:
CHSV gradStartColorCHSV(random1, randomvat1, brightness);
CHSV gradEndColorCHSV(random2, randomvat2, brightness);

CRGB gradStartColorCRGB;
CRGB gradEndColorCRGB;

hsv2rgb_rainbow( gradStartColorCHSV, gradStartColorCRGB);
hsv2rgb_rainbow( gradEndColorCHSV, gradEndColorCRGB);

fill_gradient_RGB(leds, 0, gradStartColorCRGB, NUM_LEDS-1, gradEndColorCRGB, LONGEST_HUES);

So with this i don’t get an error when compiling, but sketch hangs up when reaching fill_gradient_RGB

Code here: https://gist.github.com/Husqvarna450/670d6188da0e4162b42c31653051d326

Looking at your code on line 14 you have:
CRGBSet right(leds(66, 111));
but I believe that should only go to 110 (if NUM_LEDS is 111).
You could code it this way so if NUM_LEDS changes the code will still work:
CRGBSet right(leds(66, NUM_LEDS-1));

Code line 133 should also have a 110 instead of 111 (or use NUM_LEDS-1)

Also, I think I see the error you’re running into when using CRGBArray and fill_gradient (which I can’t get to compile) vs fill_gradient_RGB (which does seem to work with CRGBArray).