Shop OBEX P1 Docs P2 Docs Learn Events
StampPlot Help — Parallax Forums

StampPlot Help

cplattcplatt Posts: 55
edited 2011-04-13 19:53 in BASIC Stamp
I am a total beginner and need a little wisdom. I am trying to change the following PBasic command into something StampPlot could use:

DEBUG DEC (x / 1000), ".", DEC2 (x), CR 'displays raw 1234 as 1.234

in my mind it would be:

DEBUG "!ACHN 0, ", DEC (x/1000) + DEC3(x), CR


Alas, of course it doesn't work. I understand that the command cuts up a number in the form 1.234, displays the 1, then the period, then the 234. I just don't understand why? Is it because the stamp cannot display fractions? Anyhow thank you for looking at this.

Comments

  • Mike GreenMike Green Posts: 23,101
    edited 2011-04-09 20:21
    I can't tell what you're trying to do, but the Stamps do their arithmetic in 16 bit integers only. These range from 0 to 65535 or from -32768 to +32767 depending on whether you use DEC or SDEC to display them. If you want to do fractions, you have to scale them. As you've noticed, 1.234 gets represented as the integer 1234. You can add and subtract values that are scaled the same, but you have to correct the results when you multiply or divide such values.
  • Martin HebelMartin Hebel Posts: 1,239
    edited 2011-04-13 18:07
    If the DEBUG window shows it as 1.234, StampPlot should see the same.

    Here's a better trick - let StampPlot do the math for you - send data in brackets to perform processing before being used, such as:
    [1234 / 1000] would use the value of 1.234. (you can open the DEBUG window and test - ensure you have a space between numbers and operators. In the StampPlot Debug/Immediate window, enter to test:
    !DBUG [1234 / 1000]
    and see the value. Send the same structure from the BS2:

    DEBUG "!ACHN 0,[", dec x, " / 1000]", CR

    Note, math is performed left to right without inner brackets for precedence, so:
    [1 + 10 * 3] would equal 33.

    -Martin Hebel (StampPlot Pro Developer)
  • Martin HebelMartin Hebel Posts: 1,239
    edited 2011-04-13 19:53
    Forgot color as you did as well:
    !ACHN channel, value, color
    DEBUG "!ACHN 0,[", dec x, " / 1000], (RED)",CR
Sign In or Register to comment.