#!/usr/sbin/blassic '/home/graham/i2c/solar/LCD03_keyboard_get_key_once.bas 'i2c driver for LCD03 display and keypad 'press a key on the keypad - display it and speak its value 'LABEL Again 'Set key_pressed to X so master program wil repeat till good value returned key$ = "X" :SHELL "echo -n "+key$+" >/var/www/ramdisk/key_pressed.txt" 'send the low and high bytes to the ramdisk then bring it into Blassic SHELL "i2cget -y 0 0x63 0x1 b > /var/www/ramdisk/lo_byte.txt" OPEN "/var/www/ramdisk/lo_byte.txt" FOR INPUT AS #1 INPUT #1,lo_byte$ CLOSE #1 SHELL "i2cget -y 0 0x63 0x2 b > /var/www/ramdisk/hi_byte.txt" OPEN "/var/www/ramdisk/hi_byte.txt" FOR INPUT AS #1 INPUT #1,hi_byte$ CLOSE #1 'PRINT lo_byte$ 'PRINT hi_byte$ IF lo_byte$ = "0x01" THEN key$ = "1": hex_key$ = "31" IF lo_byte$ = "0x02" THEN key$ = "2": hex_key$ = "32" IF lo_byte$ = "0x04" THEN key$ = "3": hex_key$ = "33" IF lo_byte$ = "0x08" THEN key$ = "4": hex_key$ = "34" IF lo_byte$ = "0x10" THEN key$ = "5": hex_key$ = "35" IF lo_byte$ = "0x20" THEN key$ = "6": hex_key$ = "36" IF lo_byte$ = "0x40" THEN key$ = "7": hex_key$ = "37" IF lo_byte$ = "0x80" THEN key$ = "8": hex_key$ = "38" IF hi_byte$ = "0x01" THEN key$ = "9": hex_key$ = "39" IF hi_byte$ = "0x02" THEN key$ = "10": hex_key$ = "2A" IF hi_byte$ = "0x04" THEN key$ = "0": hex_key$ = "30" IF hi_byte$ = "0x08" THEN key$ = "11": hex_key$ = "23" key_value = VAL(key$) 'PRINT "hi_byte$ ", hi_byte$ 'PRINT "key$ ",key$ 'PRINT "VAL(key$) ",key_value IF ((key_value < 12) AND (key_value > 0)) OR (hi_byte$ = "0x04") THEN PRINT "key =",key$ : SHELL "echo -n "+key$+" >/var/www/ramdisk/key_pressed.txt" 'temporary exit - press # to stop the program 'IF hi_byte$ = "0x08" THEN key$ = "hash": hex_key$ = "23":SHELL "espeak -s 140 'gud bye' > /dev/null 2>&1" :SYSTEM 'IF lo_byte$ = "0x00" AND hi_byte$ = "0x00" THEN key$ = "no key pressed":hex_key$ = "7E" 'PRINT "key pressed is ",key$ ' print to screen 'send error reports below to stdout and then to null 'SHELL "i2cset -y 0 0x63 0x0 0x0C b > /dev/null 2>&1" 'SHELL "i2cset -y 0 0x63 0x0 0x01 b > /dev/null 2>&1" 'SHELL "i2cset -y 0 0x63 0x0 0x"+hex_key$+" b > /dev/null 2>&1" 'espeak always works but gives an error message - dump the message 'IF hex_key$ <> "7E" THEN SHELL "espeak -s 140 "+ key$ +" > /dev/null 2>&1" 'PAUSE 300 'GOTO Again