Shop OBEX P1 Docs P2 Docs Learn Events
Converting a number to ascii character — Parallax Forums

Converting a number to ascii character

ArchiverArchiver Posts: 46,084
edited 2003-05-17 04:38 in General Discussion
I am using the Basic stamp 2 and I was wondering how I can convert a
number ie. 50 to Ascii 5 and 0.
I need to display a counter decreasing from 60 seconds down to 0 on
an LCD display

Thank you

-M

Comments

  • ArchiverArchiver Posts: 46,084
    edited 2003-05-17 02:24
    Depends on the kind of LCD you have: parallel or serial. For a parallel
    display, you have to do a bit of work:

    char = (seconds DIG 1) + 48 : GOSUB LCD_Write
    char = (seconds DIG 0) + 48 : GOSUB LCD_Write

    The '+ 48' is what converts a single-digit value to its ASCII code. If you
    have a serial LCD, you can user built-in formatting:

    SEROUT pin, baud, [noparse][[/noparse]DEC2 seconds]

    -- Jon Williams
    -- Parallax


    In a message dated 5/16/2003 7:44:52 PM Central Standard Time,
    mdbware@h... writes:

    > I am using the Basic stamp 2 and I was wondering how I can convert a
    > number ie. 50 to Ascii 5 and 0.
    > I need to display a counter decreasing from 60 seconds down to 0 on
    > an LCD display
    >
    > Thank you
    >
    > -M



    [noparse][[/noparse]Non-text portions of this message have been removed]
  • ArchiverArchiver Posts: 46,084
    edited 2003-05-17 04:38
    Thank you Jon.

    I found the solution on one of the postings, this is what I did.

    for Index = 2 to 0
    char=(t1 dig iNDEX) + "0"
    gosub lcdWr
    next

    Thank you

    -M




    --- In basicstamps@yahoogroups.com, jonwms@a... wrote:
    > Depends on the kind of LCD you have: parallel or serial. For a
    parallel
    > display, you have to do a bit of work:
    >
    > char = (seconds DIG 1) + 48 : GOSUB LCD_Write
    > char = (seconds DIG 0) + 48 : GOSUB LCD_Write
    >
    > The '+ 48' is what converts a single-digit value to its ASCII
    code. If you
    > have a serial LCD, you can user built-in formatting:
    >
    > SEROUT pin, baud, [noparse][[/noparse]DEC2 seconds]
    >
    > -- Jon Williams
    > -- Parallax
    >
    >
    > In a message dated 5/16/2003 7:44:52 PM Central Standard Time,
    > mdbware@h... writes:
    >
    > > I am using the Basic stamp 2 and I was wondering how I can
    convert a
    > > number ie. 50 to Ascii 5 and 0.
    > > I need to display a counter decreasing from 60 seconds down to 0
    on
    > > an LCD display
    > >
    > > Thank you
    > >
    > > -M
    >
    >
    >
    > [noparse][[/noparse]Non-text portions of this message have been removed]
Sign In or Register to comment.