Shop OBEX P1 Docs P2 Docs Learn Events
Convert Word To Number — Parallax Forums

Convert Word To Number

kenwtnkenwtn Posts: 250
edited 2008-04-08 23:08 in BASIC Stamp
Can someone tell me how to convert a WORD to a number so it can be used in calculations? The problem I am having is when I use the sample code that comes with Parallax’s compass it defines angle as a word and when displayed in DEBUG you use DEBUG DEC angle, but if you use DEBUG angle you get junk. Can anyone help me out?

Comments

  • Mike GreenMike Green Posts: 23,101
    edited 2008-04-08 21:10
    A word is already in the form needed for use in calculations. The DEC formatter converts the numeric value to a human readable form. When you use "DEBUG angle", the Stamp takes the numeric value and transmits the lower 8 bits as a byte to the debug window where it's displayed as a character. Since the value is an angle, it's probably not a useful character and displays as "junk".
  • kenwtnkenwtn Posts: 250
    edited 2008-04-08 21:14
    Mike,

    · Thanks, but how do get into say 90 degrees so I can test it. Like

    IF angle = 90 THEN

    ·· do something

    ENDIF
  • kenwtnkenwtn Posts: 250
    edited 2008-04-08 21:25
    Ok a bit of a new problem I added

    testA = angle + 5
    DEBUG DEC testA

    Most of the time I get a number that is plus 5 but at times I get a number like 994
  • Mike GreenMike Green Posts: 23,101
    edited 2008-04-08 22:39
    I think your problem is that you're assuming that the angle is in degrees. Check the comments in the sample code.

    On your second problem ... You didn't say where you got the original angle value or what it was. I think you'll find that the + 5 worked fine if you account for the original value.
  • kenwtnkenwtn Posts: 250
    edited 2008-04-08 22:43
    Mike,

    · Thanks as always you are a good source. If found my problem and got it fixed. I do have yet another question. After I calabrated the compass I get about a 18 degree swing in the readings is that normal?
  • Mike GreenMike Green Posts: 23,101
    edited 2008-04-08 23:05
    I think so. The compass isn't that precise. Look at the datasheet for the actual compass chip.
  • kenwtnkenwtn Posts: 250
    edited 2008-04-08 23:08
    I thought is was right and expected some drift. Thanks Mike
Sign In or Register to comment.