I figured I'd try to make a moodlight as a cool touch to any project. I have this WEIRD RGB LED, though. I can't get the code to work right. Can someone help me try to figure out what is wrong? It cycles through all the colors, but it occasionally acts erratically. Sometimes it will just fade in and out one color, and other times it will 'jump' from one color to another (not transitioning). Here's the code:
int onePin = 3; //RED
int twoPin = 5; //BLUE
int threePin = 6; //GREEN
int i;
int selPin;
void setup()
{
Serial.begin(9600);
pinMode(onePin, OUTPUT);
pinMode(twoPin, OUTPUT);
pinMode(threePin, OUTPUT);
randomSeed(analogRead(0));
}
void loop() {
//digitalWrite(onePin, LOW);
//digitalWrite(twoPin, LOW);
//digitalWrite(threePin, LOW);
//delay(300);
//digitalWrite(onePin, HIGH);
//digitalWrite(twoPin, HIGH);
//digitalWrite(threePin, HIGH);
//delay(300);
//digitalWrite(onePin, LOW);
//digitalWrite(twoPin, LOW);
//digitalWrite(threePin, HIGH);
//delay(10000);
selectPin();
for(i = 255; i > 0; i--) {
analogWrite(selPin, i);
delay(5);
}
selectPin();
for(i = 0; i < 255; i++) {
analogWrite(selPin, i);
delay(5);
}
}
void selectPin() {
selPin = random(7);
switch(selPin) {
case 0:
selectPin();
break;
case 1:
selectPin();
break;
case 2:
selectPin();
break;
case 4:
selectPin();
break;
case 7:
selectPin();
break;
}
}
And here's a post on this unique LED that you MUST read before speculating on how to fix this:
http://forums.parallax.com/forums/default.aspx?f=5&m=266028&p=1
All help is appreciated!