Go Down

Topic: Potentiometer controlled RGB fade without using serial (Read 1 time) previous topic - next topic

joey2point0

is there a way to use a potentiometer to control an RBG fade thought Arduino without using and type of serial command. the code below only semi works. how can i chage the code to fade smoothly through the whole color spectrum?


Code: [Select]


// BlinkM / BlinkM MinM pins
const int redPin = 3; 
const int grnPin = 4;
const int bluPin = 1; 
const int sclPin = 2; 

const int knobPin  = sclPin;

int pos;


void setup() {
  pinMode(redPin, OUTPUT);
  pinMode(grnPin, OUTPUT);
  pinMode(bluPin, OUTPUT);


  pinMode(knobPin, INPUT);

}

void loop() {

  pos = analogRead( knobPin );

 
  int redValue = constrain(map(pos, 0, 512, 255, 0),0,255);

  int greenValue = constrain(map(pos, 0, 512, 0, 255),0,255)-constrain(map(pos, 512, 1023, 0, 255),0,255); 

  int blueValue = constrain(map(pos, 512, 1023, 0, 255),0,255);




  analogWrite(redPin, redValue);

  analogWrite(grnPin, greenValue);

  analogWrite(bluPin, blueValue);
}

robtillaart

Quote
is there a way to use a potentiometer to control an RBG fade thought Arduino without using and type of serial command. the code below only semi works. how can i chage the code to fade smoothly through the whole color spectrum?


Yes, possible but not trivial and not 100% . There is a problem as the RGB color space is not "the whole colorspectrum".  In fact the colorspectrum is 3 dimensional and with your potmeter you can only control one dimension. To control the color along the rainbow (spectrum) you need the LAB color space - http://en.wikipedia.org/wiki/Lab_color_space - or the HSL colorspace  and convert it to RGB values. BUt this RGB is device dependant.

That said you can approximate the needed conversion quite well, for some formulas see  - http://www.easyrgb.com/index.php?X=MATH -

Try the HSL to RGB first




Rob Tillaart

Nederlandse sectie - http://arduino.cc/forum/index.php/board,77.0.html -
(Please do not PM for private consultancy)

joey2point0

I dont even know where to start with writing that into my program...

AWOL

I'm pretty sure there is example code for HSL to RGB somewhere; have you tried the Playground?
"Pete, it's a fool looks for logic in the chambers of the human heart." Ulysses Everett McGill.
Do not send technical questions via personal messaging - they will be ignored.

robtillaart


found this one - http://www.dipzo.com/wordpress/?p=50 - need a rewrite a bit to read from potmeter iso rotary encoder

Seems to work quite well
Rob Tillaart

Nederlandse sectie - http://arduino.cc/forum/index.php/board,77.0.html -
(Please do not PM for private consultancy)

joey2point0

Quote

found this one - http://www.dipzo.com/wordpress/?p=50 - need a rewrite a bit to read from potmeter iso rotary encoder

Seems to work quite well


The problem i am having is that anything that has "serial" in it, i will always get an error.

SurferTim

What error are you getting when you try the serial interface? Like in this thread?
http://arduino.cc/forum/index.php/topic,67519.0.html
If so, reply#10 in that thread had the solution for me.
Watch for me on National Geographic Wild "When Sharks Attack: Gulf Coast Killers". Airs on June 22nd.

nexekho

I've done something similar when designing a character creator for a game - a slider that selects hue.  I split the bar up into red->red+green, red+green->green, green->green+blue, green+blue->blue, blue->red+blue, red+blue->red and made each section linear interpolate.  Worked quite nicely.

AWOL

"Pete, it's a fool looks for logic in the chambers of the human heart." Ulysses Everett McGill.
Do not send technical questions via personal messaging - they will be ignored.

Go Up
 


Please enter a valid email to subscribe

Confirm your email address

We need to confirm your email address.
To complete the subscription, please click the link in the email we just sent you.

Thank you for subscribing!

Arduino
via Egeo 16
Torino, 10131
Italy