Shop OBEX P1 Docs P2 Docs Learn Events
How do I make a Bar Graph on a LCD Display that responds to a ADC 0831 OUTPUT V — Parallax Forums

How do I make a Bar Graph on a LCD Display that responds to a ADC 0831 OUTPUT V

sam_sam_samsam_sam_sam Posts: 2,286
edited 2008-08-15 01:31 in General Discussion
Has any one done this before Would you Please help me get Started

This what I want to



I want 40·Display Character··that are (*), would = 2 AMP·on the Display that would show how many·MillAmps there are for Two Amps MAX

·This is how·I Have it set up

2 volt· = 2 amps

.0098 volts for each ADC step

For each Display Character·=·5.25·@ ONE ADC Step··Which there are 40 Display Character··in to 210 ADC Steps

This would mean that 4 Character·I would have to add one Character







But I want to a lot·less range that this
This is what I have so far



I could do it way but this not what I am looking for

·IF (result <= 20) THEN
····· GOSUB Display01
ELSEIF (result >= 20 AND result· <= 82) THEN
····· GOSUB· Display02
ELSEIF (result >= 83 AND result <= 87) THEN
····· GOSUB· Display03
ELSEIF(result >= 87 AND result <= 95) THEN
····· GOSUB Display04
ELSEIF(result >=·96 AND result <= 101) THEN
····· GOSUB Display05



·Display01:
·· SEROUT LCD, Baud, [noparse][[/noparse]ClearScreen]
·· SEROUT LCD, Baud, [noparse][[/noparse]LineOne0,LineTwo0,"*"]
·· RETURN

·· Display02:
·· SEROUT LCD, Baud, [noparse][[/noparse]ClearScreen]
·· SEROUT LCD, Baud, [noparse][[/noparse]LineOne0,LineTwo0,"****"]
·· RETURN

·· Display03:
·· SEROUT LCD, Baud, [noparse][[/noparse]ClearScreen]
·· SEROUT LCD, Baud, [noparse][[/noparse]LineOne0,LineTwo0,"********"]
·· RETURN

·· Display04:
· ·SEROUT LCD, Baud, [noparse][[/noparse]ClearScreen]
·· SEROUT LCD, Baud, [noparse][[/noparse]LineOne0,LineTwo0,"************"]
·· RETURN

··· Display05:
·· SEROUT LCD, Baud, [noparse][[/noparse]ClearScreen]
·· SEROUT LCD, Baud, [noparse][[/noparse]LineOne0,LineTwo0,"****************"]
·· RETURN

▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
··Thanks for any·idea.gif·that you may have and all of your time finding them

·
·
·
·
Sam

Post Edited (sam_sam_sam) : 8/13/2008 12:42:42 AM GMT

Comments

  • PJAllenPJAllen Banned Posts: 5,065
    edited 2008-08-13 00:53
    sam_sam_sam,

    Will you ever connect with FOR...NEXT ? · burger.gif

    I'm using DEBUG, but changing to SEROUT should be no big deal.· You don't want to have a SEROUT for each series of stars or bargraph blocks.· That takes up, unnecessarily, so much program space.
    ' {$STAMP BS2}
    ' {$PBASIC 2.5}
     
    stars  VAR  Byte
    bargraph  VAR  Byte
     
    prompt:
      DEBUG "input stars to see 0-9", CR
      DEBUGIN DEC1 stars
      DEBUG CLS
      IF stars = 0 THEN prompt
      FOR bargraph = 1 TO stars
        DEBUG "*"
        NEXT
      PAUSE 2000
      DEBUG CLS
      GOTO prompt
    
  • PJAllenPJAllen Banned Posts: 5,065
    edited 2008-08-13 02:04
    ' {$STAMP BS2}
    ' {$PBASIC 2.5}
    
    result    VAR  Byte    ' 0 to 100
    bargraph  VAR  Byte
     
    prompt:
      result = result / 20
      DEBUG CLS
      IF stars = 0 THEN prompt
      FOR bargraph = 1 TO stars
        DEBUG "*"
        NEXT
      PAUSE 2000
      DEBUG CLS
      GOTO prompt
    


    Post Edit -- Looks like you omitted your post for which this was a Reply, OM.

    Post Edited (PJ Allen) : 8/13/2008 2:15:28 AM GMT
  • ZootZoot Posts: 2,227
    edited 2008-08-13 02:19
    e.g.

    char VAR Byte
    ADCval VAR Byte
    i VAR Nib
     
    ADCval = 8 ' really would be derived from A/D
     
    Char = LineOne0
    GOSUB LCD_Char_Out
    Char = LineTwo0
    GOSUB LCD_Char_Out
     
    char = "*"
    FOR i = 0 TO ADCval
      GOSUB LCD_Char_Out
    NEXT
     
    DO : LOOP
     
     
    LCD_Char_Out:
       SEROUT LCD, Baud, [noparse][[/noparse]char]
       RETURN
     
    
    


    Besides being simpler, this will save you a huge amount of code space and make your output to the LCD much more flexible.

    If you need to adjust the range, then just the val in the for/next loop, i.e., if you are getting values of 20-101, then you might do

    FOR i = 0 to ( ADCval MIN 20 - 20 /·5 )

    which gives you about 16 "bars" of resolution across that range

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    When the going gets weird, the weird turn pro. -- HST

    1uffakind.com/robots/povBitMapBuilder.php
    1uffakind.com/robots/resistorLadder.php


    Post Edited (Zoot) : 8/13/2008 2:26:52 AM GMT
  • sam_sam_samsam_sam_sam Posts: 2,286
    edited 2008-08-13 03:39
    Zoot

    Thank you for your reply

    Please tell me if i have this Right
    I can not test it now

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    ··Thanks for any·idea.gif·that you may have and all of your time finding them

    ·
    ·
    ·
    ·
    Sam

    Post Edited (sam_sam_sam) : 8/13/2008 3:45:52 AM GMT
  • sam_sam_samsam_sam_sam Posts: 2,286
    edited 2008-08-13 03:42
    PJ Allen

    Thank You for your help

    I try your second post code and work GREAT which is the Bargraph Demo below


    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    ··Thanks for any·idea.gif·that you may have and all of your time finding them

    ·
    ·
    ·
    ·
    Sam

    Post Edited (sam_sam_sam) : 8/13/2008 4:51:54 AM GMT
  • TCTC Posts: 1,019
    edited 2008-08-13 12:27
    I am not that good with programing, but could the "REP" formatter work?

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    We all make mistakes when we are young………That’s why paste is edible!
  • ZootZoot Posts: 2,227
    edited 2008-08-13 12:34
    TC -- yes, absolutely. I forgot about that formatter. It would amount to the same thing -- the REP is a kind of internal for/next. Would save code space, though.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    When the going gets weird, the weird turn pro. -- HST

    1uffakind.com/robots/povBitMapBuilder.php
    1uffakind.com/robots/resistorLadder.php
  • sam_sam_samsam_sam_sam Posts: 2,286
    edited 2008-08-13 12:53
    TC

    Thank You for that I had not·seen that before

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    ··Thanks for any·idea.gif·that you may have and all of your time finding them

    ·
    ·
    ·
    ·
    Sam
  • TCTC Posts: 1,019
    edited 2008-08-13 13:59
    I used it years ago with debug, but never serout

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    We all make mistakes when we are young………That’s why paste is edible!
  • ZootZoot Posts: 2,227
    edited 2008-08-13 14:30
    sam_sam_sam:

    e.g.

    SEROUT LCD, Baud, [noparse][[/noparse] REP "*"\(result MIN 20-20/50) ]
    
    



    But I'll take back what I said -- I think for code space, clarity and flexibility you are better off using the serout in the sub, with a for next loop. Duplicating serout statements can chew up serious code space.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    When the going gets weird, the weird turn pro. -- HST

    1uffakind.com/robots/povBitMapBuilder.php
    1uffakind.com/robots/resistorLadder.php
  • Tracy AllenTracy Allen Posts: 6,666
    edited 2008-08-13 17:02
    It is also possible to do high resolution bargraph by taking advantage of the CG character ram. The idea is to have vertical bars 1, 2, 3 4 and 5 pixels wide. Then on a 20 character wide display, you can have a bar with 5*20 = 100 steps instead of just 20. There are still 1 pixel spaces between each group of 5 though. The following routine fills the CG RAM with the required patterns (Scott Edwards backpack syntax):
    serout 12,$4054,[noparse][[/noparse]254,$40]             ' select CG ram
    for n=0 to 39                         ' five chars, 40 bytes
    serout 12,$4054,[noparse][[/noparse] DCD (n/8) - 1 REV 5] ' math trick to get patterns
    next
    


    Then when the number you want to display is scaled to the range of n={0 to 99}, the following line displays the bar (this happens to position the bar on the second line of a 4x20 display):
    SEROUT 12,$4054,[noparse][[/noparse] 254,192,rep 255\(n/5),n//5,rep 32\(19-(n/5))]
    


    That prints a series of character 255 (a solid block), followed by one narrower block drawn from CG ram by the n//5, and then clears the rest of the line by prining the required number of spaces (ascii 32).


    There is a demo program here at bargraph.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Tracy Allen
    www.emesystems.com
  • sam_sam_samsam_sam_sam Posts: 2,286
    edited 2008-08-13 18:25
    Tracy Allen

    Thank You for your reply
    I like this ·idea.gif·but need to ask you something about·(Scott Edwards backpack)

    I know that they are not the same as a Parallax 4 Line display

    I do not have·a (Scott Edwards backpack or Display) will this matter can you do·the same thing with a Parallax 4 Line display and how would you do it· I have one of these

    Thank you for all of your help

    ·Zoot

    Thank You for your help·with this also·I will give this try as soon as·I finish the Basic Stamp to· Optic Sensor / ADC Board and hook up the LCD Display

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    ··Thanks for any·idea.gif·that you may have and all of your time finding them

    ·
    ·
    ·
    ·
    Sam

    Post Edited (sam_sam_sam) : 8/13/2008 6:36:56 PM GMT
  • Tracy AllenTracy Allen Posts: 6,666
    edited 2008-08-13 22:04
    I'm not familiar with what syntax differences there might be between the Parallax and Scott Edwards displays. For all I know, they are identical.

    In any case, the LCD controller would be the same and any changes required would likely be minor.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Tracy Allen
    www.emesystems.com
  • Chris SavageChris Savage Parallax Engineering Posts: 14,406
    edited 2008-08-14 14:45
    There are examples of standard and high-resolution bar graphs at the following link from the Completed Projects Forum.· These examples should get you started.

    http://forums.parallax.com/showthread.php?p=553226

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Chris Savage
    Parallax Tech Support
  • sam_sam_samsam_sam_sam Posts: 2,286
    edited 2008-08-15 01:31
    Chris Savage or any One Else

    Thank you for the links and Demo which I was able to get the Demo working

    The ·standard and high-resolution bar graphs work great

    And·I got ADC Demo to work

    But Can not·seem the two·of them to·work together I try a lot of different way of doing it·

    The ·high-resolution bar graphs is the one that want to use

    with 210 is the Max

    But I at a lost as what to do next

    Thank for any help that you can give me

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    ··Thanks for any·idea.gif·that you may have and all of your time finding them

    ·
    ·
    ·
    ·
    Sam

    Post Edited (sam_sam_sam) : 8/15/2008 1:36:37 AM GMT
Sign In or Register to comment.