RGB LED

Hi everyone, I have a question, related to rgb led, in my work I need to put two alternating colors, like the police siren, and I do not know how to do it, when I try, it makes a junction of the two, like magenta Thanks.

(deleted)

float TempC; float TempC1; float TempC2; int tempPin1=1; //sensor int tempPin=0; // sensor int tempPin2=2; //sensor int Rled=9; int Bled=10; int Gled=11;

void setup () {

Serial.begin(9600);

pinMode(Rled,OUTPUT); pinMode(Bled,OUTPUT); pinMode(Gled,OUTPUT);}

void loop () {

TempC= analogRead(tempPin); TempC= ((5.0*TempC*100.0)/1024.0);

delay (1000);

TempC1= analogRead(tempPin1); TempC1= ((5.0*TempC1*100.0)/1024.0);

delay (1000);

TempC2= analogRead(tempPin2); TempC2= ((5.0*TempC2*100.0)/1024.0);

delay (1000);

if (TempC>80) { analogWrite(Rled,255); analogWrite(Bled,0); analogWrite(Gled,0); delay(500); analogWrite(Rled,0); analogWrite(Bled,255); analogWrite(Gled,0);

}

}

Is your RGB LED common anode? If so a 0 will turn on a color and 255 will turn it off. So when you think that you are turning on the red LED, you actually are turning on green and blue (cyan).

analogWrite(Rled,255);
  analogWrite(Bled,0);
  analogWrite(Gled,0);

is cathodo

And with a resistor in each anode?

yes

Have you tested the LED to turn on all colors one at a time? Did this work?

when I try, it makes a junction of the two, like magenta

Try a bigger delay between the two states. You have half a second at the moment maybe that is too fast for your eyes.