Page 195 - ARM Based Microcontroller Projects Using MBED
P. 195
8.16 PROJECT 13—HI-LO GAME 181
BEGIN
Configure BUTTON1 as digital input
Clear the screen and home the cursor
Display heading
Count = 0
DO FOREVER
IF button is pressed THEN
Increment Count
ENDIF
Go to line 4, column 0
Display Count =
Display value of Count
ENDDO
END
FIG. 8.43 Program PDL.
8.15.4 Program Listing
Theprogramlisting(program:SerialEvents)isshowninFig.8.44.Atthebeginningofthepro-
gram,BUTTON1isconfiguredasdigitalinput,thescreeniscleared,cursorishomed,andahead-
ingisdisplayed.Theremainderoftheprogramisexecutedinanendlessloop.Insidethisloop,the
program waits until the button is pressed. When the button is pressed, the value of Count is
incremented by 1. The cursor is positioned at line 4, column 0 of the screen and Count 5 is
displayed starting from this position. The value of Count is then displayed as shown in Fig. 8.45.
8.16 PROJECT 13—HI-LO GAME
8.16.1 Description
This is the popular Hi-Lo game which is played as follows: the computer generates a secret
random number. The user guesses this number by entering a guess number. If the guessed
number is higher than the secret number, then the message You are HIGH is displayed. If on
the other hand the guessed number is lower than the secret number, then the message You are
LOW is displayed. This way the user finally guesses the secret number and the message Suc-
cess is displayed together with the number of attempts made to guess the secret number. In
this project, the generated secret number is between 1 and 100.
8.16.2 Aim
The aim of this project is to show how the various serial communication functions can be
used in a program.
8.16.3 The PDL
Fig. 8.46 shows the program PDL.