Shop OBEX P1 Docs P2 Docs Learn Events
Problem with CASE — Parallax Forums

Problem with CASE

MichelBMichelB Posts: 154
edited 2009-05-24 16:10 in BASIC Stamp
Hi, I wrote a small program giving position in degrees of my standard servo. For example when I type 60, CASE 60, duration = 450·the horn turns clockwise at 60 degrees but when I type -90 i.e. CASE -90, duration = 1180 the horn turns clockwise at 90 degrees instead of 90 degrees counterclockwise expected. CASE does not accept negative numbers? Thank you in advance for help.

Comments

  • Mike GreenMike Green Posts: 23,101
    edited 2009-05-24 14:48
    The Stamps do unsigned 16 bit arithmetic. It's possible to do a little signed arithmetic if you understand what you're doing. Are you using the SDEC formatter in your SERIN or DEBUGIN statement? DEC only handles unsigned numbers and will read "-90" as 0 followed by 90.

    The CASE should work because it's using an equal (exact) comparison with -90.
  • MichelBMichelB Posts: 154
    edited 2009-05-24 16:10
    Thank you very much Mike, it runs very well with SDEC. I'm going to learn difference between signed and unsigned, DEC and SDEC.
Sign In or Register to comment.