Bought my first arduino board two days ago and have just been playing around with LED's etc, I've built a 3x3 cube and have had no problem programming it to display an array of patterns etc.
Today I got some 3mm RGB LED's. I have it plugged into a breadboard with the common cathode plugged into a 10k Ohm resister, and then into the 5v on the arudino board.
Each of the three annodes is plugged into digital pins 8,9 and 10.
This is the code I'm using:
int red = 8;
int blue = 9;
int green = 10;
int time = 500;
// the setup routine runs once when you press reset:
void setup() {
// initialize the digital pin as an output.
pinMode(red, OUTPUT);
pinMode(blue, OUTPUT);
pinMode(green, OUTPUT);
digitalWrite(red, HIGH);
digitalWrite(green, HIGH);
digitalWrite(blue, HIGH);
}
void loop() {
digitalWrite(red, LOW); //Red
delay(time);
digitalWrite(red, HIGH);
delay(time);
digitalWrite(green, LOW); //Green
delay(time);
digitalWrite(green, HIGH);
delay(time);
digitalWrite(blue, LOW); //Blue
delay(time);
digitalWrite(blue, HIGH);
delay(time);
digitalWrite(red, LOW); //Red & Green
digitalWrite(green, LOW);
delay(time);
digitalWrite(red, HIGH);
digitalWrite(green, HIGH);
delay(time);
digitalWrite(green, HIGH); //Green & Blue
digitalWrite(blue, HIGH);
delay(time);
digitalWrite(green, HIGH);
digitalWrite(blue, HIGH);
delay(time);
digitalWrite(red, LOW); //Red & Blue
digitalWrite(blue, LOW);
delay(time);
digitalWrite(red, HIGH);
digitalWrite(blue, HIGH);
delay(time);
}
With the above code I was trying to flash on then off each color on separately, then start mixing to colors two at a time.
When the program runs, turning on each colour one at a time works as expected, but things start turning weird when I try to use two colours.
This is what I see happening:
red on
pause
red off
pause
blue on
pause
blue off
pause
green on
pause
green off
pause
(where it gets weird)
red on
red off
blue on
blue off
pause
green on
green off
pause
This red bit then continually repeats.