Negative Help!
Commander_Bob
Posts: 17
I have been trying to get my 3 Axis accelerometer to work with positive and negative numbers and use commands like > or < but if I do something like 1 > -1 it says false and when I use debug it says -1 = 65535. How can I make the BS2 know it is a negative number and use this code?
IF··Gforce < -110 THEN
HIGH 3
ELSE
LOW 3
ENDIF
Thanks
IF··Gforce < -110 THEN
HIGH 3
ELSE
LOW 3
ENDIF
Thanks
Comments
The numbers in a word variable range from 0 to 65535. When you want to think about negative numbers using a word variable you split the 65535 in half. You then have 32768 positive numbers and 32768 negative numbers. Remember zero is one of the positive numbers so really 65536/2 so the range is 0 thru 32767 positive and 32768 thru 65535 represent negative numbers.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Think Inside the box first and if that doesn't work..
Re-arrange what's inside the box then...
Think outside the BOX!
sign = zg.BIT15
IF (sign = 0) AND (ABS(zg) > 0) THEN
HIGH 3
ELSE
LOW 3
ENDIF