Shop OBEX P1 Docs P2 Docs Learn Events
Re[2]: [basicstamps] temperature sensor — Parallax Forums

Re[2]: [basicstamps] temperature sensor

ArchiverArchiver Posts: 46,084
edited 2001-02-03 20:15 in General Discussion
Hello Don,

Mmm... well i wanted to convert the 0-255 value (8bit) from the
outputs of the adc to a 0-99 display.

Or you have a better idea?

Friday, February 02, 2001, 11:40:01 PM, you wrote:

DR> Re: My previous reply... Since you said you wanted a two digit display, I
DR> assumed you wanted to display the 8 bit value in HEX. If you wanted to
DR> display the 8bit value in decimal, you may need up to three digits (0-255).

DR> If you want the 8bit value displayed as a decimal number in the range 0-255
DR> you can use the DEC modifier on the SEROUT command and the Stamp will do the
DR> necessary conversion auto-magically. :-)

DR> Don Russell

Comments

  • ArchiverArchiver Posts: 46,084
    edited 2001-02-03 07:11
    So you want to "scale" the 0-255 range to an integer range of 0-99? Or you
    expect the byte value range to always be within 0-99?

    As mentioned, the DEC modifier for the SEROUT command will handle the
    conversion to 2 digits (or only 1 if the result is less than 10 decimal)

    If you want to scale the range so that a display of 99 represents the 255
    "actual" value.... multiply the value by 100 then divide by 255. Basically
    you're calulating the percentage of the 0-255 range that way. This would
    actually give you a final range of 0-100...

    Original Message
    From: "Kalun Lau" <klnlau@t...>
    To: "Don Russell" <basicstamps@yahoogroups.com>
    Sent: Friday, February 02, 2001 9:28 PM
    Subject: Re[noparse][[/noparse]2]: [noparse][[/noparse]basicstamps] temperature sensor


    > Hello Don,
    >
    > Mmm... well i wanted to convert the 0-255 value (8bit) from the
    > outputs of the adc to a 0-99 display.
    >
    > Or you have a better idea?
    >
    > Friday, February 02, 2001, 11:40:01 PM, you wrote:
    >
    > DR> Re: My previous reply... Since you said you wanted a two digit
    display, I
    > DR> assumed you wanted to display the 8 bit value in HEX. If you wanted to
    > DR> display the 8bit value in decimal, you may need up to three digits
    (0-255).
    >
    > DR> If you want the 8bit value displayed as a decimal number in the range
    0-255
    > DR> you can use the DEC modifier on the SEROUT command and the Stamp will
    do the
    > DR> necessary conversion auto-magically. :-)
    >
    > DR> Don Russell
    >
    >
    >
    >
    >
    >
  • ArchiverArchiver Posts: 46,084
    edited 2001-02-03 20:15
    >Mmm... well i wanted to convert the 0-255 value (8bit) from the
    >outputs of the adc to a 0-99 display.

    If you are sending data to the debug screen, then use

    debug dec value,cr
    or
    value = value */ 100 ' normalize 0->255 to 0->99
    debug dec value,cr
    similarly for the serout command, use the DEC modifier, for example
    to send the output to a serial LCD screen.


    If you can't use the DEC modifier, which is only available with the
    serout or debug commands, then look into the DIG operator (see the
    Stamp manual). This might be the case if you are working with a
    parallel LCD interface.

    value=value */ 100 ' normalize if necessary
    for i=1 to 0
    char=value DIG i
    gosub sendchar ' print the char on display
    next

    That picks off the 2 decimal digits.

    BTW, the new BS2P will have an LCDout command for parallel LCDs, that
    will allow you to use all the format modifiers as in SEROUT.

    regards,
    Tracy Allen
    electronically monitored ecosystems
    http://www.emesystems.com
Sign In or Register to comment.