Hi everyone
I'm trying to control the color of an common anode RGB LED, powering it using the 5v from the board and a 200ohm. using 3 potentiometers and PWM i control the each color, I have a problem as color red reaches full brightness it overpowers the other 2 colors and all you can see is a red LED.
This is the code.
#define LED_rojo 9 //Red LED
#define LED_verde 10 //Green LED
#define LED_azul 11 //Blue LED
#define Pot_rojo A0 //Red Potentiometer
#define Pot_verde A1 //Green Potentiometer
#define Pot_azul A2 //Blue Potentiometer
int INT_verde=0,INT_rojo=0,INT_azul=0; //color brightness (0-255)
void setup()
{
pinMode(LED_rojo,OUTPUT);
pinMode(LED_verde,OUTPUT);
pinMode(LED_azul,OUTPUT);
Serial.begin(9600);
}
void lectura() //read and convert to a value of 0-255
{
int lectura=0;
lectura=analogRead(Pot_rojo);
INT_rojo=255-((lectura*(5.0/1023.0))*255)/5;
lectura=0;
lectura=analogRead(Pot_verde);
INT_verde=255-((lectura*(5.0/1023.0))*255)/5;
lectura=0;
lectura=analogRead(Pot_azul);
INT_azul=255-((lectura*(5.0/1023.0))*255)/5;
lectura=0;
if(INT_rojo<=255 && INT_rojo>=250){INT_rojo=255;}
if(INT_verde<=255 && INT_verde>=250){INT_verde=255;}
if(INT_azul<=255 && INT_azul>=250){INT_azul=255;}
if(INT_rojo<=5 && INT_rojo>=0){INT_rojo=0;}
if(INT_verde<=5 && INT_verde>=0){INT_verde=0;}
if(INT_azul<=5 && INT_azul>=0){INT_azul=0;}
}
void loop() {
lectura();
analogWrite(LED_rojo,INT_rojo); //write the red LED
analogWrite(LED_verde,INT_verde); //write the green LED
analogWrite(LED_azul,INT_azul); //write the blue LED
Serial.print("Rojo: ");
Serial.print(INT_rojo);
Serial.print(" Verde: ");
Serial.print(INT_verde);
Serial.print(" Azul: ");
Serial.println(INT_azul);
}