Shop OBEX P1 Docs P2 Docs Learn Events
Help with Numbers Object — Parallax Forums

Help with Numbers Object

lfreezelfreeze Posts: 174
edited 2010-02-26 16:06 in Propeller 1
Please help me solve this problem…..
I am using the numbers object to convert variables to strings for display on an LCD. The numbers
Object does display the correct converted variables to strings, but it adds a leading blank space for each conversion.
I am using this format from the numbers object to make the conversion,

ser.str(num.tostr(HOUR,%000_000_000_0_0_000000_01010 ))

The format results in an LCD display of “hour= 12” , I need to eliminate the leading blank
Character and display this “hour=12 “


The example program is below.
Is there a Way to format the numbers object to eliminate the leading blank character entirely ,
Or a way to edit the string?
I tried using the formaters associated with the lcd to eliminate the blank “destructive backspace and character positioning”
but they did not help. I hope someone can point me the right direction,
Thank you in advance for any help/

Larry

{{ TEST OF NUMBERS OBJECT

}}

CON
_clkmode = xtal1 + pll16x
_xinfreq = 5_000_000

OBJ
ser :"fullduplexserial"
num : "numbers"
PUB main | hour
hour:=0
ser.start(31, 30, 0, 9600) 'note pin 16 is for the data to the lcd

repeat
ser.tx(13)'carriage return
ser.tx(10)'line feed
waitcnt (20_000_000 + cnt )
num.init
ser.str(STRING("hour="))
ser.str(num.tostr(HOUR,%000_000_000_0_0_000000_01010 ))
waitcnt (20_000_000 + cnt )
HOUR++
if HOUR==11
HOUR:=1

Comments

  • Dave HeinDave Hein Posts: 6,347
    edited 2010-02-25 22:25
    You could print out the hour by calling ser.dec(hour)
  • lfreezelfreeze Posts: 174
    edited 2010-02-26 01:57
    Thanks for the response. I tried ser.dec(hour) and all I get is a blank lcd screen. After spending some more time with the problem, I believe this is due to some problem with the
    lcd set up characters. If I can't correct this with the lcd I have, I will purchase the parallax lcd. Can anyone tell me, if
    when usning the fullduplexserial object that "ser.dec(anyvariable)" will display correctly without any leading blank character on the parallax lcd?
    Thanks
    Larry
  • MagIO2MagIO2 Posts: 2,243
    edited 2010-02-26 06:08
    I don't think that it's the display. I just had a short glance into the number-object. It looks like the leading space is placeholder for the sign. If you don't have negative numbers - that's what I'd suppose for hours - then simply add 1 to the result of num.tostr.

    num.tostr will return the address of the string, so when you add 1 your send will skip the first character.
  • max72max72 Posts: 1,155
    edited 2010-02-26 06:26
    As an alternative check the obex.
    There is another, simpler, smaller numbers object, and if i remember correctly you can get rid of the leading space.

    obex.parallax.com/objects/182/

    Massimo
  • lfreezelfreeze Posts: 174
    edited 2010-02-26 15:10
    Thank you everyone, changing to the "Simple_Numbers" object solved my leading blank character problem.
    I used that object with "ser.str(num.decf(hour,1))" and this eliminated the leading blank.
    Larry
  • Dave HeinDave Hein Posts: 6,347
    edited 2010-02-26 16:06
    I'm puzzled as to why ser.dec(hour) didn't work.· I may not have been clear on how to use it.· The call to ser.dec converts a number to ascii AND prints it out.· So the correct way to use it would be

    ser.dec(hour)

    and not

    ser.str(ser.dec(hour))

    I just wanted to make that clear.

    Dave
Sign In or Register to comment.