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);
}