Need to program toggle switch on controller

It was in graphical C.

What programming language are you using?

Algo1, it is pretty simple in Blockly, you can see it here: http://www.robotmesh.com/studio/21767. I set it to only turn one motor off and on using the F Up button, but you could do this for two motors by duplicating this code for another button (like E Up).

Another way, which would be even easier, would be to use separate buttons for each function, like F Up to go forward, F Down to go back, and R Up to stop.

Let us know if we can help any other way.

“sleep for 0.3 seconds” is like a hack here.

It is, kind of, but it was an easy way to deal with long key presses. I changed it using a state variable so you can press as long as you want. (Good to see someone looked at this…) Try http://www.robotmesh.com/studio/21767 to see the modified program.

Sleep ain’t a hack. It’s a poor man’s debounce. Not sure about the remote controller, but for the brain buttons, you can get quite significant oscillation (pressed - not - yes - no, yeeeeees) on press.
You can either devise a complex state machine or just wait a little for the physics to sort the situation out.
Even the RobotC built-in functions are using such “hacky” waits - you turn the motor on, but the inertia causes a delay before it actually moves enough to register.

Yes, but 0.3 sec! Its too big delay. Anyway, don’t take it too seriously :slight_smile:
And its, actually, interesting, whether controller buttons need debounce? Bumper switch?..