Mode switching in XOD

Hello,

I would like to ask how to do the switching of three modes with one button.

Thanks.

1 Like

There are many options for this. The best one might depend on the rest of your code; how do you need to signal to your code what the mode is? Probably one of the easiest solutions that is also expandable is to use a count node to keep track of which mode you are in.
image
This uses a tweak-pulse to simulate a button. ‘count’ node initializes and resets to zero, so your “modes” are 0, 1, & 2. The greater-or-equal and defer nodes are to reset to mode 0 when you leave mode 2. The output of the count node indicates your mode.

What to do with the count depends on the rest of your program. Is mode just a speed that requires a different number to feed some other part of the code? nth-input can be used to select the appropriate value. Do you need 3 true/false signals with only the “active” mode being true? You can use 3 ‘equal’ nodes to compare count output to 0, 1, & 2. The same can also be used to send a pulse to activate a specific mode.

You could also use flip-flops to remember which mode you are in, but you will need to use ‘and’ or ‘gate’ nodes to determine which nodes should be set/reset with each button press, you also need a way to initialize the 1st mode on boot, so it ends up quite a bit more complicated.


One possible advantage of this method: you can change how you cycle through modes. For example, you might code the gates to go from mode A to B to C to B to A and repeat (like a transmission shifting gears) rather than just going A B C, then repeat.

1 Like

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.