0
votes

I need to write a program in Arduino that turns ON or OFF two LEDs independently depending on the data received via serial communication. For example, the first LED will turn on if the Arduino board receives a1,and it will turn OFF if a2 is received. but I require help on doing this. i havent started on this yet but i am trying to do it using 2 blinking light code. I am new to Arduino programming and i don't understand some concepts. but i can definitely use help on doing this.

int LEDred = 3;
int LEDgreen = 6;

void setup() {
    pinMode (LEDred, OUTPUT);
    pinMode (LEDgreen, OUTPUT);
}

void loop() {
    digitalWrite (LEDred, HIGH);
    digitalWrite (LEDgreen, LOW);
    delay (1000);
    digitalWrite (LEDred, LOW);
    digitalWrite (LEDgreen, HIGH);
    delay (1000);
}
1
see the BlinkWithoutDelay example - Juraj
What do you mean by ...receives a1? Do you mean when pin A1 is high? Or do you mean you receive an "a1" on the serial port? Please edit you question and be clear. - lurker
@lurker YES thats the one - ibrahim shaffee

1 Answers

0
votes

Use 1 or 2 instead of a1 and a2. Because it's easier to process.Consider you send 1 via serial port. Read the signal by

byte val;
if(Serial.available()>0){
val=Serial.read();
}

Then use another if statement in order to blink red or green LED