0

I'm trying to use CHSV with FastLED library and as I understand hue, value and saturation in the CHSV type are of type uint8_t, or 1 byte.

My problem is with using variables:

CHSV led = (hue, sat, val); 

with:

uint8_t hue;
uint8_t sat;
uint8_t val;
  1. Is there a difference between uint8_t and byte data types? what is it and how does one use it with the context of arduino and FastLED library?

  2. Am I getting the syntax wrong? I get an error - convertion from 'uint8_t' to non scalar type 'CHSV' requasted. I thought the library does that on its own, do I need to add more code? If yes, what code?

Thank you

1

Is there a difference between uint8_t and byte data types?

There is no difference in the datatype. byte is defined in Arduino.h:

typedef uint8_t byte;

So, uint8_t and byte are exactly the same. The uintX_t types and their siblings are specifically meant for having the same size on every platform (in difference to for example double which is only 16 bits on Arduino Uno, but can be 32 bits on bigger chips). But byte will also be 8 bits on every platform, so there is really no difference.

Am I getting the syntax wrong? I get an error - convertion from 'uint8_t' to non scalar type 'CHSV' requasted. I thought the library does that on its own, do I need to add more code? If yes, what code?

You get the error, because you use the wrong syntax here. A CHSV color is not just 3 byte values, it is a class with member variables and methods. So you cannot simply assign 3 byte values directly to the object. You need to actually create the object, using the values as parameters for the constructor:

CHSV led = CHSV( hue, sat, val);

This creates a CHSV object, executes it's constructor, which uses the values from the parameters to set the internal values. That is the context, how this is used in the FastLED library. You can also find such lines in the examples of the library (I found such use in line 15 of the example ColorPalette, but there might be more). Also this is the same principle, as with the other color classes, like CRGB.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.