UCS: The Ultimate Computer Source
A Thinkquest 1999 Entry

Front | Teach | Thinkquest | About UCS

[ History - How? - Internet - Programming - Glossary - Issues - Operating Systems ]

Click here for graphical version

TI-Basic Tutorial

  • Preface
  • Writing to the Screen
  • Variables
  • Getting Input
  • Labels, Goto
  • Menu
  • If,Then,Else,For,While,Repeat
  • Networking


    TI-Basic Tutorial - Preface

    This Tutorial is going to cover the TI-Basic programming language. TI-Basic has little to do with Basic, QBasic, or Visual Basic, except that it is very easy to learn and simple to use.

    The particular TI-Basic that will be concentrated on here is the TI-83 TI-Basic. If you have any other TI (81, 82,  85) then this tutorial is still for you, but there may be subtle differences that you'll have to work out.

    The TI (Texas Instruments) line of programmable graphing calculators are special because they are one of the smallest and most compact line of calculation devices that can do the simplest of things (equations like 1+1), yet have simple yet wonderful programming capabilities to allow for games, science, or math programs in. TI-83 (and the other calculators up to a certain version) is also allowed on the P/SAT's, which is one of the most useful things to have.

    If you don't have a TI calculator, they run for about 85-100 dollars. If you want to program on it by using it's built in key system, feel free and you'll learn more on that later, but if you
    want to make programming a lot easier get a PC-Link cable, that will allow you to program on your computer (typing on TI calculators is sort of a tedious process) and then transfer programs onto your calculator.

    This tutorial must assume that you have at least a basic (pun?:) knowledge of TI-calculators. Like how to type a letter using alpha, alpha lock, use the catalog, etc. For instance, you
    cannot type in keywords with letter keys. You must select them from a menu (Catalog, or the Math/Test, PRGM/Draw, etc.) Consult the calculator manual for basic operation instructions.

    < means left, > means right. Calculator buttons are indicated
    like [THIS].

    Now for a brief explanation of how to program. To start a new program, type: [PRGM] > > [ENTER] and type a name in. You will then be entered into the programming environment. After you type
    code in, exit out of the programming editor (I just turn the calculator off, and then on again).

    TI-Basic Tutorial - Chapter 1
    The Screen, And Writing To It

    The calculator's screen is small. On the 83, the screen is precisely 8 rows by 16 columns. We'll ignore pixel dimensions for now.

    The small size of the screen means that you really have to watch any text that you put on the screen. If you make it too long, text can get cut off from the screen, and TI-Basic does not wrap long text by default. So you have to keep in mind formatting text for the screen when you write programs.

    To clear the screen, use ClrHome

    There are two main commands for printing text to the screen

    Disp displays text on the next available line, and will scroll the text down however many lines if the text goes past the first screen.

    Output( allows you to print text like Disp, but you can set the exact row and column to start from.

    Disp "HELLO"

    Output(1,1,"HELLO")

    In Output(, for the #,# (1,1 in the example) the first # is the row, the second # is the column.

    In either of them you can put in a variable.

    Disp I
    Disp "MY NAME IS ",I,"."

    Or

    Output(1,1,A)
    Output(1,1,"MY NAME IS ",A,".")

    You'll learn what the variables are in the next chapter. Jump back here after you read Chapter 2.

    If you want to put more than one line in the same Disp statement, Just seperate "strings" with commas (,)

    Example:

    Disp "THIS IS LINE 1","AND THIS IS LINE 2!"

    Disp with no string and just a single " will print out an empty line.

    Disp "

    There is one more text command, but it uses a different display type. text() functions similarly to output() except for three things. For one, it does not display on the standard screen. Instead, it displays text to the graph screen. The graph screen is different from the normal output screen. To clear the graph screen, you must use ClrDraw in the [DRAW] menu. On the graph screen, by default, Axis lines are shown. This could be distracting for some programs. So, Axis lines can be turned off using AxesOff and turned on with AxesOn. The second special thing about text() is that it uses pixel plotting instead of character rows/columns. The dimensions are roughly 55x90. The final thing to know about text() is that it displays a smaller font than disp or output().

    TI-Basic Tutorial - Chapter 2
    Variables

    Variables are letters that store values.
    To store a value into a variable:

    value->variable
    (-> = the STO-> key)

    i.e.

    4->F

    There can only be 28 possible variables. This is definately limiting, but considering the maximum power of any TI-Basic program, it should be enough. The variables can be A-Z, and the 0 symbol.

    And variables support math, exactly like the regular calculator functions.

    any_math_equation->V

    (the equations answer would be stored in the variable)

    i.e.

    (1+3)*(1+1)/2->V

    And V would equal 4.

    You can also add variables, multiply them, etc.

    To store text into a variable

    "Text here"->J

    Would store "Text here" into the variable J.

    TI-Basic Tutorial - Chapter 3
    Getting Input

    TI-Basic has a few good ways of getting input
    getkey -
    reads a key
    input -
    displays a prompt and stores input into a variable

    getkey works by storing the key that is gotten into a variable.

    getkey->V

    would store the next key inputted into the variable V.

    Input makes a prompt that stores whatever is entered into a variable

    To make a prompt without a question (the prompt will consist of a ? only):

    Input VARIABLE

    To make a prompt with a question

    Input "WHAT IS YOUR NAME?" N

    This would make a prompt like this:
    WHAT IS YOUR NAME?
    And whatever entered would be stored in the variable N

    A very simple prompt is usually used to be used for things like (Hit a key to continue). It is pause. Pause freezes the program until a key is hit, and then moves on.

    Just use pause by itself.

    Pause

    Pause can be combined with some other commands to make multiple
    pages of text.

    Here's an example program

    ClrHome
    Disp "WELCOME TO MY"
    Disp" PROGRAM.          "
    Disp "HIT ANY KEY TO   "
    Disp "CONTINUE."
    Pause
    Disp "THANK YOU!"
    Disp "HIT ANY KEY TO  "
    Disp "EXIT"
    Pause

    TI-Basic Tutorial - Chapter 4
    Labels, Goto

    Labels are used for the Goto command to enable the programmer (you) to  jump to portions of the program.

    To set a label, use the Lbl command

    Lbl (label name)

    And then put Goto (label name) anywhere you want to jump to the coding position after the Lbl.

    The label name can be 0-9, A-Z, and a few symbols.

    i.e.

    Lbl H
    Lbl 7
    Lbl 4

    TI-Basic Tutorial - Chapter 5
    Menus

    Menu is a feature of TI-Basic that is (to my knowledge) not in any other programming language that I know of. It provides a nice,organized way of asking a user to choose from an option. Menus are used in conjunction with labels.

    Here is an example menu. There will be an explanation after it.

    Menu("MENU TITLE","CHOICE1",A,"CHOICE2",B)

    This would make a menu like this:

    MENU TITLE
    1: CHOICE1
    2: CHOICE2

    If the user selected choice1, it would perform (what would be the equivalent of) Goto A. If the user selected choice 2, it would perform (would be the equivalent of) Goto B. If you can recall labels in the last chapter, a menu requires a label for each entries' label (in this example, it's A and B) names.

    TI-Basic Tutorial - Chapter 6
    If, Then, Else, For, While, Repeat

    If/For/While statements control the intelligence of the program. What IF the monster is dead. What IF the number is too big. WHILE you have 2 hit points, you're alive, FOR the number of coins, add 2 points.

    If statements:

    If statement            (is true)
    Then
    (any code here)
    End

    Explanation:

    The statement after If involves a variable. It must be something like, If H = 4    If J < 100   If K > P   are examples of possible statements. You may use not( to test if a statement is false instead of true, and you can also use And to test multiple statements . Condition supplements life And, Not(, and operators like < > = are available in the [Math] menu.

    If H > 4 and not(H <4)
    Then
    Disp "H MUST BE 4!"
    End

    End is used to stop the Then statement, which contains the "actions" of the If statement if the conditions are met. If there is no "Then" statement, do not use an End. The only time when you do not need to use a "Then" statement is if the actions of the statement (what the program does if the if statement is true) is onle one line (one statement) like:

    If I < 2 Disp "I IS LESS THAN 2" Disp "THIS IS NOT PART OF", THE IF STATEMENT","ACTION"

    A For loop runs a set of instructions a certain amount of times.

    There are 4 fields in a For loop. Variable, start, end, increment. A variable is any variable you want to use. Start is what value it starts at. Usually 0. End is at what value the variable must be in order for the loop to cease. Increment is how much the variable should be increased every time a loop occurs.

    For(X,0,10,1)
    Disp "LOOP!"
    End

    Anything between the For() and End in the example would be executed 10 times. The variable starts at 0 and ends at 10. The increment is 1. The loop would thus occur 10 times.

    A While loop loops a set of instructions as long as a certain condition is met. Unless the variable in the condition can be modified in the loop to eventually make the condition false (and stop the loop), the loop will continue forever

    5->I
    While I=5
    I = I + 1
    Disp I
    End

    This would show the following:
    1
    2
    3
    4
    5

    Repeat is exactly the same as While only that it runs the set of commands at least once.

    TI-Basic Tutorial - Chapter 7
    Networking

    The term networking for TI-Calculators (at least the TI-83) is used loosely. The only "networking" features a calculator has is the ability to communicate with another calculator, via the linking wire that comes with the calculator.

    First off, TI-83s and TI-82s are not good choices to use when connecting for a multiplayer game or some network program. The 82 and 83 have different protocols in TI-Basic that makes them incompatible to a certain degree. So, if you plan to test this out, use two 83s.

    All that is involved in "networking" two calculators is the ability of TI-Basic to get and send variables.

    The actual framework of the networking program is up to you and would be too much of a hassle to explain now.

    To allow the other calculator to recieve a variable from your calculator, you must first send the variable.

    Send(K

    Now that the variable is in the transfer stream, the other calculator can get it.

    Get(K

    NOTE: You almost always will have to figure out a way to denote which calculator is what "player," because most networking programs use two at least two different string variables,
    one for each person, so it's ideal to assign "player numbers" that can be set in the beginning of the program

    Lbl O
    Print "Player 1 or Player 2?"
    Input P
    If p<1 and P>2
    Goto O


    This concludes the TI-Basic tutorial. For more information on TI calculators, check out Texas Instruments's website available at http://www.ti.com