Saturday, October 24, 2026

Exploring Serial Port Interactive Program Learning Activity || TinkerCAD Circuits Simulator - 03

 


 

Serial Port Interactive Program TinkerCAD Circuits Simulation Link

 <Code>

void setup()
{
Serial.begin(9600);
Serial.println("Who are you? enter b-boy or g-girl. ");
}
void loop()
{
if (Serial.available() > 0) {
int ans = Serial.read();
if ( ans == 'b')
Serial.println("You are boy.");
else if ( ans == 'g')
Serial.println("You are girl.");
else
Serial.println("Wrong answer.");
Serial.println("Who are you?enter b-boy or g-girl. ");
}
}

 



Here setup() function is used to set baud rate and print questions to the user on serial monitor; loop() function is having a logic part where it is checked whether serial data is available at board end, if yes then read it check it with specific character and print the proper reply. This process is repeated till the reset button is pressed.

 

The code prints questions on the Serial Monitor screen.

Who are you? enter b-boy or g-girl.

 

Type b inside the textbox situated top of serial window and press Send button. The Arduino program checks this response and replies as shown below.

You are boy.
Who are you? enter b-boy
or g-girl.

 

Type g inside the textbox situated top of the serial window and press Send button. The Arduino program checks this response and replies as shown below.

You are girl.
Who are you? enter b-boy
or g-girl.

 

Type c or any other letter inside the textbox situated top of serial window and press Send button. The Arduino program checks this response and replies as shown below.

Wrong answer.
Who are you? enter b-boy
or g-girl.

 


…till the next post, bye-bye & take care!

No comments:

Post a Comment