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?
// 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);
}
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 - CIELAB color space - Wikipedia - or the HSL colorspace and convert it to RGB values. BUt this RGB is device dependant.
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.