School Assignment? Project Due Tomorrow? Chat LIVE With A Programming Expert!

Welcome to Dream.In.Code
Become an Expert!

Join 307,136 Programmers for FREE! Get instant access to thousands of experts, tutorials, code snippets, and more! There are 1,900 people online right now. Registration is fast and FREE... Join Now!




Responding to key presses (TI-Basic; 83/84)

 
Reply to this topicStart new topic

> Responding to key presses (TI-Basic; 83/84)

Gorian
Group Icon



post 26 May, 2009 - 11:16 PM
Post #1


This program will demonstrate how to use key presses in TI-Basic(83,84)
First the program:

CODE

PROGRAM: CURSOR

:0→C
:0→G
:8→X
:4→Y
:Input  (“YOUR CURSOR: “,Str0)
:While not(C)
:ClrHome
:getKey→G
:Output(Y,X,Str0)
:X+(G=26)-(G=24) →X
:Y+(G=34)-(G=25) →Y
:If G=45
:Goto Z9
:If X≤0
:1→X
:If X≥17
:16→X
:If Y≤0
:1→Y
:If Y≥9
:8→Y
:END
:Lbl Z9
:ClrHome
:Output(1,1,”


So, to break it down.

CODE

:0→C
:0→G
:8→X
:4→Y


Sets C and G variables to 0.
Sets X and Y to 8 and 4 respectively.
This will put the cursor in the middle of the Home screen when you start.
C is used to keep the while loop running.
G is where we will store the keypress.
X and Y are Horizontal and Vertical position, respectively.

CODE

:Input  (“YOUR CURSOR: “,Str0)


Lets you choose any character to use as a cursor.

CODE

:While not(C)


Loops the program until the user ends it.

CODE

:ClrHome


Refreshes the screen every time the program loops

CODE

:getKey→G


If a key is pressed, it stores the number of the key into the variable G

CODE

:Output(Y,X,Str0)


outputs the position of the cursor (Str0) to the coordinates Y, and X Respectively. This changes every time the program loops.

CODE

:X+(G=26)-(G=24) →X


The key number for left is 24 and the key number for right is 26.
This line says “take X +(1 or 0 :evaluate if the right key is pressed or not and return a value of 1 if yes or zero if no) - (1 or 0 :evaluate if the right key is pressed or not and return a value of 1 if yes or zero if no)”

Example:

If the right key is pressed:
X+(1)-0→X //moving 1 forward on the x axis

If the left key is pressed:
X+(0)-(1) →X //moving 1 backward on the x axis


CODE

:Y+(G=34)-(G=25) →Y



The key number for up is 34 and the key number for down is 25.
This line says “take X +(1 or 0 :evaluate if the up key is pressed or not and return a value of 1 if yes or zero if no) - (1 or 0 :evaluate if the down key is pressed or not and return a value of 1 if yes or zero if no)”

Example:

If the right key is pressed:
X+(1)-0→X //moving 1 forward on the y axis

If the left key is pressed:
X+(0)-(1) →X //moving 1 backward on the y axis

CODE

:If G=45
:Goto Z9


45 is the clear button. This goes to label Z9 if the clear button is pressed, exiting the program

CODE

:If X≤0
:1→X
:If X≥17
:16→X
:If Y≤0
:1→Y
:If Y≥9
:8→Y


The edges of the home screen is 0 to 16 on the x axis, and 0 to 8 on the y axis.
This series of if statements says that if the cursor goes over the edge of the screen, put it back at the edge.

CODE

:END


Ends the while loop instance

CODE

:Lbl Z9
:ClrHome
:Output(1,1,”


If the clear key is pressed, the program goes to label Z9, and clears the home screen.
Output(1,1,” stops Done from being displayed when the program is done running.




Go to the top of the page
+Quote Post


Register to Make This Ad Go Away!

drjoe51
**



post 15 Jun, 2009 - 07:23 PM
Post #2
wow! TI-BASIC, haven't used that since high school.
Go to the top of the page
+Quote Post

Gorian
Group Icon



post 3 Nov, 2009 - 10:30 AM
Post #3
Yeah, it has been a while. I had some days bored in class...
Go to the top of the page
+Quote Post


Fast ReplyReply to this topicStart new topic
1 User(s) are reading this topic (1 Guests and 0 Anonymous Users)
0 Members:

 


Lo-Fi Version Time is now: 11/21/09 03:01PM

Live Help!

Be Social

Dream.In.Code RSS Feed Dream.In.Code LinkedIn Group Follow Us On Twitter Fan Us On Facebook

Tutorials

Programming

Web Development

Reference Sheets

Code Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month