Shop OBEX P1 Docs P2 Docs Learn Events
convert a decimal variable to a string — Parallax Forums

convert a decimal variable to a string

CrosswindsCrosswinds Posts: 182
edited 2011-12-25 08:30 in Propeller 1
Hello.

This is probably a very simple question, but i cant seem to get it to work.


I have an LCD driver, that only takes null terminated strings, and it works great.

But i want to interface the ds1302 with it, and it puts out decimal values. I have tried to use simplenumbers, dec function, but no go.

example:
rtc.readTime( @hour, @minute, @second )
LCD.Goto(0, 0)
SN.decstr(second)
LCD.writestring(second)
waitcnt (30_000_000 +cnt)

Comments

  • Mike GMike G Posts: 2,702
    edited 2011-12-25 06:43
    I'm not familar with simple numbers but don't you have to grab the pointer results of decstr()?
    myptr := SN.decstr(second)
    LCD.writestring(myptr )
    
  • CrosswindsCrosswinds Posts: 182
    edited 2011-12-25 07:17
    Mike G wrote: »
    I'm not familar with simple numbers but don't you have to grab the pointer results of decstr()?
    myptr := SN.decstr(second)
    LCD.writestring(myptr )
    

    oh sorry, i uploaded the wrong routine, that one is a private routine inside of serial numbers, it should be just SN.dec..

    Thanks for your reply, though, didnt work either..
  • CrosswindsCrosswinds Posts: 182
    edited 2011-12-25 07:35
    Maybe there is someway to break out the single numbers of this these numbers? I can send them individually with writechar function..

    ie:

    12 will be
    1
    2
  • Mike GMike G Posts: 2,702
    edited 2011-12-25 07:45
    You really should post all your code :(


    Maybe this will help. Replace the PST with the LCD object.
    CON
      _clkmode = xtal1 + pll16x     
      _xinfreq = 5_000_000
    
    VAR
      long  ptrNum
    
    OBJ
      pst   : "Parallax Serial Terminal"
      nums  : "Simple_Numbers"
    
      
    PUB Main | myNum
      pst.start(115200)
      Pause(500)
    
      myNum := 12345
      ptrNum := nums.dec(myNum)
    
      pst.str(String("Number to String: "))
      pst.str(ptrNum)
      pst.char(13)
    
    
    PRI Pause(Duration)  
      waitcnt(((clkfreq / 1_000 * Duration - 3932) #> 381) + cnt)
      return 
    
  • CrosswindsCrosswinds Posts: 182
    edited 2011-12-25 08:30
    It sure did! It works great now.


    and i had also difined the variable wrong, stupid stupid


    Thank you mike for your help!
Sign In or Register to comment.