Project

General

Profile

Analog Switch Input » History » Version 2

Adam Klama, 06/21/2026 02:57 PM

1 1 Adam Klama
# Analog Switch Input
2
3
## Overview
4
An **Analog Switch Input** reads a **multi-position switch** on a single analog
5
pin. Instead of one wire per position, the switch presents a different **voltage**
6
(or **resistance**) for each position, and this input decodes which position is
7
selected. Use it for rotary mode switches, multi-button steering controls and
8
resistor-ladder keypads.
9
10
## Prerequisites & hardware
11
- A switch wired to one analog pin that produces a distinct level per position.
12
- Know each position's nominal value so you can set the recognition tolerance.
13
- **External divider:** the input does **not** provide an internal pull-up. In
14
  **Resistors** mode you fit an **external pull-up** resistor (and optionally a
15
  pull-down) to turn the switch's resistance into a voltage, and enter those
16
  resistor values so the controller can work out the switch resistance. In
17
  **Voltage** mode the switch presents the voltages directly and no divider is
18
  needed.
19
20
## Add it in the app
21
1. Add a new input and choose **Analog Switch Input** as the type.
22
2. Select the **pin** the switch is wired to.
23
3. Give it a clear **alias** (e.g. `Mode Switch`).
24
4. Choose the **mode** and **range**. The two modes are mutually exclusive — pick
25
   whichever suits your hardware:
26
   - **Resistors:** enter the external **pull-up** (and **pull-down**) resistor
27
     values that form the divider.
28
   - **Voltage:** enter the **voltage range** (min/max voltage) the position sits
29
     in.
30
5. Set the **precision** and, for mechanical switches, the debounce timings.
31
32
## Settings reference
33
34
| Setting | Meaning | Unit | Range / values | Notes |
35
|---|---|---|---|---|
36
| **Range** | Input voltage range / scaling reference | — | `5 V`, `Internal 5 V`, `12 V`, `Raw` | Choose to cover the switch's full-scale voltage. `Raw` reports unscaled counts. |
37
| **Mode** | How the position is defined — the two are mutually exclusive | — | `Resistors`, `Voltage` | `Resistors` = an external pull-up/pull-down divider turns the switch resistance into a voltage; `Voltage` = the position is recognised by its voltage range. Configure only the fields for the mode you choose. |
38
| **Pull-up** | Value of the **external** pull-up resistor forming the divider | Ω | uint32 | **Resistors mode only.** Tells the controller the divider's upper leg so it can compute the switch resistance. |
39
| **Pull-down** | Value of the external pull-down resistor | Ω | uint32 | **Resistors mode only.** The lower leg of the divider (optional). |
40
| **Min voltage / Max voltage** | Voltage range for the position | mV | uint32 | **Voltage mode only.** The window the position's voltage falls in. |
41
| **Precision** | Matching tolerance for recognising the position | — | uint32 | How close a reading must be to count as this position. Too loose = wrong position; too tight = missed positions. |
42
| **Enable filter** | Turns on debounce filtering | — | on / off | Recommended for mechanical switches. |
43
| **Delay** | Debounce delay before a change is accepted | ms | sint32 | New position must be stable this long. |
44
| **Hold** | Minimum time a position is held | ms | sint32 | Stops rapid re-triggering. |
45
| **Interspace** | Minimum gap between transitions | ms | sint32 | Ignores transitions closer than this. |
46
47
## Common settings
48
Analog Switch Input also uses the shared settings — alias and pin.
49 2 Adam Klama
See [Common IO Settings](Common_IO_Settings).
50 1 Adam Klama
51
## Example — detect one switch position (Voltage mode)
52
Each Analog Switch Input recognises **one** position/level. This example detects a
53
single rotary position that sits at ~2.5 V:
54
1. Type **Analog Switch Input**, alias `Mode Pos 2`, on the switch's pin.
55
2. Mode `Voltage`, **Range** `5 V`.
56
3. **Min/Max voltage** `2300`/`2700` mV — the window around that position.
57
4. **Precision** moderate so the detent maps cleanly to this position.
58
5. **Enable filter**, **Delay** `20`, **Hold** `30` to settle between detents.
59
60
> To decode every position of a multi-position rotary as its own signal, add one
61
> Analog Switch Input per position — e.g. a 5-position rotary uses 5 inputs, each
62
> watching its own voltage range. That is a valid setup but not the typical use;
63
> most installs detect a single switch level.
64
65
## Troubleshooting
66
- **Wrong position selected / jumps between two:** the levels are too close for the
67
  **precision** — tighten precision or space the positions further apart.
68
- **No position recognised:** in Voltage mode the reading is outside **Min/Max
69
  voltage**; in Resistors mode the entered **pull-up/pull-down** values don't match
70
  the resistors actually fitted.
71
- **Position flickers when turning:** enable the filter and raise **Delay** /
72
  **Interspace**.
73
- **Voltage doesn't change with the switch (Resistors mode):** check the **external
74
  pull-up** is fitted — without it the divider produces no voltage.
75
76
## Related
77 2 Adam Klama
- [Analog Input](Analog_Input) — single analog voltage rather than a switch.
78
- [Digital Input](Digital_Input) — single on/off contact.
79
- [Mux Input](Mux_Input) — select between several inputs by a selector.