Page 197 - ARM Based Microcontroller Projects Using MBED
P. 197

8.16  PROJECT 13—HI-LO GAME                    183
                      while(1)                                    // Do forever
                      {

                          while(button == 1);                     // If button is pressed
                          Count++;                                // Increment Count
                          while(button == 0);                     // Wait until released

                          gotoscr('4', '0');                      // Go to line 4, col 0
                          MyPC.printf("Count = ");                // Display Count =
                          MyPC.printf("%d", Count);               // Display total Count
                      }
                  }

            FIG. 8.44,  CONT’D












            FIG. 8.45  Typical output from the program.

               BEGIN
                      Initialize USB  Serial
                      DO FOREVER
                             Initialize Attempt count
                             Display heading
                             Generate a secret random number
                             DO FOREVER
                                     Read user’s guess
                                     Increment Attempt count
                                     IF guessed number > secret number THEN
                                            Display You are HIGH
                                     ELSE IF guessed number < secret number THEN
                                            Display You are LOW
                                     ELSE
                                            Display Success
                                            Display Attempt count
                                     ENDIF
                             ENDDO
                      ENDDO
               END
            FIG. 8.46  Program PDL.
   192   193   194   195   196   197   198   199   200   201   202