Skip to main content

Logic Gates and Edge Detection

Once a project has more than a couple of inputs, you'll want to combine them: "fire when both buttons are pressed", "trigger only on the moment a switch closes", "flip a relay when any of three sensors trips". NodeBlue's logic-gates group covers exactly these patterns — small, fast modules that produce a single 0/1 output from one or more 0/1 inputs.

The gates​

NodeBlue ships the seven classic gates. Each has an inputs parameter (default 2, increasable via the right-click Add Input) and a single output:

GateOutput = 1 when…
Andall inputs are 1
Orat least one input is 1
Notinput is 0 (single input)
Nandinputs are not all 1
Norinputs are all 0
Xoran odd number of inputs are 1
Xnoran even number of inputs are 1

Their common parameters are:

ParameterDescription
Nb InputsHow many inputs the gate has (2, 3, 4 …). Right-click → Add Input to grow it.
SyncWhen the gate is evaluated — usually MainLoop for an always-on gate, or InputSync to evaluate only when an input changes.
tip

InputSync is the right pick when the gate drives an action you want to trigger only once per change (e.g. firing a counter increment, sending a serial line). With MainLoop the output is re-asserted every cycle even when nothing has changed.

Some ready-made designs to play with:

Edge detection​

Plain logic gates look at the current state. Sometimes what you actually want is the moment of change — the instant a button is pressed, not the whole time it's held. That's what the Edge module is for:

Edge modeOutput is 1 on…
RisingA 0 → 1 transition.
FallingA 1 → 0 transition.
BothEither transition.

The output is a one-cycle pulse, perfect for feeding a Counter, an InputSync-driven gate, a Serializer, or a "send once" Serial write.

The Examples/10-Logic/Edge example uses an Edge module to step a counter on each button press, and the closely-related EdgeRxLed flashes the RX LED on each detected edge.

tip

When Edge watches a mechanical button, use a Button module rather than a raw DigitalIn — the Button has built-in debouncing, so Edge sees one clean transition per real press. See the discussion in Digital Input / Outputs.

Debouncer​

The Debouncer module produces a clean output from a noisy digital input. It's the same algorithm baked into the Button module, just packaged as a standalone block — useful when the noisy signal isn't from a button (a vibration sensor, a poor-contact switch, an opto-coupler picking up RFI). It exposes the same two strategies as Button:

ModeBehaviour
FastAccept the new value immediately, then ignore further changes for the configured delay. Most reactive.
SafeWait until the value has been stable for the configured delay before accepting it. Slower but rejects more noise.

You do not need to add a Debouncer after a Button — Button already debounces internally. Reach for the standalone module only when the upstream signal isn't already clean.

Combining gates​

The classic way to compose these is to keep raw inputs flowing into small gates whose outputs feed bigger ones. A "two-of-three" voting circuit, for example, is three Ands feeding an Or; an "interlock" is an And that requires both a manual button and an enable switch. There's no limit to the depth — every gate is just a few microcontroller instructions per evaluation.

Logic gates work on 0/1 Booleans. For values — gain, offset, mixing, smoothing, range conversion — the next stop is Operators and Math.