Remote Processing CAMBASIC User Manual

Page 200

Advertising
background image

Event Multitasking - 11

Intercepting these keys in the form of strings provides a slower response than using the key positions. The following
program does an instant branch to one of 16 routines, based on the position number.

10 'Branch on the Key Position
40 ON KEYPAD$ GOSUB ..Key_interrupt
50 GOTO 50
60 ..Key_interrupt
70 K=KEYPAD$(1)
80 ON K GOTO 100,200,300,400 ......,1600
90 RETURN
.
.
100 ..service key position 1
.
150 RETURN
.
200 'service key position 2
.
250 RETURN

and so forth.

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 assigns the input position to variable K.

Line 90 returns progr am execution to the place that was executing before the key was pressed.
However , the progr am should never get to this point if 16 line numbers are specified.

Line 100 would be the routine to handle the operation desired by pressing key 1.

Line 150 returns progr am execution to the place that it was executing before the key was pressed.

Line 200 would be the routine to handle the operation desired by pressing key 1.

Line 250 returns progr am execution to the place that it was executing before the key was pressed.

Using INPUT KEYPAD$

The previous examples have shown how to use a keypad on an interrupt basis. In some applications it is acceptable for the
program to wait for operator input. INPUT KEYPAD $ will accept data in the same manner as the INPUT statement does
from a serial por t.

The following example is for the KP– 1 keypad. It uses the default assignment of a carriage return (13) for the "#" key.
This is necessary, as a string input must be terminated with the carriage r eturn.

30 INPUT KEYPAD$ 1,A$
40 PRINT A$

Line 30 is the input stateme nt. T he para meter “1” tells the system to echo the key pad char acters to

Advertising