Lesson 4


Here are another five useful codewords.

INPUT Sometimes your program might ask you to put a number into the computer while the program is running. For example, the two lines:

60 PRINT "How old are you?"
70 INPUT age

would tell the computer to ask how old you are and then wait until you have entered your age on the keyboard.

INKEY$ If the user presses a key on the keyboard the computer usually needs to know about it. You can tell the computer which key has been pressed on the keyboard by using this codeword.

FLASH You can create a flashing effect so that the ink and paper colours flash on and off. With this effect, when the ink colour is on the paper colour is off, and when the paper colour is on the ink colour is off.

BEEP Sometimes you will want the computer to make a beeping sound. The BEEP codeword allows you to tell the computer what pitch this sound should be – a high beep, or a low beep, or somewhere between. The BEEP codeword also allows you to tell the computer how long the beeping sound should last.

INVERSE This codeword swaps around the colours at certain places on the screen, so that the ink becomes the colour of the paper and the paper becomes the colour of the ink.


The INPUT codeword

The INPUT codeword is a statement/command.

The INPUT codeword tells the computer to expect to be given some data which the computer’s user will put into it from the keyboard while the program is running. (You can see that the name of this codeword, INPUT, comes from “put in”.) That data might be a number, or it might be a name, or it could be anything else typed into the computer on its keyboard.

How to use the INPUT codeword

The simplest way to use the INPUT codeword is to follow it by a variable.

Here is an example:

60 INPUT bananas

If bananas is a variable, then when the program reaches line 60 it is told to wait until a number is entered on the keyboard.

The value of the variable bananas is the number keyed in. This value is displayed at the beginning of the bottom line of the screen as it is keyed in. When the user has keyed in the number and pressed the ENTER key, the value keyed in is assigned to (in other words it is given to) the variable bananas, and the program continues.

If you want your program to ask the user to enter a number you could do so like this:

70 PRINT "How many bananas do you have?"
71 INPUT bananas

These two lines of the program tell the computer to display the message  How many bananas do you have? And then to wait for the user to type in a number. When the user has typed the number and pressed ENTER the computer will assign that number to be the value of the variable bananas.

The INKEY$ codeword

The INKEY$ codeword is a function.

INKEY$ means INput KEY string. It is used to tell the computer when a key has been pressed on the keyboard.

How to use the INKEY$ codeword.

Here is an example of how to use INKEY$

70 LET a$=INKEY$

Here, if a key has been pressed, then the computer would assign the character on that key to the variable “a”. But if no key is being pressed then INKEY$ would assign an empty string to variable a (“”).

The FLASH codeword

The FLASH codeword is a statement/command.

You can use the FLASH codeword to make character positions flash, which means making the ink and paper colours change back and forth.

How to use the FLASH codeword

When you use the FLASH codeword you must put a number after it. This number may be 0, 1 or 8.

FLASH 1 tells the computer that, until further notice, all characters displayed by the PRINT codeword should remain flashing, and the paper behind the character is also displayed flashing.

FLASH 8 tells the computer that the flashing that is already on the screen should not be changed, but the letters that you are PRINTing will be drawn as you wanted them – and they will flash if any parts of the screen under them are already flashing.

FLASH 0 tells the computer to cancel the most recent FLASH 1 or FLASH 8 instruction so that all characters subsequently displayed are normal.

Using the FLASH codeword with other display codewords

You can use the FLASH codeword following one of the display codewords to affect the flashing of what you are telling the computer to display. You do this by putting a semicolon (;) after the number 1,8 or 0 which follows the FLASH codeword, but before the data that you want to display. For example:


Here line 60 means that the word “WARNING” should be displayed and that it should appear flashing, if there are already flashing letters underneath it.

Next is another example – a little more complicated but you should be able to understand it:


This line of the program tells the computer that the word “WARNING” should be displayed, using INK 2 (red), PAPER 6 (yellow), and that the word should remain flashing and the paper behind it should also be flashing.

The BEEP codeword

The BEEP codeword is a statement/command.

BEEP makes the computer’s loudspeaker produce a single note. You tell the computer how long the note should last and what pitch it should be.

How to use the BEEP codeword

When you use BEEP you must follow it with two numbers separated by a comma. For example:

80 BEEP x, y

The first value (x) may range from 0 to 10. It tells the computer how many seconds the beep should last.

The second value (y) may range from -60 to +69. It tells the computer what pitch the note should be. If you know something about music, it might help you to know that if y is negative it is the number of semitones below middle C, and if y is positive it is the number of semitones above middle C.

The INVERSE codeword

The INVERSE codeword is a statement/command.

The INVERSE codeword causes colours to be swapped at character positions so that the ink becomes the paper and vice-versa.

How to use the INVERSE codeword

INVERSE is very simple to use.

The program line:


swaps the ink colour with the paper colour as described above.

And the program line:


swaps them back again.


Example Program

This programs asks for your name, displays a hello message and plays a tune. Line 600 to 660 asks for the name and displays the hello message. Line 670 to 720 plays a rising and falling note.

 600 PAPER 7: INK 0
 605 REM Set the ink and paper colours
 615 REM Turn off flash and inverse
 620 CLS
 625 REM Clear the screen
 630 PRINT "Please enter your name"
 635 REM Display a message asking for the users name
 640 INPUT n$
 645 REM read the name
 650 CLS
 655 REM Remove the message
 660 PRINT "Hello ";: INVERSE 1: PRINT n$: INVERSE 0
 665 REM Display Hello with the name in inverse
 670 FOR b=0 TO 8
 675 REM Count from 0 to 8
 680 BEEP .25,b
 685 REM and play a a rising note
 690 NEXT b
 695 REM Play all the notes
 700 FOR b=8 TO 0 STEP -1
 705 REM Now count down
 710 BEEP .25,b
 715 REM Play a falling note
 720 NEXT b
 725 REM Play all the notes