Page 179 - ARM Based Microcontroller Projects Using MBED
P. 179
8.9 PROJECT 6—VOLUME OF A CYLINDER 165
8.9 PROJECT 6—VOLUME OF A CYLINDER
8.9.1 Description
In this project, the volume of a cylinder is calculated and displayed on the PC screen. The
user enters the radius and height of the cylinder.
8.9.2 Aim
The aim of this project is to show how the various serial communication functions and con-
trol codes can be used in a program.
8.9.3 The PDL
The PDL of the program is very simple and is given in Fig. 8.25.
8.9.4 Program Listing
Fig. 8.26 shows the program listing (program: Cylinder). At the beginning of the program,
variables radius, height, and volume are defined as float and Pi has been initialized to
3.14159. The program then clears the screen, homes the cursor, and displays the heading Vol-
ume of a Cylinder. The radius and height of the cylinder are then read from the keyboard and
2
the volume is calculated as Volume5πr h and is displayed on the screen. Notice that
carriage-return and line-feed characters are sent to the screen before accepting an input from
the keyboard so that the messages are displayed on new lines. Also, the user inputs are not
echoed on the screen. This is because the local echo is disabled by default on Putty. We can
enable the local echo by clicking Terminal and then click Force on in Local echo: as shown
in Fig. 8.27.
8.9.5 Suggestions for Additional Work
Modify the program in Fig. 8.26 so that the program displays both the area and the volume
of a cylinder.
BEGIN
Clear the screen and home the cursor
Enter the radius
Enter the height
Calculate the volume
Display the volume
END
FIG. 8.25 Program PDL.