Showing posts with label Tutorial. Show all posts
Showing posts with label Tutorial. Show all posts

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!

Friday, October 23, 2026

Exploring Hello World! - Once Learning Activity || TinkerCAD Circuits Simulator - 02

 


 


 

Hello World! Once TinkerCAD Circuits Simulation Link

 <Code>

void setup() {
// put your setup code here, to run once:
Serial.begin(9600);
Serial.println(
"Hello World!");
}
void loop() {
// put your main code here, to run repeatedly:
}

 



Here two code lines are added to setup() function, first one sets communication speed between Arduino Uno board and Host computer [baud rate:9600]; second line prints ‘Hello World!’ text on a new line.

To see the text line once again, you have to reset the Arduino Uno board [press the Stop & then Start Simulation]. So it is evident that the setup() function is used to set up the board or system and runs only once on every reset.



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

Thursday, October 22, 2026

Exploring Bare Minimum Learning Activity || TinkerCAD Circuits Simulator - 01

 



Bare Minimum TinkerCAD Circuits Simulation Link

 

The Arduino Uno R3 board is loaded with the default ‘L’ LED blink program, so when simulation starts 1st Arduino Uno R3 board’s ‘L’ LED starts blinking.

 

<Code>

// C++ code
//
void setup()
{
  pinMode(LED_BUILTIN, OUTPUT);
}

void loop()
{
  digitalWrite(LED_BUILTIN, HIGH);
  delay(1000);
// Wait for 1000 millisecond(s)
  digitalWrite(LED_BUILTIN, LOW);
  delay(1000);
// Wait for 1000 millisecond(s)
}

 

Whereas the 2nd Arduino Uno R3 board’s ‘L’ LED does not blink, because it is loaded with Bare Minimum code which does nothing & no tasks are added here.

 

Both Arduino boards Green Power LED glows when simulation is started, to indicate both are powered.

 

<Code>

void setup() {
// put your setup code here, to run once:
}
void loop() {
// put your main code here, to run repeatedly:
}

 



As seen in the above flow chart, both setup() and loop() functions are blank or have no tasks so no output will be produced.

Even though the above code performs no function, it is useful for clearing out any old program.


 


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

Sunday, October 23, 2022

Notes on C++ with OOP eBook related articles list

 This index page contains list of “OOPs with C++” articles related with my free eBook Notes on C++ with OOP:

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

…till next post, bye-bye & take care

Wednesday, June 9, 2021

Avoiding mistakes

What are mistakes?

The computers don't make mistakes, but user can tell the computer what to do and cause mistakes!

Hence it is very important to learn how to make computer avoid mistakes.

Because the mistakes turn out into big blunder

  • as in banking process balance will be made  nil within second
  • as in medical instrument wrong reading makes wrong diagnosis and leads to severe problem for the patient
  • as in design software the building may collapse due to mistake in building design

The mistakes or bugs can cause a program to show unexpected results or sometimes make the computer to stop working!

Hey Computer:

Create my_number

Remember 10 as my_number

Repeat until my_number is less than 9

Add 1 to my_number

Display my_number

 

Output:

     Not responding…

The above sequence is not responding or hangs out as my_number will never be less than 9 and the program never display the output (and get into an infinite loop).

What is debugging?

The debugging is simply means finding and correcting the bugs. It is an important part of programming.

For example the following sequence is having bug:

Hey Computer:

Remember “Dog” as my_pet

Add “Cat” to my_pet

Display my pet

 

Output:

     ----No output----

The bug is in last instruction:

 Display my pet

There is no underscore between two words. Such mistakes are called syntax errors. Note that this type of errors is easily found out by just reading the instructions carefully. The process of reading instructions is called debugging.

Logic bug

When you press space bar, the text moves to the next line, it is called as logical bug.

Sometimes, programs have logic bug so the program doesn't crash but doesn't give the desired result.

For example observe the below sequence

Hey Computer:

Create my_age

Remember 30 as my_age

IF my_age is about 35

Display “Your offer 35%!”

IF my_age is below 25

Display “Your offer 25%!”

     Output:

          ---unpredictable---

Here no check for age between 25 and 35 is done. So it is hard to find the logic bugs like this. Finding the logic bugs is also called as a debugging.

While writing the sequence, there should be a condition to check for all scenarios.

Avoiding bug

When programs become longer and complex their instructions become harder to read.

How can we avoid mistakes and understand it better? The solution is to providing comments to understand the code better.

In other words comments and meaningful variable and function names make the code easier to debug and understand.

The programmer should carry a series of tests before releasing a program as there might be critical bugs in it.

 

Summary

The mistakes in programs are called as bugs.

 The debug is the process of finding bugs in a program.

The bugs are usually logic or syntax based one.

The bugs can be avoided by commenting, using proper names and testing the program.

 

PS: I have composed this post-series based on my pdf eBook on playstore:

Basics of Computer, Programming and C

The series is posted continuously one each next day, and reader can found any post by referring blogs’ time line tab.

--till next post, bye-bye and take care.