Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

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"

    }

}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote