I’m using LVGL on a TFT display with an Arduino. I’m trying to get the RGB values from the color picker widget. The code seems to be working, but it’s returning unexpected values. I can’t seem to figure out what I’m missing or how I’m interpreting the data incorrectly.
lv_color_t selectedColor = lv_colorwheel_get_rgb(ui_colorWheel);
uint8_t red = selectedColor.ch.red;
uint8_t green = selectedColor.ch.green;
uint8_t blue = selectedColor.ch.blue;
Serial.print("Color changed to RGB: ");
Serial.println(red);
Serial.println(green);
Serial.println(blue);
When the color wheel selection is basically red (hard to get it exact), the output is:
Color changed to RGB: 31
3
0
I would expect something more like 255 for the red value. I know it’s red because later in the code I set the text color to the color wheel selection. What am I missing?
Setting it to yellow-ish, the output is:
Color changed to RGB: 30
63
0
I’m not understanding something. Any help is appreciated! Thanks
I get the same problem , does it should be 0 -255, it seems that the big value is 31
Here is the code I get rgb value :
uint16_t out[3];
lv_color_t c = lv_colorwheel_get_rgb(ui_Colorwheel3);
out[0] = LV_COLOR_GET_R(c);
out[1] = LV_COLOR_GET_G(c);
out[2] = LV_COLOR_GET_B(c);
I have try and cannot compile:
E:/project/TFT_BW8625/TFT_BW8625/main/ui.c:848:20: error: ‘lv_color_t’ {aka ‘union ’} has no member named ‘r’
out[0] = c.r;
^
E:/project/TFT_BW8625/TFT_BW8625/main/ui.c:849:20: error: ‘lv_color_t’ {aka ‘union ’} has no member named ‘g’
out[1] = c.g;
^
E:/project/TFT_BW8625/TFT_BW8625/main/ui.c:850:20: error: ‘lv_color_t’ {aka ‘union ’} has no member named ‘b’
out[2] = c.b;
attached file is lv_color.h file. lv_color.h (22.8 KB)
yes , have tried and cannot compile . You can check my lv_color.h , it doesn’t have member red green and blue . Below is the log :
E:/project/TFT_BW8625/TFT_BW8625/main/ui.c:848:20: error: ‘lv_color_t’ {aka ‘union ’} has no member named ‘red’
out[0] = c.red;
^
E:/project/TFT_BW8625/TFT_BW8625/main/ui.c:849:20: error: ‘lv_color_t’ {aka ‘union ’} has no member named ‘green’
out[1] = c.green;
^
E:/project/TFT_BW8625/TFT_BW8625/main/ui.c:850:20: error: ‘lv_color_t’ {aka ‘union ’} has no member named ‘blue’
out[2] = c.blue;
^
Thanks .
It can use
out[0] = c.ch.red;
out[1] = c.ch.green_h;
out[2] = c.ch.blue;
to get color value ,but it is the same value as what I have got before:
You may have to convert it to 32-bit color. You might try lv_color_to32.
See this bit of the documentation (convert color): Colors — LVGL documentation
That’s a relief you found a clean way to convert lv_color_t to lv_color32_t and extract the 32-bit RGB values correctly! Dealing with different color depths (like 16-bit vs. 32-bit) in embedded systems is always where the weird, unexpected values pop up. The lv_color_to32(c) conversion is definitely the key step there.Just a small suggestion for workflow: Since you are now working with 32-bit color spaces (which often correspond to standard screens), if you ever need to match a specific color from an external source (like a designer’s image or a web reference) and get the exact RGB numbers to plug into your code, I highly recommend using colorpickerimage.org.It’s a simple, free online tool where you can upload an image, click anywhere on it, and it gives you the precise decimal RGB values and HEX codes you need. Super useful for making sure the colors you get on your hardware match your intended design exactly!
Glad you got it working!