Shop OBEX P1 Docs P2 Docs Learn Events
How does Spin handle the code in an object file? — Parallax Forums

How does Spin handle the code in an object file?

Bulslayer85Bulslayer85 Posts: 34
edited 2012-04-25 23:45 in Propeller 1
K so i finally got how to refer my main AI code to a gyroscope object, my question is can i call a pub function to get all axis info at once or do i have to dived it into different pubs for each axis? I'm using the 3-axis gyro.Also do i need to have the Var s in my main code or just having them in object work?

Comments

  • Mike GMike G Posts: 2,702
    edited 2012-04-23 07:04
    A few object coding best practices.
    • Methods should do one thing well.
    • All like items (methods, VARs...) should be encapsulated in the same object.

    Doing one thing well could mean reading 3 axis from the gyro. Post your code if you need help.
  • Heater.Heater. Posts: 21,230
    edited 2012-04-25 23:45
    In your calling code define an array of LONGs that will be used to hold data obtained from the gyro object.
    The gyro access function will take one parameter, the address of the array defined above, you can get that address with the @ operator.
    When called the gyro access object will write the data for all three axis to their places in the given array.
    The gyro access function need not even have a return value but it could be used for returning a success/fail indication or some error code.
Sign In or Register to comment.