Shop OBEX P1 Docs P2 Docs Learn Events
PBasic Question. Please Help! — Parallax Forums

PBasic Question. Please Help!

koolitudekoolitude Posts: 37
edited 2007-02-22 21:26 in BASIC Stamp
The following statement was used to display the compass bearing obtained from a digital compass.

DEBUG· 2,0,1, "Compass Bearing (0-359 Degrees ", DEC3 I2cData/10

This does work. But my question is how can·I store the value of (DEC3 I2cData/10)·for further manipulation?

I wanna write a program such that when the bearing = certain degree then do something else.

I tried to declare another variable to store the value:
Bearing VAR·Word
Bearing = DEC3 I2cData/10

Then I got an error message:
Expected a constant, variable, unary operator, or '('

and the code DEC3 was highlighted:
Bearing = DEC3 I2cData/10

Please Help! Thanks you very much!
·

Comments

  • LarryLarry Posts: 212
    edited 2007-02-21 09:12
    you'll need to post the rest of your code. It probably has to do with either an if- then or case statement, or how you read the compass.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
  • Bruce BatesBruce Bates Posts: 3,045
    edited 2007-02-21 10:50
    koolitude -

    Right idea, but the wrong syntax. Try this:

    Bearing VAR Word

    Then after the bearing is fetched
    :
    Bearing = I2cData

    That's all there is to it. After that, it's just a matter of checking Bearing for whatever value you need to check, like these examples:

    IF Bearing > 180 AND Bearing < 270 THEN GOTO SomeLabel 'One line format

    or

    IF Bearing < 90 OR Bearing > 180 THEN· 'Multi-line format:

    · Count = Count + 1
    · Flag = 1

    ELSE

    · Count = Count -1
    · Flag = 0

    etc.

    Regards,

    Bruce Bates
  • koolitudekoolitude Posts: 37
    edited 2007-02-22 05:23
    Thank you, Larry!

    Thank you Bruce! I can now compile the program~ so... the problem was adding DEC3 in front of I2cData, right?

    DEC3 is only used for formatting in the debug windows? am I right?
  • Mike GreenMike Green Posts: 23,101
    edited 2007-02-22 05:54
    DEC3 (and the other formatting prefixes) are used in input/output statements like DEBUG. Look in the PBasic manual under SERIN/SEROUT.
  • Chris SavageChris Savage Parallax Engineering Posts: 14,406
    edited 2007-02-22 21:26
    To elaborate a bit on Mike’s reply, those affect serial data, so they can be used in commands like DEBUG and SERIN/SEROUT to convert the binary value into an ASCII string. Take care.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Chris Savage
    Parallax Tech Support
Sign In or Register to comment.