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.
Keyboard interface connections
KB Data KB Clock 14M2 C.1 C.2 18M2+ C.7 C.6 20M2 C.1 C.2 20X2 C.1 C.2 28X2, 28X1 C.7 C.6 40X2, 40X1 D.7 D.6
Keyboard toggling a LED
When a key is pressed which has keycode value $25 a LED on output B.1 is turned on, and turned off when a key is pressed which has keycode value $45.
Submit Your Own Code!
You must be logged in to submit code examples. Login now.