ROYGBIV slider to RGB values using a formula

Hello I have a color slider here

and looking for advices on a way to convert them to RGB values via a formula instead of brute force manually typing all possible combination. what im reading is from left to right is 0x00 - 0xFF respectively. They are arranged by their spectrum frequency 700nm - 400nm (ROYGBIV)

is there a way to extract the 8bit rgb values from the wavelength frequency?

Yes, if you can measure the frequency.
Paul

Maybe not exactly what you want, but in the HSV (Hue, Saturation, Brightness) system the hue goes from 0 (red) to 360* (violet). So you could relate frequency to hue.

In the FastLED library the hue values go from 0 to 255 so it will fit in one byte.

Sadly no frequeny. I was thinking of setting the red most part as 700nm and the violet most part as 400nm split everything inbetween them by 256 values and extract it from there.

BUT i found a frequency chart red is 4.29x10^14 and violet is 7.5x10^14. so i cann map everything inbetweenn to those numbers.

So how to get the rgb values from the frequency ?

Don't confuse frequency and wavelength. Each is the reciprocal of the other.
What sort of rgb values are you looking for?
Paul

what do you mean by what sort of rgb values?

basically what i want to do is to for a RGB led that takes in an RGB values to follow what ever was selected on the color slider. The data i read from color slider is from 0 - 255 (red-violet). since im memory costrained i cannot simply list all the rgb values for all the position of the slider hence i am asking advice on how to do it in a formulaic way

Did you try a search? A couple of minutes searching came up with at least two languages using the same conversion algorithm e.g., Conversion of wavelength in nanometers to RGB in Python

2 Likes

This one looks good and siimple enough that i can port over to c++. but it a bit dominnant on the red side, ill have to play a bit with the numbers, how was he able to show the whole spectrum?

I found one that i like much better since it has a range so i know what to set my limits at

Maybe something simpler/more accurate for your needs : p5.js Web Editor

It can be easily converted to C/C++, I just did it with p5.js because it was easy to show the result

1 Like

looks good, but why is the green only valued at 128 ? since green has its own LED isnt it supposed to be 255? i did try to change it to 255 and it looked good

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.