I am trying to modify the standard HSV Hue color code that ranges from 0 - 360 to one that ranges from 0 – 255. The Saturation and Brightness that range from 0 – 100 do not need to be modified only the Hue.
I need to modify the Hue range so it can be used in my Arduino program with slide controls to control some LED’s. The Arduino program uses a special FastLed library with a modified HSV Hue chart (0 – 255)
I have nowhere near the math skills to figure it out, because of the way the modified color chart works.
Fore example: On the standard HSV chart: 60 = Yellow, 120 = Green, 240 = Blue and 300 = Purple.
On the modified chart: 64 = Yellow, 96 = Green, 160 = Blue and 192 = Purple, and so on.
Here is the standard Hue chart: standard chart
Here is the modified Hue chart: modified chart
Here is the code I have to convert the Standard chart to RGB: (the slider sends a “h” value from 0 – 359) as stated I need this to work with a slider that sends a value from 0 – 255)
function ConvertHSVtoRGB(h,s,v) {
var r,g,b;
var c,x;
c = v*s;
if (h < 120) {x = h/60;}
else {
if (h < 240) {x = (h-120)/60;}
else {x = (h-240)/60;}
}
x = c * (1-Math.abs(x-1));
x += (v-c);
switch (Math.floor(h/60)) {
case 0: r = v; g = x; b = v-c; break;
case 1: r = x; g = v; b = v-c; break;
case 2: r = v-c; g = v; b = x; break;
case 3: r = v-c; g = x; b = v; break;
case 4: r = x; g = v-c; b = v; break;
case 5: r = v; g = v-c; b = x; break;
}
setRGBColor(r, g, b); }
function setRGBColor(r,g,b) {
r = Math.max(0, Math.min(255, Math.round(r255)));
g = Math.max(0, Math.min(255, Math.round(g255)));
b = Math.max(0, Math.min(255, Math.round(b*255)));
}
I would greatly appreciate if anyone can figure out the math needed to help me modify the code.
Thank you for taking the time to read my post, Mike.
Thank you Joriki.