Skip to main content

Operators and Math

Logic gates handle the 0/1 decisions; what handles values is the operator group — gain, offset, mixing, comparison, range conversion, low-pass filtering and the few sundries that don't fit anywhere else. They're the small black boxes that turn raw sensor readings into the kind of clean number a downstream module can act on.

The group splits cleanly along data type. Integer operators (u8 / s16 / u16 / u32) stay in the integer domain and run a hair faster; the Float variants do their arithmetic in f32 and accept floating-point inputs. Pick the one that matches the rest of your signal chain — the IDE shows port colours so you can see at a glance whether two ports speak the same type.

Arithmetic basics​

These four cover most of what you'll need:

ModuleWhat it does
OpGain / FloatGainMultiplies the input by a constant gain factor.
OpOffset / FloatOffsetAdds a constant offset to the input.
OpMixer / FloatMixerSums several inputs (each with its own gain), one output.
FloatSumTrivial multi-input sum (no per-input gain).

Mixer is the workhorse for sensor fusion, audio-style cross-fading, simple PID summing, and any "a · x + b · y + c · z" combination — its inputs parameter increases with right-click → Add Input, like the logic gates.

The Examples/05-Control/P_Controller project demonstrates a proportional controller built from a Gain and a Mixer.

Range mapping​

Real signals rarely come in the units a downstream module expects. ADCs give you 0..65535; the dashboard wants 0..100; a PWM wants 0..255. The Range family converts between them:

ModuleWhat it does
RangeLinear remap from one numeric range to another (e.g. ADC 0..65535 → percentage 0..100).
RangeModuleSame idea, but with the input range learned by calibration (drive it through its extremes once, save).
RangeDeadZoneRange remap with configurable dead zones at the low and high ends of travel — designed for pedals so the mechanical hard-stops reliably read 0 % and 100 %.
FloatRangeThe floating-point variant — handy when you're converting to a physical unit (e.g. ADC code → volts).

Range parameters are uniform:

ParameterDescription
Min in / Max inThe input range.
Min out / Max outThe output range it maps to.
ClampWhether to clip outputs that fall outside Min out / Max out, or extrapolate.

RangeModule's Calibration input is what makes it special: pulse the calibration input to enter learning mode, sweep the source through its physical extremes, pulse it again to leave. The min/max it learned are persisted to EEPROM and applied on the next boot. This is exactly how the IDE's game-controller axis calibration works.

Smoothing — FloatIIRFilter​

Noisy sensors (loadcells, magnetometers, anything analog at a high gain) need smoothing before you act on them. FloatIIRFilter is a first-order infinite-impulse-response low-pass — one tuning knob (the time constant or alpha) and a value going in, a smoothed value coming out.

The trade-off is the classic one: a longer time constant smooths more but adds more lag. Start with something like 100 ms for a sensor you'll display, 10 ms for something in a real-time control loop, and tune from there.

Comparator​

Sometimes you need a Boolean answer from a value: "is this above a threshold?", "is this between these two bounds?". The Comparator does that.

Comparison modeOutput is 1 when…
> / <Input is above / below a configured threshold.
>= / <=Same, inclusive.
== / !=Input equals / differs from a target value.
In rangeInput is between two bounds.
Out of rangeInput is outside two bounds.

A Comparator feeding an Edge gives you the moment a threshold is crossed — typical for tripping a relay, sending an alert, or stepping a counter.

Counter​

The Counter module counts events on its input. Each rising edge of the input increments the internal counter; reaching the configured maximum optionally wraps around or triggers an output pulse.

ParameterDescription
MaxThe value at which the counter wraps (or stops, depending on mode).
Reset on overflowWhether to wrap to 0 or stop.

Pair it with an Edge when the input is a level (a button), so you count presses rather than the entire time the button is held. The Examples/01-Basics/Counter design is the minimal demo.

TypeCast​

When two modules speak different numeric types, TypeCast is the explicit converter. Most of the time NodeBlue's wire-colour matching makes the conversion automatic; reach for TypeCast when you want to control rounding, signedness or saturation explicitly (e.g. an f32 from a filter to a u16 for a PWM register).

Constant and Sync​

Two tiny utilities that round out the group:

  • Constant — emits a fixed numeric value, configured in its parameters. Handy as the "b" in a + b (paired with a Mixer or Offset) when the value is hand-tuned rather than read from somewhere.
  • Sync — the named sync source covered in Timers / Sync signals. Driven by a timer once, referenced by name from many consumers.

Once a value is shaped the way you want it, the next thing you'll often do is turn it into something humans can read — see Strings and Text.