Shop OBEX P1 Docs P2 Docs Learn Events
need minor help with LM9033a driver ver 002 — Parallax Forums

need minor help with LM9033a driver ver 002

radialrandyradialrandy Posts: 78
edited 2011-01-06 13:44 in Propeller 1
'***************************************
PRI displayMainScreen
'***************************************

    'Setup a screen with the logo
    gr.color(3)
    gr.textmode(2,2,5,4)
    gr.width(0)
    gr.text(63,67,@TXTlogo)
    gr.textmode(2,2,5,4)
    gr.width(1)
    gr.text(63,45,@TXTprs)
    gr.colorwidth(3,1)
    gr.box(0,0,128,50)
    gr.textmode(4,4,8,5)
    gr.colorwidth(0,7)
    gr.text(64,25,@TXTpsi)

'***************************************
PRI pauseMSec(Duration)
'***************************************
'' Pause execution in milliseconds.
'' Duration = number of milliseconds to delay
  
  waitcnt(((clkfreq / 1_000 * Duration - 3932) #> 381) + cnt)
  


'***************************************
DAT
'***************************************

TXTlogo       byte      "Boost Leash",0
TXTprs        byte      "CO2 Psi",0
TXTpsi        byte      "100",0

At the bottom of this code in the DAT section is some text to be displayed on the lcd. How can I make it display a varible instead of the preset data?

Comments

  • MagIO2MagIO2 Posts: 2,243
    edited 2011-01-05 13:37
    You simply take one of the String libraries available in the tools section of the ObjectExchange, take care that there are enough bytes available to hold the longest number you want to display and call the function that converts a variable to a decimal string.
  • radialrandyradialrandy Posts: 78
    edited 2011-01-05 18:27
    please forgive my ignorance. But I'm trying but I cant figure out how to do it. What are the steps that I need to do to take a varible named count1 which represents a decimal number from 0-100 and get it on my lm9033 display? I'm thinking that i got to take that varible valuem (which im assuming is really a binary number) and convert it to a zero teminated string of a decimal number and store in as another varible and call that varible address. But I just cant figure it out.
  • MagIO2MagIO2 Posts: 2,243
    edited 2011-01-06 00:43
    Let's use this object from the object exchange:

    http://obex.parallax.com/objects/529/

    So, you add this object to the OBJ section:

    OBJ
    stringObj: "ASCII0_STREngine_1"
    ...

    As I learned from the source of this string-object, it has an internal buffer to hold the converted number. So, wherever you want to output the value of your variable you have to say:

    gr.text( 64,25, stringObj( count1, 3 ) )
    this will output the number with sign

    gr.text( 64,25, stringObj( count1, 3 )+1 )
    this will output the number without sign

    PS: If you have test code, then post it here and we can have a look what your missunderstanding is.
  • radialrandyradialrandy Posts: 78
    edited 2011-01-06 06:27
    MagIO2 wrote: »
    Let's use this object from the object exchange:

    http://obex.parallax.com/objects/529/

    So, you add this object to the OBJ section:

    OBJ
    stringObj: "ASCII0_STREngine_1"
    ...

    As I learned from the source of this string-object, it has an internal buffer to hold the converted number. So, wherever you want to output the value of your variable you have to say.

    gr.text( 64,25, stringObj( count1, 3 ) )
    this will output the number with sign

    gr.text( 64,25, stringObj( count1, 3 )+1 )
    this will output the number without sign

    PS: If you have test code, then post it here and we can have a look what your missunderstanding is.

    Is there something missing? I dont see anything pointing to a method in the stringObj object. Should there be something like : gr.text( 64,25, stringObj.method( count1, 3 ) ). Im just asking cause im still learning. I just though there should be a .method behind the stringObj
  • MagIO2MagIO2 Posts: 2,243
    edited 2011-01-06 11:43
    My fault ... yep, there should

    stringObj.integerToDecimal(...)

    is the right function.

    Don't hesitate to open the *.spin-files of objects you want to use. These are in most cases documented very well. The radiobuttons above the editor in the propeller-tool ("Full source", "Summary") are good for browsing a file. Summary gives you a complete list of functions available in the file. Good function names will speek for themselves.
  • radialrandyradialrandy Posts: 78
    edited 2011-01-06 13:02
    does that give a zero terminated string?
  • MagIO2MagIO2 Posts: 2,243
    edited 2011-01-06 13:37
    Have a look at your original code:
    ...
    gr.text(64,25,@TXTpsi)
    ...
    and in the DAT section you find:
    ...
    TXTpsi byte "100",0

    So, what do we have here? TXTpsi is a label which is used to mark a piece of memory, here it's a piece having 4 bytes. What makes this piece of memory a string is the fact that all bytes used there are characters ( "100" = 3 characters ) and the end of string sign (the 0).
    The problem with strings is, that we can not use strings as parameters or return values. The reason for that is that the propeller language simply does not allow that. The only datatype that can be used as parameter or return value is the LONG.
    So, how do we pass strings then? We don't, we only pass the address!
    The instruction gr.text(..., @TXTpsi) only passes the address of the memory location TXTpsi (that's what the @ means).

    And NO, the function call stringObj.integerToDec(..) does not give a zero terminated string. It returns the address where to find that string. And that's exactly what the function gr.text(...) wants to know.

    You should only be aware that integerToDec always will use the same buffer to convert a number to string. So, if you convert several numbers, the previous converted number will be overwritten. If you need to keep the strings you have to copy them from that buffer to your own buffer ( for example to TXTpsi ).

    Hope that helped.
  • radialrandyradialrandy Posts: 78
    edited 2011-01-06 13:44
    Yes you have helped greatly and gave me a better understanding. I will try this tonight. Thank you so much for taken the time to guide me through this. Thanks
Sign In or Register to comment.