Arduino programming has been a huge learning curve for me and I am trying to create a project with an rgb that's color is determined by a potentiometer. To where the further I turn it, the further across the rainbow spectrum it goes. I can't figure out how to do all values in between because I am not educated enough but I came up with this basic code...
int redpin = 6;
int greenpin = 3;
int bluepin = 5;
int potPin = 0;
void setup() {
// put your setup code here, to run once:
pinMode(redpin, OUTPUT);
pinMode(bluepin, OUTPUT);
pinMode(greenpin, OUTPUT);
pinMode(potPin, INPUT);
Serial.begin(9600);
}
void loop() {
// put your main code here, to run repeatedly:
int wavecolor = analogRead(potPin);
Serial.print(wavecolor);
{
if (wavecolor = 0) {
setColor(255, 0, 0); // red
}
if (wavecolor > 0 or wavecolor < 333) {
setColor(0, 255, 0); // green
}
if (wavecolor > 333 or wavecolor < 667) {
setColor(0, 0, 255); // blue
}
if (wavecolor > 667 or wavecolor < 1022) {
setColor(255, 255, 0); // yellow
}
if (wavecolor = 1023) {
setColor(80, 0, 80); // purple
}
}
}
void setColor(int red, int green, int blue)
{
#ifdef COMMON_ANODE
red = 255 - red;
green = 255 - green;
blue = 255 - blue;
#endif
analogWrite(redpin, red);
analogWrite(greenpin, green);
analogWrite(bluepin, blue);
}
And for some reason, where the light should change colors once the potentiometer goes past a certain number, the light just flickers and only changes colors to white when it is all the way up or down. Also, it has a weird flickery yellow color. Since I am new to this, can one of you better educated people be willing to assist me?