Single potentiometer to change LED Color?

Howdy howdy,

I was playing around with the RGB LED (sorry if that’s not what it’s called, it’s the single LED that can do Blue/Green/Red) and was wondering if it’s possible to use one potentiometer to “run the gamut” of colors (ie, run through all the colors possible)?

I have found a couple of sites (such as this one) that can do this, but using three potentiometers, but was wondering what the math would be to “wrap it into one”?

I can see it in my head, but can’t figure out a way to do it programatically. Is there a way to change the colors that doesn’t use RGB?

Hm, just thinking about it I could maybe do like

// psuedo code (or mainly general thoughts):

color = [0, 0, 0]                 //I'm thinking this can be an array, so I can change color[0], color[1], and color[2] individually
chgColor = map(potentiometer reading, 0, 1023, 0, 255)

if color[0] < 255, then keep color[1] and color[2] 0

But if color[0]= 255, then move on to color[1] and start from 0 and go to 255 as the colors go up...

Then when color[0] and color[1] are 255, start on color[3]

…does that even make sense?

Thanks for any thoughts!

edit: I know there’s an LED section, but figured this is more of a programming question than issue with LED, but mods feel free to move the post to the other area if you think it’s more appropriate there.

Look at first post : . Maybe this would give you an idea.

With PWM output, each LED color can 1 of 256 choices.
I guess that's 16.5M color choices? (256255254?), Or 0xFD0200 choices.
analogRead gives 1024 values, of 0x03FF choices.
0xfd0200/0x3ff = 0x3f50
So every 1 bit of analogRead could be 0x3f0 color choices away.
Make an array in progmem of unsigned long numbers.
colorArray = {
Then pull up a number, split it apart into the 3 PWM values for that color.

Look at first post : . Maybe this would give you an idea.

Hmm, that looks like what I was looking for - the math at the end is a little intimidating, but I'm sure it makes sense when I study it. Thanks! :grin:

CrossRoads, I see what you're saying, but am not sure about the HEX (that's HEX, ja?) values so would have to read up to know how to do that. Is that something I, as a relative beginner, should look in to - or should I come back to that once I get comfortable with C/programming in Arduino?

I see what you're saying,

Do you?
He is saying that there are way more colours you could get from your LED than there are positions you can detect with your pot. So the phrase

run through all the colors possible

Is not going to happen.