Consolidation of word variable input

bfgstew

Senior Member
I would like to be able to input into a word variable a value of between 0001 and 9999, now I can do that as long as the value is above 0999, no problem, but when I input a value below 1000 I get 999 or 99 or 9 where I would like it to be 0999 or 0099 or 0009.
I currently use this code to get the value into it

Code:
serout B.7,baud,(254,1)
	pause 500
	serout B.7,baud,(254,128," NOW SET THE FLASH  ")
	serout B.7,baud,(254,192,"       DELAY        ")
	serout B.7,baud,(254,154,"FD -",254,159,#w8,"ms")
 	pause 100
		For b33 = 1 to 4				
  			Gosub GKP
  			if key_value = 12 then return endif
  			w8 = w8 * 10 + b1 
  			serout B.7,baud,(254,159,#w8,"ms")
  			pause 30
  			next b33
 		Return
And then display on an OLED,

Is there away of getting the leading zeros in place without to much alteration to the above code.
One more question, if this can be done how do I get the cursor to blink and move onto the next character to input, so I know where I am, I have tried but the cursor seems to just sit there and blink away rather than stepping to next character?
Any help would be grateful received as this is the last piece of the jigsaw for my project and would so like it to be finished.

Stewart
 

hippy

Ex-Staff (retired)
Have a look at the BINTOASCII commands which will convert a number into a set of digits which can be displayed which will include leading "0", or use an IF-ELSE / SELECT-CASE to manually add the leading zeroes ...

Code:
Select Case w0
  Case < 10    : SerTxd( "0000", #w0 )
  Case < 100   : SerTxd( "000",  #w0 )
  Case < 1000  : SerTxd( "00",   #w0 )
  Case < 10000 : SerTxd( "0",    #w0 )
  Else         : SerTxd(         #w0 )
End Select
 

bfgstew

Senior Member
OK Hippy it is certainly a lot better than what I had, but it is still not quite how I would like it to appear on the OLED!
OK, just for example -
First press of key pad is a 0, how I would like it to appear is ___0ms
Second press is a 0 __00ms
Third press is a 5 _005ms
Fourth press is a 2 0052ms

If we can get it to appear in this way I will not require the blinking cursor, any ideas please?

Stewart
 

hippy

Ex-Staff (retired)
Keep track of how many key presses there have been and how many leading "_" you need to output. Using BINTOASCII makes that easier. Try this in the simulator ...

Code:
w0 = 0
b8 = 5 : Gosub Display

b9 = 0 : Gosub EnterDigit
b9 = 0 : Gosub EnterDigit
b9 = 5 : Gosub EnterDigit
b9 = 2 : Gosub EnterDigit
b9 = 7 : Gosub EnterDigit

Do:Loop

EnterDigit:
  b8 = b8 Min 1 - 1
  w0 = w0 * 10 + b9

Display:
  BinToAscii w0, b11,b12,b13,b14,b15
  If b8 > 0 Then : b11 = "_" : End If
  If b8 > 1 Then : b12 = "_" : End If
  If b8 > 2 Then : b13 = "_" : End If
  If b8 > 3 Then : b14 = "_" : End If
  If b8 > 4 Then : b15 = "_" : End If
  SerTxd( "Time = ",b11,b12,b13,b14,b15,"ms" )
  Return
 

bfgstew

Senior Member
Success!.......................Many thanks Hippy for the pointers, much appreciated, here is how it has been implimented into my original code snippet.

Code:
	serout B.7,N2400,(254,1)
			pause 30 
	serout B.7,N2400,(254,128,"DROP ONE:     ms")
	           pause 30
	           let b55 = 3
		For b20 = 1 to 4				
  			Gosub GKP 
  			if key_value = 10 then goto initd1   			
                                      if key_value = 12 then return
  			endif
  			w2 = w2 * 10 + b1
  			  BinToAscii w2, b50,b51,b52,b53,b54
                                                     If b55 > 0 Then : b51 = "_" : End If
                                                     If b55 > 1 Then : b52 = "_" : End If
                                                     If b55 > 2 Then : b53 = "_" : End If
                                                     If b55 > 3 Then : b54 = "_" : End If
  			serout B.7,N2400,(254,128,"DROP ONE: ",b51,b52,b53,b54,"ms")
  			pause 30
  			dec b55
  			next b20
  			pause 200
 		Return
Now to alter and amend all my coding to suit now.
Light at the end can now be seen...............................:D
 
Top