Shop OBEX P1 Docs P2 Docs Learn Events
Decimal values — Parallax Forums

Decimal values

edmondfoxedmondfox Posts: 15
edited 2005-11-27 02:53 in BASIC Stamp
Is it possible to serin decimal values to the Stamp 2? For example, how would I recieve the number 7.89, right now when I type the '.' it thinks the number is over. I have tried multiplying the input by 100 before sending it and dividing it by 100 on the stamp but that only yields what is on the left side of the decimal point (ex. 789/100 = 7), how do I fix this?

Comments

  • NewzedNewzed Posts: 2,503
    edited 2005-11-27 00:49
    If you just want to display it you can write:



    com = 787

    debug dec com/10,".",dec1 com

    That will display 78.7

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Sid Weaver
    Do you have a Stamp Tester yet?
    http://hometown.aol.com/newzed/index.html

    ·
  • edmondfoxedmondfox Posts: 15
    edited 2005-11-27 00:51
    I want to use the value as a delay.

    hers is the part of the code I need it for:

    SERIN RxD, Baud,[noparse][[/noparse]DEC stampDelay]
    stepDelay = stampDelay / 100
    .
    .
    .
    PAUSE stepDelay
  • Paul K.Paul K. Posts: 150
    edited 2005-11-27 00:52
    I believe the Stamp cant do decimal without the floating point coprocessor or something that is equivilant. Parallax sells one $15.
  • Clock LoopClock Loop Posts: 2,069
    edited 2005-11-27 01:44
    You want to use the value for a pause value. The pause value can only accept increments of 1ms. So if your trying to do 1.5ms, you can't.

    All timing/values in the BS2 is done in whole numbers. (the stamp can also do signed whole numbers)

    Even using a floating point coprocessor won't help you do what you want, because even if the coprocessor could somehow do something with the decimal, what is it going to tell the stamp?

    It can only tell the stamp to PAUSE "whole number"
  • Tracy AllenTracy Allen Posts: 6,658
    edited 2005-11-27 02:53
    What are the units of the delay you want? Is that 7.89 seconds, or 7.89 milliseconds or what? What are you trying to do?

    The units of the PAUSE command are miliseconds.
    PAUSE 7890 ' gives 7.89 seconds.

    Milliseconds are trickier. You can use a command like
    PULSOUT somepin,stampdelay
    where stampdelay is in units of 2 microseconds (on the BS2). But in computing the delay you have to account for the time it takes for the interpreter to process the instructions, which is on the order of 200 microseconds for each instruction.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Tracy Allen
    www.emesystems.com
Sign In or Register to comment.