Shop OBEX P1 Docs P2 Docs Learn Events
DIG command I need help with how to use it — Parallax Forums

DIG command I need help with how to use it

sam_sam_samsam_sam_sam Posts: 2,286
edited 2008-03-19 18:08 in BASIC Stamp
attachment.php?attachmentid=73755The Digit operator (DIG) returns the specified decimal digit of a 16-bit positive value. Digits are numbered from 0 (the right-most digit) to 4 (the left-most digit of a 16-bit number; 0 to 65535).

[img]mk:@MSITStore:C:\Program%20Files\Parallax%20Inc\Stamp%20Editor%20v2.2.6\PBASIC.chm::/graphics/bs2all_inline.gif[/img] value VAR Wordidx VAR NibMain: value = 9742 DEBUG ? value DIG 2 ' Show digit 2 (7) FOR idx = 0 TO 4 DEBUG ? value DIG idx ' Show digits 0 - 4 of 9742 NEXT END'
'·· File....... SW21-EX28-ADC0831-Simple-Vref.BS2
'·· Purpose.... Servo control and positioning with a potentiometer
'·· Author..... (C) 2000 - 2005, Parallax, Inc.
'·· E-mail..... support@parallax.com
'·· Started....
'·· Updated.... 01 SEP 2005
'
'·· {$STAMP BS2}
'·· {$PBASIC 2.5}This the part of this code that I have a question about is there a way to change it to this 2 digit 12.00 like thisThis code below show with 1 digit it like this 1.200Main:
· DO
··· GOSUB Read_0831···························· ' read the ADC
··· mVolts = result */ Cnts2Mv················· ' convert to millivolts
··· DEBUG HOME,································ ' report
········· CRSRXY, 9, 0, DEC result, CLREOL,
········· CRSRXY, 9, 1, DEC mVolts DIG 3,
······················· ".", DEC3 mVolts·......>>>>>>>>·I tryed to change this line " " to this· 1·200 show this way
··································································· I want to change where the "." point is in the display
··································································· How·do i change it·······



··· PAUSE 100
·LOOP

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

·
·
·
·
Sam

Post Edited (sam_sam_sam) : 3/19/2008 3:33:10 AM GMT

Comments

  • RDL2004RDL2004 Posts: 2,554
    edited 2008-03-19 14:41
    I could be wrong, but if I remember right, the way the code works it sends digit 3 (DIG3), a decimal point ("."), then the rest of the decimal number truncated to 3 digits (DEC3).
    ·
    I recommend you read in the editor help until you understand exactly how these commands work. Do some experimenting.
    ·
    Just guessing here, because I don't have access to the editor or the help file from work, but I think it might be like DIG3, DIG2, ".", DEC2

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    - Rick
  • sam_sam_samsam_sam_sam Posts: 2,286
    edited 2008-03-19 16:15
    RDL2004

    Thank you for your reply


    I recommend you read in the editor help until you understand exactly how these commands work

    This is all it has about this command·in the ·Basic Stamp Editor Help say· this

    The Digit operator (DIG) returns the specified decimal digit of a 16-bit positive value. Digits are numbered from 0 (the right-most digit) to 4 (the left-most digit of a 16-bit number; 0 to 65535).


    I could be wrong, but if I remember right, the way the code works it sends digit 3 (DIG3), a decimal point ("."), then the rest of the decimal number truncated to 3 digits (DEC3).

    This what i though so i changed 3 (DIG3), from 3 to 2 and 1 and did not change where the "." point was

    So i at loss of how you change where "."point is

    The one thing i did was look at what the Basic Stamp Editor Help say about this commmand before i ask the question the
    on the forum


    Now i could just change these two ·line


    ·CRSRXY, 9, 1, DEC mVolts DIG 3,
    ······················· ".", DEC3 mVolts


    To
    ········ Dec3 ?, mVolts
    ································· ·but then i would not be able to put the "." point in there· if this is case i will have to live this

    .



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

    ·
    ·
    ·
    ·
    Sam
  • Mike GreenMike Green Posts: 23,101
    edited 2008-03-19 16:31
    There is no automatic way to change the position of the decimal point. You have to do it yourself. The DIG operator simply extracts the decimal digit from the binary number. The Stamp doesn't have floating point anyway, so it's usually not an issue. If you want to be able to output several different positions for the decimal point, you could use a CASE statement where the CASE selector is the number of decimal places in the number and have different output statements to handle the different cases like:
    SELECT places
       CASE 0:
          DEBUG DEC value,CR
       CASE 1:
          DEBUG DEC value/10,".",DEC1 value//10,CR
       CASE 2:
          DEBUG DEC value/100,".",DEC2 value//100,CR
       CASE 3:
          DEBUG DEC value/1000,".",DEC3 value//1000,CR
       CASE 4:
          DEBUG DEC value/10000,".",DEC4 value//10000,CR
    ENDSELECT
    
  • sam_sam_samsam_sam_sam Posts: 2,286
    edited 2008-03-19 16:36
    Mike Green

    Thank You for your reply That will ·help a lot

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

    ·
    ·
    ·
    ·
    Sam
  • RDL2004RDL2004 Posts: 2,554
    edited 2008-03-19 18:08
    The Basic Stamp Editor help told you exactly what you needed.

    This code will do what you want, display the specified digits with the decimal point in the center.

    DEBUG DEC mVolts DIG 3, DEC mVolts DIG 2, ".", DEC mVolts DIG 1, DEC mVolts DIG 0

    This will display the same thing.

    DEBUG DEC mVolts DIG 3, DEC mVolts DIG 2, ".", DEC2 mVolts

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    - Rick

    Post Edited (RDL2004) : 3/19/2008 9:13:17 PM GMT
Sign In or Register to comment.