|
The MOVEMENT Program |
You already know how to use text to interact with the user. Now, we will use the highest form of interaction - the Getkey command. The Getkey command is followed immediately by the Store ( -> ) command and then a variable. This command waits for a user to press a button on the keypad, and then stores the numeric value for that key into a variable. The program we are about to write will use the Getkey command to return a numeric value, which will move a "cursor" on the screen.
:ClrHome :5->A :5->B :While 10 :getKey->C :If C=24 :Then :ClrHome :B-1->B :Else :If C=26 :Then :ClrHome :B+1->B :Else :If C=25 :Then :ClrHome :A-1->A :Else :If C=34 :Then :ClrHome :A+1->A :Else :If C=21 :Then :ClrHome :Stop :End :End :End :End :End :Output(A,B,"*") :End
Execute the program. Note that when you press the arrow buttons on the keypad (located in the upper right-hand corner), the asterisk moves. The variables stand for the following: A=X axis, B=Y axis, C=Getkey values. The ClrHomes found throughout the code of this program clear the screen after every movement so that you do not see multiple asterisks on the screen. The Else statement leads the program from one If statement to the next. Thus providing for the multiple Ends at the end of the program. This program also uses the While statement. This statement creates a loop in the code; it is the equivalent form of the Lbl...Goto...Lbl loop. We have not worked with this statement previously, but it is extremely helpful in this type of program. Using this program as a basis, one can create interactive, graphical programs.

Above is a copy of the TI83 keypad values.
|
|
|