Dear coding fellows,
I bought some RGB led's for a school project. When I connect them to an arduino leonardo or mega. The RGB decides to only light up in blue for some reason. This is the code that i'm using it's just a basic code that I found only so I don't think there can be much wrong with that.
int redPin= 7;
int greenPin = 6;
int bluePin = 5;
void setup() {
pinMode(redPin, OUTPUT);
pinMode(greenPin, OUTPUT);
pinMode(bluePin, OUTPUT);
}
void loop() {
setColor(255, 0, 0); // Red Color
delay(1000);
setColor(0, 255, 0); // Green Color
delay(1000);
setColor(0, 0, 255); // Blue Color
delay(1000);
setColor(255, 255, 255); // White Color
delay(1000);
setColor(170, 0, 255); // Purple Color
delay(1000);
}
void setColor(int redValue, int greenValue, int blueValue) {
analogWrite(redPin, redValue);
analogWrite(greenPin, greenValue);
analogWrite(bluePin, blueValue);
}