KBIN variable KBIN [timeout], variable
KBIN [timeout, address],variable
KBIN [timeout], #variable
KBIN [timeout, address], #variable
Variable - receives the key
Timeout - is a variable/constant which sets the timeout period in milliseconds
Address - is a label which specifies where to go if a timeout occurs.
Wait until a new keyboard press is received.
This command is similar to the keyin command found on older PICAXE parts, but also includes a timeout option.
This command is used to wait for a new key press from a computer keyboard (connected directly to the PICAXE - not the keyboard used whilst programming, see keyled in the manual command for connection details). All processing stops until the new key press is received, but program flow will jump to address after the timeout period. The value of the key press received is placed in the variable.
Note the design of the keyboard means that the value of each key is not logical, each key value must be identified from the table (see keyin command). Some keys use two numbers, the first $E0 is ignored by the PICAXE and so keyvalue will return the second number. Note all the codes are in hex and so should be prefixed with $ whilst programming. The PAUSE and PRNT SCRN keys cannot be used reliably as they have a special long multi-digit code. Also note that some keys may not work correctly when the 'Nums Lock' LED is set on with the keyled command.
To overcome some of these issues the #variable option has been added to M2 parts. In this case the ASCII character of the keyboard letter is loaded into the variable. Unsupported characters like 'Ctrl' will get an ASCII "?" returned. For older parts the sample file 'keyin.bas' (installed in the \samples folder) provides details on how you can convert the key presses into ASCII characters by means of a look up table.
Effect of Increased Clock Speed
This command will automatically use the internal 4MHz resonator for correct operation.
Please note the 'kbin' command is only supported for 18M2 firmware D.x (PICAXE chips labelled 18M2+) and is not available for use with 18M2 firmware 2.x (PICAXE chips labelled 18M2).
The PICAXE compiler will syntax check code for an 18M2 as correct when using the 'kbin' command but will generate an error when an attempt is made to download into an 18M2 with firmware 2.x.