Hello.
What my project is supposed to do is:
-ask for input on serial monitor (1, 2, or 3)
-then light a specific LED based on the input.
When I type "1" in the serial monitor, the red LED lights as it is supposed to, but then the green LED lights up, though it is not supposed to. I just want the red LED to blink once, and then the program should wait for additional input before blinking another light. I want the green light to only light when I enter "3" in the serial monitor.
This Link is a link to a video where I enter "1" then "2" then "3". the green light always comes on after the red and yellow.
If anyone can help, I would really appreciate it!!
here is my code:
int pin2 = 2;
int pin7 = 7;
int pin12 = 12;
int delPer = 500;
void setup()
{
pinMode(pin2, OUTPUT);
pinMode(pin7, OUTPUT);
pinMode(pin12, OUTPUT);
Serial.begin(9600);
Serial.println("Enter 1 for red");
Serial.println("Enter 2 for yellow");
Serial.println("Enter 3 for green");
}
void loop()
{
if (Serial.available())
{
char ch = Serial.read();
if (ch == '1')
{
digitalWrite(pin2, HIGH);
delay(delPer);
digitalWrite(pin2, LOW);
}
else if (ch == '2')
{
digitalWrite (pin7, HIGH);
delay(delPer);
digitalWrite (pin7, LOW);
}
else if (ch =='3');
{
digitalWrite (pin12, HIGH);
delay(delPer);
digitalWrite (pin12, LOW);
}
}
}
Thanks again for any and all suggestions!