Hi. I have a delay() issue.
By this code, I want to have red light only 5 seconds and then change to green light.
But if I try this, the delay of the red light comes out like 10 seconds and 20 seconds long.
If I have delay less than 1 second, then it works well. But over 5 seconds, the light changes so late.
If you help me solve this problem I would sincerely appreciate it.
Thank you.
int RED = 6;
int GREEN = 7;
int BLUE = 8;
void setup(){
Serial.begin(9600);
pinMode(RED,OUTPUT);
pinMode(GREEN,OUTPUT);
pinMode(BLUE,OUTPUT);
}
void loop(){
while(Serial.available()>0){
char ser=Serial.read();
switch(ser){
case '0':
setColor(255,0,0);
delay(5000);
break;
case'1':
setColor(0,255,0);
delay(5000);
break;
}
}
}
void setColor(int red, int green, int blue)
{
analogWrite(RED, red);
analogWrite(GREEN, green);
analogWrite(BLUE, blue);
}