Shop OBEX P1 Docs P2 Docs Learn Events
Display a VAR in graphics — Parallax Forums

Display a VAR in graphics

samsn4samsn4 Posts: 49
edited 2007-10-22 16:55 in Propeller 1
I'm trying to do a simple interface with the PING))). There is no demo that uses the TV, so I'm trying to write one using Graphics. My problem is that I can not figure out how to display a variable.

Thanks for the help

▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Daniel Mueth

Comments

  • Mike GreenMike Green Posts: 23,101
    edited 2007-10-22 16:37
    You can take the "dec" method from the tv_text driver that's included with the Propeller Tool and modify it slightly to use the graphics driver text method to do the actual display. The "dec" method uses the "out" method to display each character. It could be changed to
    VAR byte decBuffer[noparse][[/noparse]12]
    
    PUB dec(value) | i,p
    '' Print a decimal number
      p := 0
      if value < 0
        -value
        decBuffer[noparse][[/noparse]p++] := "-"
      i := 1_000_000_000
      repeat 10
        if value => i
          decBuffer[noparse][[/noparse]p++] := value / i + "0"
          value //= i
          result~~
        elseif result or i == 1
          decBuffer[noparse][[/noparse]p++] := "0"
        i /= 10
      decBuffer[noparse][[/noparse]p] := 0
    
    


    You'd call this to convert some variable into a decimal string, then use the text routine in the graphics package to draw the string (@decBuffer) on the screen where you want it.
  • Martin HebelMartin Hebel Posts: 1,239
    edited 2007-10-22 16:55
    Hi Dan,
    You can also use the FloatString library to turn a floating point value into a string (after 1st converting it to a float with FloatMath):

    
    Obj:
        gr    : "graphics"
        TV    : "TV"
        FP    : "FloatMath"    
        FS    : "FloatString"  
    
    Pub Main
       .
       .
       .
        gr.text(100,151,FS.FloatToString(FP.FFloat(x))) 
       .
       .
    
    

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    StampPlot - GUI and Plotting Software
    Southern Illinois University Carbondale, Electronic Systems Technologies
Sign In or Register to comment.