Using an arduino uno, give the documented code that will display \'Two Hours\' o
ID: 3693235 • Letter: U
Question
Using an arduino uno, give the documented code that will display 'Two Hours' on the serial port but only after an ASCII 2 is typed into the serial port. Below I have the following... It works for numbers including and above 2, any suggetions of how to fix this? Thank You
int char; // setting integer for received input
void setup() {
Serial.println();
Serial.begin(9600); // start serial monitor
}
void loop() {
if (Serial.available() == 2) { // read incoming
Serial.print("Two Hours"); // Display "Two Hours"
char = Serial.read(); // read next
}
}
Explanation / Answer
Just swap the instructions, Serial.print(), and Serial.rea() inside the loop. That will do the needful. So, the code for loop should look like this:
void loop() {
if (Serial.available() == 2) { // read incoming
char = Serial.read(); // read next
Serial.print("Two Hours"); // Display "Two Hours"
}
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.