Reading a 3 digit DEC value into the Prop ?
JMLStamp2p
Posts: 259
Hello all,
I am reading DEC values into the Prop via a Matrix Keypad and displaying them on a Serial LCD by Matrix Orbital. The Method below is working for a two digit number. Example: When I press "1" on the Keypad it loads the DEC number "88" into Timer_1_Value· and displays it on the LCD. I would like to load a number from "0 - 999" into the Prop and have a Counter count down from that number to "0" and·then turn an output on or off. Could someone give me a starting point on how to accomplish this. I am using FullDuplexSerial for TX & RX.
Thanks,
JMLStamp2p
..........................................................
Working Code at this point below:
..........................................................
PUB Key_Pad_Input | Timer_1_Value
· data.Stop·
· data.start(3,2,0,19200)
· data.tx(254)···'Initiate LCD screen control·····································
· data.tx(88)···· 'Clear LCD screen
· data.tx(254)·· 'Initiate LCD screen control
· data.tx(72)···· 'Go to LCD home position
·repeat
·· Timer_1_Value := data.rx
····
·· if Timer_1_Value == (88)······················································
····· Toggle_Pin_23· 'Go to Method "Toggle_Pin_23"
·...........................................................····
I am reading DEC values into the Prop via a Matrix Keypad and displaying them on a Serial LCD by Matrix Orbital. The Method below is working for a two digit number. Example: When I press "1" on the Keypad it loads the DEC number "88" into Timer_1_Value· and displays it on the LCD. I would like to load a number from "0 - 999" into the Prop and have a Counter count down from that number to "0" and·then turn an output on or off. Could someone give me a starting point on how to accomplish this. I am using FullDuplexSerial for TX & RX.
Thanks,
JMLStamp2p
..........................................................
Working Code at this point below:
..........................................................
PUB Key_Pad_Input | Timer_1_Value
· data.Stop·
· data.start(3,2,0,19200)
· data.tx(254)···'Initiate LCD screen control·····································
· data.tx(88)···· 'Clear LCD screen
· data.tx(254)·· 'Initiate LCD screen control
· data.tx(72)···· 'Go to LCD home position
·repeat
·· Timer_1_Value := data.rx
····
·· if Timer_1_Value == (88)······················································
····· Toggle_Pin_23· 'Go to Method "Toggle_Pin_23"
·...........................................................····
Comments
JMLStamp2p
I've downloaded the code and looked at it but this is a little over my Head. Could you help me with an example ? If I wanted to inter the number on my Keypad with "3" successive strokes of "9" representing the number "999". This would send "76, 76 & 76" to the Propeller, what method would I need to use to convert
this into a single DEC number that I could decrement and test.
Thanks for your help as always.
JMLStamp2p
just a quick answer about the principle
just use the fundemental principle of the decimal system
DecValue := 0 ' init with zero
you get the first digit as a "76"
transform "76" to "9"
and store the "9" in a variable called "KbdDigit"
DecValue := DecValue + KbdDigit * 100
get second digit
transform "76" to "9"
and store the "9" in a variable called "KbdDigit"
DecValue := DecValue + KbdDigit * 10
get third digit
transform "76" to "9"
and store the "9" in a variable called "KbdDigit"
DecValue := DecValue + KbdDigit * 1
that's all
greetings
Stefan
JMLStamp2p
Did some enhancements.
[noparse][[/noparse]code]
{'*****************************
''* Keyboard input sample v1.0·· *
''*· 2008-02-14· *
''*****************************
''····· Filename:InputSample.spin
Sample code to demonstrate how to input numbers on a keypad and present it on a videomonitor.
Enter as many digits you want and finish by pressing enter key.
}
CON
· _clkmode = xtal1 + pll16x
· _xinfreq = 5_000_000
VAR
· Byte datain[noparse][[/noparse]16]
· Byte· Delimiter··········
OBJ
· text········· :"tv_text"·····························
· kb··········· :"Keyboard"
· num·········· :"Numbers"
· Fm··········· :"FloatMath"··
PUB Main | value
· text.start(12)··············· 'Video·
· text.str(string("Waits for keypad input i.e 789 and then press enter",13))
··· 'start the keyboard
· kb.start(26, 27)
· repeat
··· RxStr (@dataIn)
··· text.str(@datain)
··· text.out(13)
··· Value:=num.FromStr(@datain,10)
··· value:=value/2············· ' example
··· text.dec(value)
··· text.out(13)
PUB RxStr (stringptr) : Value | ptr
{{
· Accepts a string of characters - up to 15 - to be passed by reference
· String acceptance terminates with a carriage return or the defined delimiter character.
· Will accept up to 15 characters before passing back.
· Serial.Rxstr(@MyStr)······· ' accept
· serial.str(@MyStr)········· ' transmit
·}}
··· ptr:=0
··· bytefill(@dataIn,0,15)······························
·· dataIn[noparse][[/noparse]ptr] :=· kb.getkey'uart.Rx·······
·· ptr++·················································
·· repeat while ((DataIn[noparse][[/noparse]ptr-1] <> 13) and (DataIn[noparse][[/noparse]ptr-1] <> Delimiter)) and (ptr < 15)······
······ dataIn[noparse][[/noparse]ptr] :=· kb.getkey'uart.RX···
······ ptr++
·· dataIn[noparse][[/noparse]ptr-1]:=0········································
·· byteMove(stringptr,@datain,16)
[noparse][[/noparse]/code]
Goran
Post Edited (Goran (Sweden)) : 2/14/2008 11:15:43 PM GMT
Thank You very much for the code, this should definately help out !
I am using Matrix Oribital's Serial LCD and Parallax's matrix 4 by 4 Keypad. I may have to
ask a few questions converting some code but at least I have something to go by.
Thanks again,
JMLStamp2p
Psuedo-code:
Post Edited (MarkS) : 2/15/2008 1:36:25 AM GMT