I fail to see my mistake!! I am relearning a lot of things,

I fail to see my mistake!!

I am relearning a lot of things, and I am trying to use HSV in the “moving pixel” example

the original example:

#include <FastLED.h>
#define NUM_LEDS 10
#define DATA_PIN 23

CRGB leds[NUM_LEDS];

void setup() {
FastLED.addLeds<NEOPIXEL, DATA_PIN>(leds, NUM_LEDS);
}

void loop() {

    for(int dot = 0; dot < 10; dot++) { 
    leds[dot] = CRGB::Red;
    FastLED.show();
    leds[dot] = CRGB::Black;
    delay(30);
    }

}

my modification for HSV:

#include <FastLED.h>
#define NUM_LEDS 10
#define DATA_PIN 23

CRGB leds[NUM_LEDS];
CHSV hsvs[NUM_LEDS];

void setup() {
FastLED.addLeds<NEOPIXEL, DATA_PIN>(leds, NUM_LEDS);
}

void loop() {

    hsv2rgb_rainbow(hsvs,leds,NUM_LEDS);
    
    for(int dot = 0; dot < 10; dot++) { 
    hsvs[dot] = CHSV(255,255,255);
    FastLED.show();
    hsvs[dot] = CHSV(255,255,0);
    delay(30);
    }

}

the result: every pixel off

what am I doing wrong?

I’m no expert but I think you need to have FastLED.show() to “display” the LEDs when they’re off.

Don’t quote me on this, because I’m a noob, but something like… ??

for(int dot = 0; dot < 10; dot++) {
hsvs[dot] = CHSV(255,255,255);
FastLED.show();
delay(30);
}
for(int dot = 0; dot < 10; dot++) {
hsvs[dot] = CHSV(255,255,0);
FastLED.show();
delay(30);
}

noup. that is not the problem… continues being all off

It should be leds[dot]=CHSV(…)

@Jarrod_Wagner

It works like this, but I think it should also work with hsvs… and I would need it to work as hsvs because if I want to manipulate the values in HSV, I need to trigger hsvs and not leds…

in setup() you use FastLED.addLEDS to add the “led” array. This means that FastLED will show this array. the hsvs array is an array that is kept in memory but used for nothing, and FastLED is not aware of it.

So any manipulation of this array does have no visible effect.

What are you trying to achieve by having two different arrays ?

I am not trying to achieve anything. I am trying to figure out how to do this. I did this because I am cotrolling the leds in a different sketch like this and it works.

this is the other example where I also have two arrays, and I can handle hsvs happily:

#include <FastLED.h>
#define NUM_LEDS 12
#define DATA_PIN 41

CRGB leds[NUM_LEDS];
CHSV hsvs[NUM_LEDS];

int threshold = 700;

boolean Key1LastState01 = false;

int sensorValue01;

void setup() {
FastLED.addLeds <WS2811, DATA_PIN, BRG>(leds, NUM_LEDS);
}

void loop() {

fadePixels();
hsv2rgb_rainbow(hsvs,leds,NUM_LEDS);
FastLED.show();

sensorValue01 = analogRead(A0);

if (sensorValue01 > threshold && Key1LastState01 == false) {
hsvs[0] = CHSV(213,255,254);
Key1LastState01 = true;
}
else if (sensorValue01 < threshold && Key1LastState01 == true) {
hsvs[0] = CHSV(213,255,255);
Key1LastState01 = false;
}
}

void fadePixels() {
if(hsvs[0].v > 0 && hsvs[0].v < 255) {
hsvs[0].v = qsub8(hsvs[0].v, 2);
}
}

take a look at this post where @Mark_Kriegsman help me out making the sketch work with hsvs…

https://plus.google.com/114844607488015640212/posts/JQv8T7qb82U

mark? any idea?

You have to call hsv2rgb_rainbow immediately before FastLED.show()

@Leo_Bettinelli ​ you’re confusing 2 different ideas here.

The struct leds ( CRGB leds[num_leds]) is the storage for information.

Colorspaces in fastLED (CRGB::… And HSV(…)) Are methods of modifying that information before it’s sent to the leds by fastLED.show().

By declaring a second “storage” for those LED values, you must inform the library that there is a second instance of those LEDs to be changed or written out to the physical LEDs.

You would perform a SECOND addLEDs with the substituted, correct information.

You can use both HSV AND CRGB on the same led array quite happily. Even in the same loop…

Your order of operations isn’t what you think. The hsv2rgb call will translate your HSV array to an RGB array prior to show(), so you understand that. However, you call it once, and then go into your color set loop and don’t do it again. I think your idea is to blink the lights to test this all out. It may work better like this.

// Set them all white
void loop()
{
for (int i = 0; i < NUM_LEDS; i++) {
hsvs[i] = CHSV(255,255,255);
}
hsv2rgb_rainbow(hsvs, leds, NUM_LEDS);
FastLED.show();
}

What you are doing is setting your CRGB array first with no data. Then, you loop through setting all your pixels to white, then to black again, with a show in the middle (the array doesn’t get translated in the middle which is what I think you assume). Since you set them black again after the show, when you next call hsv2rgb_rainbow(), they are all black again, and this will continue until you stop it.

If you want them to blink, do this

// All on and off in a loop every second
void loop()
{
for (int i = 0; i < NUM_LEDS; i++) {
hsvs[i] = CHSV(255,255,255);
}
hsv2rgb_rainbow(hsvs, leds, NUM_LEDS);
FastLED.show();

delay(1000);

for (int i = 0; i < NUM_LEDS; i++) {
hsvs[i] = CHSV(255,255,0);
}
hsv2rgb_rainbow(hsvs, leds, NUM_LEDS);
FastLED.show();
}

It’s CHSV, not CRGB, so the v in this case being 0 means no color.

I haven’t coded up a CHSV in a while though, so I may be remembering the HSV setup wrong, but I think this is what’s happening.

thanks guys!

It is clearer for me now

:slight_smile:

V=value=brightness:255. White should have a saturation value of 0 so CHSV(x,0,255);