TI-Basic Z80 Programming/Hello, World!
To begin coding TI-BASIC on your calculator, you must use the program editor. This allows you to edit, manage, and run your programs. To access it, pressNEW . Then, type in a short name for your program. The names for programs must follow these rules:
- Must include only uppercase letters and numbers, where the first character must be a letter
- Cannot include any other tokens, such as symbols or math functions
- Maximum length of 8 tokens long
To navigate the program editor, use the arrow keys to move the cursor, which is represented by a blinking black box. Pressto move the cursor down a line, or to create a new line if the cursor is at the bottom-most line. To insert a line at any point, move the cursor to the end of the line above where the new line should be inserted. Then press [INS] . To clear a line, press . Press on any empty line to delete it.
Always, the first line (
PROGRAM:EXAMPLE) on the screen shows the name of the program. It is not a line in the code, but rather a header to show the name of the current program. Press . Now, a new line on the program editor is created:
PROGRAM:EXAMPLE : :
In TI-Basic, colons (
:) are used to signify new lines.
- Colons are automatically placed by the calculator when creating a new line. These colons cannot be deleted, except by deleting the line itself.
- Manually adding a colon ( [:]) also signifies a new line. These colons can be deleted.
To run a program, you need to first exit the program editor. Press[QUIT] to return to the home screen. Press and use the up and down arrows to select your program. Now, press twice: once to paste it to the home screen and second to execute it.
To stop a program during execution, press thekey and an error will be thrown, stopping the program.
Now that you have learned how to navigate and perform simple edits on a program, now we will program our first program: the "hello world." This simple program tells the calculator to display the text
HELLO, WORLD! on the screen.
PROGRAM:HLLOWRLD :ClrHome :Disp "HELLO, WORLD!"
Now, let's break down each line of this program and understand how it works.
Every new line in a TI-BASIC program automatically starts with a colon. It's how the calculator knows when a line ends and a new line begins. ClrHome ( I/O 8) is the instruction that clears the home screen, erasing any text or numbers that may have been on it.
:Disp "HELLO, WORLD!"
Disp ( I/O 3) displays a variable, value, or string to the screen. If the screen is full, it will scroll down a line. If the string is more than 16 characters, Disp will only show the first 15 of them, followed by an ellipse (…). During the execution of the program, you will not be able to scroll and see the rest of the line if the 16 character limit is exceeded. Strings are displayed left-aligned, and values are displayed right-aligned.
In order to add quotation marks ("), press.
In this example, the string
HELLO, WORLD! is printed to the screen.
| If you attempt to recreate the above example and get an output of
Another command offered for printing to the screen is the Output ( I/O 6) command. This command offers more arguments to specify where on the screen to print.
- Where row is the vertical positioning of the output. A value of 1 prints on the first row, etc.
- Where column is the horizontal positioning of the output. A value of 1 prints on the first column, etc.
- Where "text" or value is the text or value to be displayed to the screen.
Here's how to use this command in the "hello world" program. It prints
HELLO, WORLD! at row 1 column 1:
PROGRAM:EXAMPLE :ClrHome :Output(1,1,"HELLO, WORLD!")
This program will result in the same output.
|On some old versions of the Operating System on the TI-83+, the calculator may crash if there are many other programs. You should update the operating system, or (preferably) program on the computer and then transfer to the calculator.|
You try it!Edit
Try these examples to practice the Disp and Output commands.
Use the Disp commands to print a simple poem to the screen. Your poem should be 7 or fewer lines to fit on the screen (if you try to print an 8th line, the first line will move off the screen).
:ClrHome :Disp "A POEM BY ME" :Disp "ALL BUT CLASSIC" :Disp "MADE TO YOU" :Disp "FOR TI-BASIC"
This example poem will print to the screen:
A POEM BY ME ALL BUT CLASSIC MADE TO YOU FOR TI-BASIC
Using Output, replicate the following output exactly. You will need to use the command more than once.
WELCOME TO THE TI-BASIC Z80 WIKIBOOK
:ClrHome :Output(1,2,"WELCOME TO THE") :Output(2,3,"TI-BASIC Z80") :Output(3,5,"WIKIBOOK")