Only one at a time


  • boolean1 (default=false)
  • boolean2 (default=false)
  • booleanN (default=false)


  • boolean1 (default=false)
  • boolean2 (default=false)
  • booleanN (default=false)

Need node, that passes only one “true” boolean at a time.
For example: relay control unit for several relays, that allows only one relay an a same time be active (for power source overload protection)
Node receives booleans and:
In case only one is true - it passes through. (boolean1(in)–true–>boolean1(out)) till input will get false.
In case if two or more inputs are true, node passes the first one, (boolean1(in)–true–>boolean1(out)) and waits till passed boolean will get false.
After it became false, node sends “false” to first to output, and let next in line “true” value pass through

There is no way to specify variadic outputs, so you can’t make a generic node for this. The closest you could do is probably to output a numeric index indicating which output should be active.

You can hard-code your node for a specific value of N.

Basically, you want to know if “this” input is true AND all previous inputs were false. Here is one way that could be coded for 4 input/outputs (it would just repeat for more input/outputs):

That would get pretty large for a lot of nodes, but you can use buses to compact it down:

This code “sets output true for the left-most true input”. If you want to set output true for the 1st true input & hold it until it turns false, it will be quite a bit different. You need to be able to remember which input switched to true first, so you probably need to add flip-flops. Here is one solution:

Note that it does have a bug: If one of the outputs is true, switching its input to false while multiple other inputs are true will flip the output to true for all inputs that are true. One way to fix it would be to tie the nor patch to inputs rather than output values. A side-affect of that would be that if an output is true, it will go false as soon as its input goes false, but no other outputs will go true until all inputs go false, then one input goes true. If two inputs go true at the same time, both outputs will still go true.

One possible fix to make sure only one output is active at a time is to use mutex instead of flip-flop. This will guaranty that only one output is active at a time.

I originally programmed this wiring the input directly to the mutex-state-ACQ pin, but changing the active true pin to false would leave everything false even if there were other true pins. By using input true/false to gate a continuous pulse to the ACQ pin, it allows one of the other true inputs to activate its output when the active input goes false. If you only want an output to go true if its input changed to true while there where no active outputs, drop the gate. Input pins that are true when the active input goes false would then have to go false & back to true to active its output pin (probably not what you would want most of the time).

As you can see…there are many solutions. The “best” solution will depend on which side-affects work better with what you are trying to do. The 1st solution is simplest & fool-proof, but active output pin could change even if the input for the current active output doesn’t go to false (if one of the input pins further left goes true); this is preferable if you want to prioritize your circuits (1st activates if needed, we don’t care about others that were active). The flip-flop implementation has the risk of activating more than one output pin. The mutex solution is more complicated (and probably requires more arduino resources), but may be exactly what you need. I’m sure there are other options as well…

I just realized, using mutex means you can split out each of the input/output pairs.

first-true patch:



Any copies of first-true using the same mutex object will only allow one to be active at a time. There is no need to make custom patches with the correct # of input/outputs, making this MUCH simpler. Creating another mutex object allows you to have another group of input/outputs with their own active output independent of this group. You can also add an output-mutex to first-use to allow daisy-chaining; just link it to mutex-state-MUX’ output pin.

1 Like

Thank you very much! Exactly what i was searching for!

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