Hi all, I've been enjoying playing with my first Uno and some SK6812WWA LED

Hi all, I’ve been enjoying playing with my first Uno and some SK6812WWA LED strips. I’ve been using the FastLED library and defining/controlling them like the RGB WS2821B seems to work fine, but I have a few basic questions-

Using CHSV instead of CRGB I’m trying to control both the H (hue) and the S (Saturation), so I can adjust colour and brightness. I have part of it working but could really benefit from some expert advice :slight_smile:

  1. All LED’s will be outputting the same, how do I talk to them all without referencing each one separately like I am currently?

    leds[0] = CHSV(0,255,255);
    leds[1] = CHSV(0,255,255);
    leds[2] = CHSV(0,255,255);
    leds[3] = CHSV(0,255,255);
    leds[4] = CHSV(0,255,255);
    leds[5] = CHSV(0,255,255);

To be able to reduce this to a single line like leds[0-6] = etc

  1. I’ve got a pot adjusting the Hue value but only by using if else statements. How do I make Hue and Value a variable and set up 10 steps for each?

I’m currently doing it inefficienctly like this -

void loop() {

int val = analogRead(1);
if (val < 125) {

leds[0] = CHSV(0,255,255);
leds[1] = CHSV(0,255,255);
leds[2] = CHSV(0,255,255);
leds[3] = CHSV(0,255,255);
leds[4] = CHSV(0,255,255);
leds[5] = CHSV(0,255,255);

FastLED.show();

}
else if (val < 250) {

leds[0] = CHSV(34,255,255);
leds[1] = CHSV(34,255,255);
leds[2] = CHSV(34,255,255);
leds[3] = CHSV(34,255,255);
leds[4] = CHSV(34,255,255);
leds[5] = CHSV(34,255,255);

an so on etc.

Any support would be much appreciated.

Rob

use the map function to scale the pot reading to 0…255 (you also could divide by 8); but with map you also can ‘turn’ the pot around. https://www.arduino.cc/en/Reference/Map
int gHue = map(analogRead(1), 0, 1023, 0, 255);
leds[0] = CHSV(gHue, 255, 255);
FastLED.show();

To turn it around:
int gHue = map(analogRead(1), 1023, 0, 0, 255);

Thank you Juergen, The map function is perfect :slight_smile:
How do I make this function assign to all the LEDs (NUM_LEDS)

At the moment I’m writing to each one individually, so it’s not ideal?

leds[0] = CHSV(gHue, 255, 255);
leds[1] = CHSV(gHue, 255, 255);
leds[2] = CHSV(gHue, 255, 255);
leds[3] = CHSV(gHue, 255, 255);
leds[4] = CHSV(gHue, 255, 255);
leds[5] = CHSV(gHue, 255, 255);

#define NUM_LEDS 6
CRGB leds[NUM_LEDS];

just look over to the post next to you
https://plus.google.com/112445599599385082979/posts/6kXny2QPWVw