Hello World ;
I am new Arduino user I am trying to do a very simple project the circuit contains 2 LEDs on is red and other is yellow and the user supposed to enter how many time each LED should blinks so I used this code multiple times no help on Arduino IDE 1.8.19 ( Latest release ) somehow it worked perfectly on Arduino IDE 1.5.4R2 which is so annoying my question how do I prompt the user to enter multiple value using serial in this release please help
int redLEDPin=9; //Declare redLEDPin an int, and set to pin 9
int yellowLEDPin=10; //Declare yellowLEDPin an int, and set to pin 10
int redOnTime=250; //Declare redOnTime an int, and set to 250 mseconds
int redOffTime=250; //Declare redOffTime an int, and set to 250
int yellowOnTime=250; //Declare yellowOnTime an int, and set to 250
int yellowOffTime=250; //Declare yellowOffTime an int, and set to 250
int numYellowBlinks; //Number of times to blink yellow LED
int numRedBlinks; //Number of times to blink red LED
String redMessage="The Red LED is Blinking"; //Declaring a String Variable
String yellowMessage= "The Yellow LED is Blinking"; //Declaring a String Variable
void setup() {
Serial.begin(115200); // Turn on the Serial Port
pinMode(redLEDPin, OUTPUT); // Tell Arduino that redLEDPin is an output pin
pinMode(yellowLEDPin, OUTPUT); //Tell Arduino that yellowLEDPin is an output pin
Serial.println("How Many Times Do You Want the Red LED to Blink? "); //Prompt User for Input
while (Serial.available()==0){ } //Wait for User Input
numRedBlinks = Serial.parseInt(); //Read User Input
Serial.println("How Many Times Do You Want the Yellow LED to Blink? "); //Prompt User for Input
while (Serial.available()==0){ } //Wait for Input
numYellowBlinks = Serial.parseInt(); //Read User Input
}
void loop() {
Serial.println(redMessage);
for (int j=1; j<=numRedBlinks; j=j+1) { // Start our for loop
Serial.print(" You are on Blink #: ");
Serial.println(j);
digitalWrite(redLEDPin,HIGH); //Turn red LED on
delay(redOnTime); //Leave on for redOnTime
digitalWrite(redLEDPin,LOW); //Turn red LED off
delay(redOffTime); //Leave off for redOffTime
}
Serial.println(" ");
Serial.println(yellowMessage);
for (int j=1; j<=numYellowBlinks; j=j+1) { // Start our for loop
Serial.print(" You are on Blink #: ");
Serial.println(j);
digitalWrite(yellowLEDPin,HIGH); //Turn yellow LED on
delay(yellowOnTime); //Leave on for yellowOnTime
digitalWrite(yellowLEDPin,LOW); //Turn yellow LED off
delay(yellowOffTime); //Leave off for yellowOffTime
}
Serial.println(" ");
}