Thread: Toggle?
View Single Post
  #4   Spotlight this post!  
Unread 01-11-2002, 18:34
rbayer's Avatar Unsung FIRST Hero
rbayer rbayer is offline
Blood, Sweat, and Code
no team (Teamless Orphan)
 
Join Date: Mar 2002
Rookie Year: 2001
Location: Minnetonka, MN
Posts: 1,087
rbayer is a glorious beacon of lightrbayer is a glorious beacon of lightrbayer is a glorious beacon of lightrbayer is a glorious beacon of lightrbayer is a glorious beacon of light
Send a message via AIM to rbayer
OK, here's some basic code for doing this with p1_sw_trig.


In itit section:
p1_sw_trig_old var bit
p1_sw_trig_old=0
p1_sw_trig_toggleVal var bit
p1_sw_trig_toggleVal=0

Sometime after serin:
if((p1_sw_trig=0) or (p1_sw_trig_old=1)) then dontToggleValue
p1_sw_trig_toggleVal=1-p1_sw_trig_toggleVal
dontToggleValue:


Sometime before serout
p1_sw_trig_old=p1_sw_trig


Using this code, the value of p1_sw_trig_toggleVal will flip between 0 and 1 everytime you press the trigger. If you want to do some other action (such as incremement some form of counter), replace p1_sw_trig_toggleVal=1-p1_sw_trig_toggleVal with the appropriate code. If you have any questions about this, please go ahead and ask. I should be able to answer within a few hours at the most.
__________________
New C-based RoboEmu2 (code simulator) available at: http://www.robbayer.com/software.php