Question: what is the simplest way to call the HSV to rgb conversion that is built into the fastspi library? I have a sketch that uses static byte vales for r, g , and b .
leds[i] = CHSV(h, s, v) is nice
And if you want to extract the individual values into your own “r, g, b” variables:
CRGB rgb( CHSV( hue, sat, val ) );
r = rgb.r;
g = rgb.g;
b = rgb.b;
There’s no API for calling hsv2rgb with six scalar variables (H,S,V inputs and &R,&G,&B outputs). However, both Zeke’s example and this one (above) compile down into code that’s approximately as efficient as it would be passing in six separate variables – and sometimes it’s actually smaller/faster than that.
This code work for you?
for the first suggestion from Zeke:
my code works with:
leds[iLed] = CRGB(red,blue,green);
But when I add:
setup()
int h = 300;
int s = 100;
int v = 100;
and
add one line in
loop()
leds[iLed] = CHSV(h, s, v);
I get error messages:
In function ‘void choosearray(int)’:
no match for ‘operator=’ in ‘leds[((int)iLed)] = CHSV(((uint8_t)h), ((uint8_t)s), ((uint8_t)v))’
C:\Users\hib\Documents\Arduino\libraries\FastSPI_LED2/pixeltypes.h:118: note: candidates are: CRGB& CRGB::operator=(const CRGB&)
C:\Users\hib\Documents\Arduino\libraries\FastSPI_LED2/pixeltypes.h:127: note: CRGB& CRGB::operator=(uint32_t)
when I try Mark’s suggestion and
use:
CRGB rgb( CHSV( hue, sat, val ) );
r = rgb.r;
g = rgb.g;
b = rgb.b;
instead of
I get many errors dealing with not declaring a class or struct (which I am not that familiar with;
mario_1.ino: In function ‘void choosearray(int)’:
mario_1:98: error: expected primary-expression before ‘rgb’
mario_1:98: error: expected ;' before 'rgb' mario_1:99: error: 'r' was not declared in this scope mario_1:99: error: request for member 'r' in 'rgb', which is of non-class type 'int [3][3][3]' mario_1:100: error: 'g' was not declared in this scope mario_1:100: error: request for member 'g' in 'rgb', which is of non-class type 'int [3][3][3]' mario_1:101: error: 'b' was not declared in this scope mario_1:101: error: request for member 'b' in 'rgb', which is of non-class type 'int [3][3][3]' mario_1:107: error: expected primary-expression before 'rgb' mario_1:107: error: expected;’ before ‘rgb’
mario_1:108: error: ‘r’ was not declared in this scope
mario_1:108: error: request for member ‘r’ in ‘rgb’, which is of non-class type ‘int [3][3][3]’
mario_1:109: error: ‘g’ was not declared in this scope
mario_1:109: error: request for member ‘g’ in ‘rgb’, which is of non-class type ‘int [3][3][3]’
mario_1:110: error: ‘b’ was not declared in this scope
mario_1:110: error: request for member ‘b’ in ‘rgb’, which is of non-class type ‘int [3][3][3]’
mario_1:114: error: expected primary-expression before ‘rgb’
mario_1:114: error: expected ;' before 'rgb' mario_1:115: error: 'r' was not declared in this scope mario_1:115: error: request for member 'r' in 'rgb', which is of non-class type 'int [3][3][3]' mario_1:116: error: 'g' was not declared in this scope mario_1:116: error: request for member 'g' in 'rgb', which is of non-class type 'int [3][3][3]' mario_1:117: error: 'b' was not declared in this scope mario_1:117: error: request for member 'b' in 'rgb', which is of non-class type 'int [3][3][3]' mario_1:121: error: expected primary-expression before 'rgb' mario_1:121: error: expected;’ before ‘rgb’
mario_1:122: error: ‘r’ was not declared in this scope
mario_1:122: error: request for member ‘r’ in ‘rgb’, which is of non-class type ‘int [3][3][3]’
mario_1:123: error: ‘g’ was not declared in this scope
mario_1:123: error: request for member ‘g’ in ‘rgb’, which is of non-class type ‘int [3][3][3]’
mario_1:124: error: ‘b’ was not declared in this scope
mario_1:124: error: request for member ‘b’ in ‘rgb’, which is of non-class type ‘int [3][3][3]’
What version of the library are you using? RC5 is the latest. https://code.google.com/p/fastspi/downloads/list I just want to make sure we’re on the same page before digging in to the details here.
Also just FYI, something to think about once we get the compilation issues under control here: in the FastLED library, hue, saturation, and brightness are defined here as 8-bit values from 0-255; they should be declared as “uint8_t” or simply just “byte” instead of “int” (which is a 16-bit data type). There’s some discussion of that here: https://code.google.com/p/fastspi/wiki/CRGBreference#Introduction_to_HSV
I just tested with RC5 and this program compiles and works. This is the entire program; you might want to try compiling this and see what you get.
#include “FastLED.h”
#define OUTPUT_PIN 13
#define NUM_LEDS 10
CRGB leds[NUM_LEDS];
byte h = 200;
byte s = 100;
byte v = 100;
void setup() {
FastLED.addLeds< WS2811, OUTPUT_PIN, GRB>(leds, NUM_LEDS);
}
void loop() {
for( int i = 0; i < NUM_LEDS; i++) {
leds[i] = CHSV(h, s, v); // HSV to RGB assignment
}
FastLED.show();
}
@Mark_Kriegsman
I uninstalled prior FastSPI library an installed RC5.
I tried your code but it calls for a missing library in the first line
#include “FastLED.h”
Since there is no such file in RC5, I substituted “FastSPI_LED2.h” and it compiled.
tomorrow I will HSV with my sketch.
thanks
Ah…ooops, sorry about the “FastLED.h” name problem! You did the right thing switching to FastSPI_LED2.
I bet that with the old version removed you’ll have success.
I ran the sketch with my LPD8806 strip and I get no control over color with H.
H and S together affect color sometimes, but not in any known manner. V controls brightness
Do you have any suggestions?
If you keep S and V both at 255, and just change Hue, do you get sensible results?
And just to make sure the basics are working: when you use RGB values directly instead of HSV, do you get the expected results?
that did the trick,
thanks
Great! Can’t wait to see the results!
Happy to help.