Over the last few days I've been working on an anode RGB LED in Arduino, I've tried getting it to do an RGB spectrum but all I would get is just the colors from red to green, then it would get stuck on white and cyan, I believe that the red LED in the RGB Anode turns on and off, as the combination of green and blue is cyan and the three of them result white if they're equal which in this case I guess they are (not entirely sure).
Thing is the RGB Anode doesn't display all colors, I made it so the level of voltage given to the RGB anode is increased with a loop function and decreased once reached 255 with a decreasing function, here's the code:
int redPin = 11;
int greenPin = 10;
int bluePin = 9;
void setup() {
pinMode(redPin, OUTPUT);
pinMode(greenPin, OUTPUT);
pinMode(bluePin, OUTPUT);
}
void loop() {
redFuncInc(1);
delay(100);
greenFuncInc(1);
delay(150);
blueFuncInc(1);
delay(200);
// calling decreasing methods
redFuncDec(255);
delay(10);
greenFuncDec(255);
delay(15);
blueFuncDec(255);
delay(20);
}
// Increasing from rainbow spectrum
void redFuncInc(int red){
for (int i = 1; i<=255; i +=1){
analogWrite(redPin, i);
delay(10);
}
}
void greenFuncInc(int green){
for (int z = 1; z<=255; z +=1){
analogWrite(greenPin, z);
delay(20);
}
}
void blueFuncInc(int blue){
for (int u = 1; u<=255; u +=1){
analogWrite(bluePin, u);
delay(30);
}
}
// Decreasing from rainbow spectrum
void redFuncDec(int red){
for (int y = 255; y <=255; y -=1){
analogWrite(redPin, y);
delay(10);
}
}
void greenFuncDec(int green){
for (int x = 255; x <=255; x -=1){
analogWrite(greenPin, x);
delay(10);
}
}
void blueFuncDec(int blue){
for (int g = 255; g <=255; g -=1){
analogWrite(bluePin, g);
delay(10);
}
}
Thanks for your help, please don't mind my English...