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:
| Gate | Output = 1 when… |
|---|---|
| And | all inputs are 1 |
| Or | at least one input is 1 |
| Not | input is 0 (single input) |
| Nand | inputs are not all 1 |
| Nor | inputs are all 0 |
| Xor | an odd number of inputs are 1 |
| Xnor | an even number of inputs are 1 |
Their common parameters are:
| Parameter | Description |
|---|---|
| Nb Inputs | How many inputs the gate has (2, 3, 4 …). Right-click → Add Input to grow it. |
| Sync | When the gate is evaluated — usually MainLoop for an always-on gate, or InputSync to evaluate only when an input changes. |
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:
- Examples/10-Logic/And — two buttons must both be pressed to light the LED.
- Examples/10-Logic/Or — either button lights the LED.
- Examples/10-Logic/Nor — the LED is on as long as neither button is pressed.
- Examples/10-Logic/Not — a button that turns the LED off instead of on.
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 mode | Output is 1 on… |
|---|---|
| Rising | A 0 → 1 transition. |
| Falling | A 1 → 0 transition. |
| Both | Either 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.
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:
| Mode | Behaviour |
|---|---|
| Fast | Accept the new value immediately, then ignore further changes for the configured delay. Most reactive. |
| Safe | Wait 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.