Shop OBEX P1 Docs P2 Docs Learn Events
Memsic Program — Parallax Forums

Memsic Program

NewzedNewzed Posts: 2,503
edited 2005-11-04 05:16 in BASIC Stamp
I had to repost this - error in the file heading.

I have modified the Sample code that comes with the Memsic so it displays a reading ONLY if X or Y has changed.· If the Stamp detects that the new X and Y readings are the same as the last displayed readings, then it skips the display.· Really removes a lot of clutter from the debug screen - now you get a reading only when X or Y changes.

Sid

Comments

  • Jon WilliamsJon Williams Posts: 6,491
    edited 2005-11-04 00:21
    The original program used cursor positioning (that you've disabled) so there was no "clutter" in the output. If you simply put the cursor positioning back in you won't have any clutter in your code.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Jon Williams
    Applications Engineer, Parallax
  • NewzedNewzed Posts: 2,503
    edited 2005-11-04 00:24
    I know, but then you could not see the previous reading to see where you were or how fast the tilt was changing.·

    Sid
  • Jon WilliamsJon Williams Posts: 6,491
    edited 2005-11-04 00:26
    Okay, then, but I would suggest that the subroutine (which should simply read the sensor) is not the cleanest place for the decsion -- it should be done in the main loop (and it could be handled far more elegantly using PBASIC 2.5 features).

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Jon Williams
    Applications Engineer, Parallax
  • NewzedNewzed Posts: 2,503
    edited 2005-11-04 00:33
    Do you have time to show me how?· Even at my age, I'm not too old to learn a little.

    Sid
  • Jon WilliamsJon Williams Posts: 6,491
    edited 2005-11-04 01:34
    Just move the comparison to the main loop (pseudo-code):

    · IF (xTilt <> oldX) OR (yTilt <> oldY) THEN
    ··· ' display new values
    ··· oldX = xTilt
    ··· oldY = yTilt
    · ENDIF

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Jon Williams
    Applications Engineer, Parallax
  • Bruce BatesBruce Bates Posts: 3,045
    edited 2005-11-04 05:16
    Sid -

    Just a reminder for use with Jon's otherwise fine routine. Make sure during initialization to do a "first_time_read" of the accelerometer, so that you can initialize the saved variables:

    /code

    first_time_read: 'Prime accelerometer values
    GOSUB Read_Memsic 'Obtain present values for X and Y Tilts
    oldX = xTilt 'Save xTilt
    oldY = yTilt 'Save yTilt

    either that, or guarantee a mis-match by doing this:

    oldY= $FF
    oldY= $FF

    code/

    If I had a nickel for everytime I forgot to inititalize a variable on start-up over the years, I'd be a very rich man!

    Regards,

    Bruce Bates
Sign In or Register to comment.