Trying to write a times table tester
I've finally found time to sit down and get my head around the prop.
I've been working on some code for testing times tables
Here is what I've got so far.....
I'm stuck because the key input system only accepts one key so far so I can't go above 9 and I'd like to go to 12.
Also it stops me entering the correct answer because it only waits for a keypress and not a string of presses.
Does anyone have any life changing information they could share with me?
I've been working on some code for testing times tables
Here is what I've got so far.....
CON
_clkmode = xtal1 + pll16x
_xinfreq = 5_000_000
OBJ
text : "tv_text" 'tv output object
kb : "keyboard" 'keyboard input object
rnd : "SL32_INTEngine_2" 'random numbers
VAR
byte x[3]
byte y[3]
byte z[10]
PUB Main
rnd.random(cnt,1,9)
text.start(12) 'start the TV object on pin 12
kb.start(26,27) 'start the keyvoard object on pins 26 and 27
text.str(string(" Nurbit's Times Table Tester",13,13)) 'print to screen (13 adds CR)
text.str(string(" Which Table would you like? (1-9)")) 'ask which table
kb.getkey
if kb.keystate("1") == TRUE
text.out($00)
x :=1
elseif kb.keystate("2") == TRUE
text.out($00)
x:=2
elseif kb.keystate("3") ==TRUE
text.out($00)
x:=3
elseif kb.keystate("4") ==TRUE
text.out($00)
x:=4
elseif kb.keystate("5") ==TRUE
text.out($00)
x:=5
elseif kb.keystate("6") ==TRUE
text.out($00)
x:=6
elseif kb.keystate("7") ==TRUE
text.out($00)
x:=7
elseif kb.keystate("8") ==TRUE
text.out($00)
x:=8
elseif kb.keystate("9") ==TRUE
text.out($00)
x:=9
y:= rnd.random(cnt,1,9)
text.out($00)
text.str(string("What is "))
text.dec(x)
text.str(string(" times "))
text.dec(y)
kb.getkey
I'm stuck because the key input system only accepts one key so far so I can't go above 9 and I'd like to go to 12.
Also it stops me entering the correct answer because it only waits for a keypress and not a string of presses.
Does anyone have any life changing information they could share with me?

Comments
Anyhow, it should give you a solid idea of the concept. Good Luck!
CON '' Clock settings _CLKMODE = XTAL1 +PLL16X _XINFREQ = 5_000_000 '************** Connections { '' This is My setup TV = 0 KeySig = 24 KeyClk = 25 } '' This is Nurbit's setup TV = 12 KeySig = 26 KeyClk = 27 '************** ASCII Conversion chart BKSP = 8 ' Backspace CR = 13 ' carriage return SPC = 32 ' Space USCORE = 95 ' Underscore '************** Buffer size information MaxBufferSize = 64 ' alter this number to make your buffer bigger/smaller for your needs VAR Byte InputBuffer[MaxBufferSize] ' input buffer Long Decimal ' Decimal decoded string OBJ text : "tv_text" 'tv output object key : "keyboard" 'keyboard input object ' rnd : "SL32_INTEngine_2" 'random numbers DAT OverFlow_ Byte "Buffer Overflow Error",CR, 0 FoundVal_ Byte "Found value = ",0 PUB Init '' Init the drivers here ' rnd.random(cnt,1,9) 'Start the RNG TEXT.start(TV) 'start the TV object on pin 12 KEY.start(KeySig,KeyClk) 'start the keyvoard object on pins 26 and 27 TEXT.out(USCORE) Main PUB Main | char, pos '' Main method for accepting input from the user, storing it as a string, then coverting it to decimal values. '' Char is the character found at the keyboard. (ASCII value) '' Pos is the position in the buffer where it should be stored. repeat char := KEY.getkey ' Get the key if char == CR ' if a CR is found TEXT.out(BKSP) ' go over the previous cursor TEXT.out(SPC) ' White out the cursor TEXT.out(CR) ' go to new line InputBuffer[Pos] := 0 ' Null terminate the string Pos := 0 ' reset the pointer Decimal := StrToBase(@InputBuffer, 10) ' convert the string to a base 10 decimal ManipulateHere ' Go to the method that does the work on the decimal value elseif char > 31 and char < 126 ' If the character is standard ASCII number/letter/symbol InputBuffer[Pos++] := char ' store the character in the buffer, post increment pointer TEXT.out(BKSP) ' delete the previous cursor TEXT.out(char) ' Display the character TEXT.out(USCORE) ' Display the cursor if Pos == (MaxBufferSize-1) ' if pointer is at final null termination TEXT.str(@OverFlow_) ' display on the screen the buffer has overflowed bytemove(@InputBuffer, 0, MaxBufferSize) ' Zero Fill the buffer PUB StrToBase(stringptr, base) : value | chr, index {Converts a zero terminated string representation of a number to a value in the designated base. Ignores all non-digit characters (except negative (-) when base is decimal (10)).} '' This method taken from one of the many string manipulator methods in the obex. Cannot remember what one tho. value := index := 0 repeat until ((chr := byte[stringptr][index++]) == 0) chr := -15 + --chr & 011111 + 39*(chr > 56) 'Make "0"-"9","A"-"F","a"-"f" be 0 - 15, others out of range if (chr > -1) and (chr < base) 'Accumulate valid values into result; ignore others value := value * base + chr if (base == 10) and (byte[stringptr] == "-") 'If decimal, address negative sign; ignore otherwise value := - value PUB ManipulateHere '' Put your code here for manipulating the decimal value. For now, it just reports to user the converted decimal number. TEXT.str(@FoundVal_) TEXT.dec(Decimal) TEXT.out(CR) TEXT.out(USCORE) ' Display the cursorWow, that's really well commented, even I should be able to do something with that
I'll have a play with it