Applications examples – Remote Processing CAMBASIC User Manual

Page 198

Advertising
background image

Event Multitasking - 9

2.

KEYPA D$ function returns either a one– character string that has been assigned to each key or the
numerical position of the key. The two variations are:

A$=KEYPAD$(0)

retur ns a string ch aracter to a string var iable. The assign ment is show n below. A null string is
returned if no key was pressed. This variation is most useful where a single character can be
assigned to match the keypad marking.

A=KEYPAD$(1)

returns the key position number to a numeric variable. A zero is returned if no key was pressed.
For large keypads, the legends often contain some words and sym bols in addition to letters. The
variation is most suited for these cases.

Assigning Character String to Keys

A table in RAM can be pr ogramm ed to return any ASCII value. The table is set up so that the first character is the
upper– left– hand corner and the last character is the lower– right– hand corner.

You can assign a single character string to the keys in the following manner.

10 FOR X=0 TO 15
20 READ A$
30 POKE SYS(8)+X,ASC(A$)
40 NEXT
50 DATA 1,2,3,A,4,5,6,B,7,8,9,C,*,0,#,D

This example matches the KP– 1 Keypad except that the "#" sign is replaced by a carriage return (value= 13).

Applications Examples

Basic 16– Key E xample
The first example is written for the KP– 1 Keypad. No characters were entered into RAM. The CAM BASIC system
defaults to the KP – 1 chara cter set.

10 'Basic 16 Key Demo Program
40 ON KEYPAD$ GOSUB ..Key_interrupt
50 GOTO 50
60 ..Key_interrupt
70 PRINT KEYPAD$(0)
80 RETURN

Line 40 tells CAM BASIC to call a subroutine by the name of “Keypad_interrupt” every time a key
is pressed.

Line 50 is used only as part of this demo program so that the system will wait. You could insert the
r e st of y ou r c on tr o l p r o gr a m .

Line 70 prints the keypad character.

Advertising