beautypg.com

Remote Processing CAMBASIC User Manual

Page 199

background image

Event Multitasking - 10

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

Inputting Multi– digit Numbers
T h e ba s ic e xa m p le s pr i nt ou t t he k ey th a t w a s p r e ss e d. T h e fo ll ow i ng e xa m p le is a va r ia t io n of th e ba s ic 1 6– k e y d e m o
that inputs a multi– digit number.

10 'Input a multi–digit number
30 ON KEYPAD$ GOSUB ..Key_interrupt
35 PRINT R
40 DELAY .25
45 GOTO 35
50 ..Key_interrupt
55 B$=KEYPAD$(0)
60 IF B$=CHR$(13) THEN ..Get_value
65 IF B$="*" THEN B$="."
70 A$=A$+B$
75 RETURN
80 ..Get_value
85 R=VAL(A$)
90 A$=""
95 RETURN

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

Line 35 prints the number that the input string will be converted to. Initially, it will be zero.

Line 40 is a 0. 25 second delay for de monstration pur poses.

Line 45 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 55 assigns the input to B$.

Line 60 tests to see if this is the term inator key for the inpu t.

Line 65 tests to see if the input is an a sterisk. If so, it converts it to a d ecimal po int.

Line 70 adds the new value to the string.

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

Line 85 converts the assembled string into a number.

Line 90 clear the assembled string to a null string.

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

Fast Branching on Keys

Sometimes the input data is in the form of symbols. That is, rather than numbers and letters, the keypads legends might be
direction arrows or w ords like “Load” and “Stop” .