Analog Switch Input

Applies to: IOcan · Standalone controller. What this means

Overview

An Analog Switch Input watches one analog pin and reports true (1024) while the reading sits inside a window you define, false otherwise. It is a level detector, not a position decoder.

That distinction matters, because a multi-position switch needs one Analog Switch Input per position — a five-position rotary is five inputs, each watching its own window on the same pin. There is no single input that reports "which position", and nothing decodes a position number for you. If you want a number rather than a set of booleans, feed the results into an RBC Input or a Mux Input.

Use it for rotary mode switches, multi-button steering controls and resistor-ladder keypads.

A multi-position selector is the usual reason to reach for this type — the analog PRND shifter is built from one Analog Switch Input per position. Wiring concepts covers how a non-standard shifter reaches the device in the first place.

Defining the window

Two mutually exclusive ways, and you fill in only one of them:

  • Voltage mode — you give the window directly, as Min voltage and Max voltage in volts, exactly as for an Analog Input.
  • Resistors mode — you give the external divider's resistor values and a precision, and the device derives the window from them.

Precision is in parts per thousand, not an abstract tolerance: 50 means ±5 %. It is applied to the resistor values before the window is derived, so it widens the window rather than shifting it.

Resistors mode has three special cases that are easy to hit by accident:

Pull-up Pull-down Window
0 0 Empty — the input can never be true.
0 > 0 Near the top of the Range, widened by precision
> 0 0 Near zero, widened by precision
> 0 > 0 Computed from the divider, widened by precision

With precision left at 0, the two single-resistor cases fall back to a fixed narrow window at the top and bottom of the Range respectively.

Prerequisites & hardware

  • A switch on one analog pin that produces a distinct level per position.
  • Each position's nominal level, so you can size the windows without overlap.
  • There is no internal pull-up on this input. In Resistors mode you fit an external pull-up (and optionally a pull-down) to turn the switch's resistance into a voltage, and enter those values. In Voltage mode the switch presents the voltages itself.

Add it in the app

  1. Add a new input and choose Analog Switch Input as the type.
  2. Select the pin, and name it for the position it detects — Mode Sport reads better than Mode Switch once there are five of them.
  3. Set the Range.
  4. Choose the mode and fill in only that mode's fields.
  5. Leave the filter off unless this is a momentary button — see below.
  6. Repeat for every position you need to detect.

Settings reference

Setting Meaning Unit Range / values Notes
Range The voltage that corresponds to a reading of 1024 5 V, Internal 5 V, 12 V, Raw Sets the reference for the window.
Mode How the window is defined Resistors, Voltage The two are mutually exclusive. Any other value produces no input at all.
Pull-up External pull-up resistor forming the divider Ω uint32 Resistors mode. 0 with a pull-down fitted gives a near-full-scale window.
Pull-down External pull-down resistor Ω uint32 Resistors mode. 0 with a pull-up fitted gives a near-zero window.
Min voltage / Max voltage The window, directly V uint32 Voltage mode.
Precision Tolerance applied to the resistor values uint32 Parts per thousand: 50 = ±5 %. Resistors mode.
Enable filter Converts the result into a one-shot event on / off Not a debouncer — see below.
Delay Cycles the level must hold before the event fires cycles (≈ ms) sint32 Filter only.
Hold Inert. Accepted, then overridden by the firmware.
Interspace Cycles before another event may fire cycles (≈ ms) sint32 Filter only.

⚠️ The filter turns a level into a single-cycle pulse. With it on, the input reads 1024 for one cycle after the level has held for Delay, then 0 again even while the switch is still in that position. That is right for a momentary button and wrong for a rotary detent you want to read as a state. Full behaviour: the event filter.

Common settings

Analog Switch Input also uses the shared Name and Pin settings. See Common IO settings.

Example — a five-position rotary, in Voltage mode

The rotary produces roughly 0.5 V, 1.5 V, 2.5 V, 3.5 V and 4.5 V.

Add five Analog Switch Inputs on the same pin, all Range 5 V, Mode Voltage, filter off:

Name Min (V) Max (V)
Mode 1 0.25 1.0
Mode 2 1.0 2.0
Mode 3 2.0 3.0
Mode 4 3.0 4.0
Mode 5 4.0 4.75

The windows meet without overlapping, and the gap at each end catches an open or shorted wire as "no position". Measure the real voltages before committing to the boundaries — the nominal figures on a data sheet rarely survive contact resistance and a long harness.

To turn the five booleans into one number, feed them into a Mux Input selector, or use a Counter Input driven by up/down buttons instead.

Troubleshooting

  • Never true in Voltage mode: measure the pin with the switch in that position. The nominal voltage and the real one differ by more than people expect once harness and contact resistance are in the circuit, and a tight window built on the nominal figure will sit just beside the real reading.
  • Never true in Resistors mode: pull-up and pull-down are both 0, which produces an empty window by construction. Enter the resistors actually fitted.
  • Two positions read true at once: the windows overlap. Tighten them, or lower precision.
  • A position reads true for only an instant: the filter is on. Turn it off for a state; keep it for a button.
  • Nothing changes when the switch moves (Resistors mode): the external pull-up is missing, so the pin never sees a voltage divider.