Toggle?

I see a command in PBASIC called Toggle. From what I understand in reverses the I/O of a pin. I think this could be very useful for FIRST, but I haven’t seen any mention of using it, or any example of it being used in FIRST. I’ve been experimenting with it, but I’m not sure if my syntax is right.

Can anyone give a better explanation of it, its uses, or an example of it being used?

I know I’ve posted too much today but I am really bored.

It acually is used in FIRST. If you look through the default code, you’ll see “Toggle 7.” This is what makes the Basic Run light blink so fast.

About the only thing we could use it for would be reversing one of the LED outputs, as those are the only things connected directly to I/O pins. Anyway, if you do find a use for it, the syntax is just

Toggle X

where X is the pin you want to change. For FIRST, this can only be 7-15, with 7 being the basic run light and 8-15 being the LED outputs that are visible on the OI.

Also, as long as you’re asking valid questions, nobody is going to mind you posting a lot. Asking questions is good–it helps you learn and it helps other people who visit this site sometime later.

–Rob

ok thanks, on a semi-related note:

How do you make a joystick button act like a toggle switch? Where you push and release, but the value stays at 1, and then you push and release again to make the value go back to 0

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.

while it is possible to use toggle on the first bot, it really isnt all that useful. toggle only affects the output pins located on the stamp in the hands of the driver, and it has no effect on the stamp on the bot. since everything is communicated with serin and out, changing the state of the output pins dont do nuttin.

*Originally posted by VanWEric *
**while it is possible to use toggle on the first bot, it really isnt all that useful. toggle only affects the output pins located on the stamp in the hands of the driver, and it has no effect on the stamp on the bot. since everything is communicated with serin and out, changing the state of the output pins dont do nuttin. **

Not quite true. First, if you do a toggle on 1, 2, or 3, chances are everything will go horribly awry as these are the pins used to communicate withe the master uP. However, you CAN do a toggle on 7-15 to change the feedback LEDs. It has exactly the same effect as:

out8=1-out8

The advantage of Toggle is that it’s a little easier to read and a little faster to type.