I'm a beginner on arduino.
I have an arduino mega with two LED (like the image with only 2 less and without the buzzer). A red LED and a green LED. When the arduino receive the code 200 I want the red LED turn on and the green LED turn off. But when I test that but any led turn off or turn on..
void setup()
{
pinMode(LR, OUTPUT);
pinMode(LV, OUTPUT);
Serial.begin(9600);
}
void readSerial(){
while(Serial.available() > 0){
car = Serial.read();
if(car != '+'){
buff[i] = car;
buff[i+1] = '\0';
i++;
}
else{
sscanf(buff, "%d", &received_code);
}
}
}
void loop()
{
readSerial();
if (received_code == 200){
LRstate = HIGH;
digitalWrite(LR, LRstate); // turn the LED on (HIGH is the voltage level)
digitalWrite(LR,LOW);
delay(100);
digitalWrite(LV,LOW);
}
}
How can I solve my problem?
Thanks a lot.
But when I test that but any led turn off or turn on.
, as this sentence isn't very clear.