Hi I have been following Paul McWhorter on youtube and I am having some problems using a while loop so I can tell the code through the serial port the video was posted in 2014.
So I am unsure if there are some changes in the creation of the code with the newer version of the software.
the actual problem is that the serial port will ask for the first setting then will skip the second and allow the 3rd to be set you can add the settings if you are quick but the serial port is not pausing waiting for all settings to be set.
please find my code below:-
int redLEDPin=9; //Declaring redLEDPin as an int, and set to pin 9
int whiteLEDPin=10; //Declaring whiteLEDPin as an int, and set to pin 10
int redOnTime=250; //this is the red LED on time
int redOffTime=250; //this is the red LED off time
int whiteOnTime=250; //this is the white LED on time
int whiteOffTime=250; //this is the white LED off time
int numRedBlink; //number of times the red LED blinks
int numWhiteBlink; //number of times the white LED blinks
String redMessage=“the Red LED is blinking”; //Declaring a String variable
String WhiteMessage=“the White LED is blinking”; //Declaing a String variable
void setup() {
Serial.begin(115200); //serial port on code
pinMode(redLEDPin, OUTPUT); //tell arduino that redLEDPin is an output pin
pinMode(whiteLEDPin, OUTPUT); //tell arduino that whiteLEDPin is an output pin
Serial.println("how many times do you want to blink the RED LED "); //promt user for input for the amoutn of blinks
while (Serial.available()==0){
} //wait for input
numRedBlink = Serial.parseInt( ); //Read user input
Serial.println("how many times do you want to blink the WHITE LED "); //promt user input
while (Serial.available()==0){
} //wait for input
numWhiteBlink = Serial.parseInt( ); //read user input
}
void loop() {
Serial.println(redMessage); //start point of the print line for red LED
for (int j=0; j<=numRedBlink; j=j+1 ) { //start for the loop
Serial.print(" you are on blink #: "); //indicating the blink
Serial.println(j); //what part do you want to see in the serial port
digitalWrite(redLEDPin, HIGH); //Turn the red LED on
delay(redOnTime); //red LED on delay timer
digitalWrite(redLEDPin, LOW); //turn the red LED off
delay(redOffTime); //red LED off delay timer
}
Serial.println(" “);
Serial.println(WhiteMessage); //start point of the print line for white LED
for (int j=0; j<=numWhiteBlink; j=j+1 ) { //start for the loop
Serial.print(” you are on blink #: "); //indictaing the blink
Serial.println(j); //what part do you want to see in the serial
digitalWrite(whiteLEDPin, HIGH); //turn the white LED on
delay(whiteOnTime); //white LED on delay timer
digitalWrite(whiteLEDPin, LOW); //turn the white LED off
delay(whiteOffTime); //white LED off delay timer
}
Serial.println(" ");
}