Pages: [1]   Go Down
Author Topic: Single potentiometer to change LED Color?  (Read 117 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 36
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

Code:
// 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.
« Last Edit: July 23, 2014, 11:50:36 pm by Piethon » Logged

Poland
Offline Offline
Full Member
***
Karma: 7
Posts: 174
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Look at first post : http://forum.arduino.cc/index.php?topic=46874.0 . Maybe this would give you an idea.
Logged

Global Moderator
Boston area, metrowest
Offline Offline
Brattain Member
*****
Karma: 524
Posts: 26473
Author of "Arduino for Teens". Available for Design & Build services. Now with Unlimited Eagle board sizes!
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

With PWM output, each LED color can 1 of 256 choices.
I guess that's 16.5M color choices? (256*255*254?), 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 [] = {
0x3f50,
0x7ea0,
0xbdf0,
0xfd40,
etc.
:
:
0xfc8210,
0xfcc160,
0xfd00b0,
}
Then pull up a number, split it apart into the 3 PWM values for that color.


Logged

Designing & building electrical circuits for over 25 years. Check out the ATMega1284P based Bobuino and other '328P & '1284P creations & offerings at  www.crossroadsfencing.com/BobuinoRev17.
Arduino for Teens available at Amazon.com.

Offline Offline
Newbie
*
Karma: 0
Posts: 36
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Look at first post : http://forum.arduino.cc/index.php?topic=46874.0 . 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!  smiley-mr-green

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? 
Logged

Manchester (England England)
Offline Offline
Brattain Member
*****
Karma: 602
Posts: 33379
Solder is electric glue
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
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
Quote
run through all the colors possible
Is not going to happen.
Logged

Pages: [1]   Go Up
Jump to: