View Single Post
  #10   Spotlight this post!  
Unread 16-01-2002, 23:07
Jnadke Jnadke is offline
Go Badgers!
#0093
Team Role: Alumni
 
Join Date: Jan 2002
Location: Appleton, WI
Posts: 775
Jnadke is on a distinguished road
Send a message via ICQ to Jnadke Send a message via AIM to Jnadke Send a message via Yahoo to Jnadke
Quote:
Originally posted by Joseph F

...
This may work. I'm not exactly sure about negations in pbasic. It could end up attempting to put in a negative... Use it at your own risk.
...
Uhhh.... that's not a negative sign (unary operator). That's a tilde (inverse operator).

Say you have a value of 0 (binary 00000000). The inverse sign inverses all the bits to 255 (11111111). Simplest way of doing it.

Example: 00010100 = ~11101011


Same concept for toggling relays....
Example:
relay_solenoid var bit
relay_solenoid = 0 'solenoid should be deactivated
relay_solenoid = ~relay_solenoid ' toggle the solenoid state

This code is simpler than using if-then statements to check the current state of the bit. All you're doing is altering it.


Suggestion is to read the stamp manual. I did and I learned more than I ever wanted to know about the PBASIC programming language. Just head over to The PBASIC programming manual and check it out. Be careful, it's 2 mb.

Last edited by Jnadke : 16-01-2002 at 23:16.