Tutorial #2: Chase
This is another tutorial designed to help user to familiarize with different function calls of the C version of COMATOS. The goal of this program is to press button of the corresponding LED within a certain amount of time. There are a total of three rounds in this game. Each round is more difficult than the previous round. The rule to the game is that one must be able to press the button as soon as the corresponding LED lights up. In addition, one must be able to get 3 out of 4 hits in order to advance to the next round. The only difference between each round is the allowed time required to press a button. For example, round 2 has less time than round 1 and so on. Once the three rounds are finished, or the user lost failed to hit any of the 4 hits, the OS will display the number of miss hits.
The Program Design:
This program is separated into two tasks, a key press/LED task and a display task. Unlike the keypad scheme implemented in the DMC tutorial, this task does not contain a debounce state machine. This is because the pace of this game moves at a faster rate than pressing the actual buttons. The LED part of the this task is divided into six states. Each state is responsible for a different action. State Start signals the initiation process when the start button (0x40) is pressed. State MeasureWait simply holds the LEDs for a brief moment before lighting up. The bulk of the program lies in State MeasureBlink and State MeasureDetect. MeasureBlink lights different LEDs based in a random fashion while MeasureDetect detects the number of misses corresponding to each LED lighting. The program jumps between these two states until a total of four LEDs have lit up. The display task is very similar to the display task in DMC tutorial. It uses the UART to transmit the messages and outputs on the computer screen.
Questions? Contact Nick Liu