Question
C++ 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;
C++
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 numRedBlinks;
int numYellowBlinks=5;
void setup() {
// put your setup code here, to run once:
Serial.begin(9600);
pinMode(redLEDPin, OUTPUT); // Tell Arduino that redLEDPin is an output pin
pinMode(yellowLEDPin, OUTPUT); //Tell Arduino that yellowLEDPin is an output pin
}
void loop() {
// put your main code here, to run repeatedly:
Serial.println("How Many Times Do You Want the Red LED to blink?"); //Prompt User for Input
while(Serial.available()==0) { // Wait for User to Input Data
}
numRedBlinks=Serial.parseInt(); //Read the data the user has input
Serial.println("The Red LED is Blinking");
for (int j=1; j
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("The Yellow LED is Blinking");
for (int j=1; j
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
}
}
When running the provided code above it asks "How Many Times Do You Want the Red LED to blink?" if I type "2" the red link will blink "2 times" and the yellow "5". Now, what I need help with is to modify the code to get the output below:
For example, when running it has to ask for the first digit and if I type "2" it will blink 2 times, and then it will ask for the second digit and if I type "3" it will blink 3 times and continuing the loop. Please, help.
In the Serial Monitor, the user should see the question. What is the first digit of your age? Then the Serial Monitor waits the user to enter one number. Let's use m to refer to this number. After that, the user should see the question. What is the second digit of your age? Then the Serial Monitor waits the user to enter one number. Let's use n to refer to this number. After the numbers are entered. The red LED should blink m times and the yellow LED should blink n times. The serial monitor should produce something like the following. (o0) COM8 (Arduino/Genuino Uno) What is the first digit of your age? What is the second digit of your age? The Red LED is Blinking 1 2 3 The Yellow LED is Blinking 1 What is the first digit of your ageStep by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started