RBC Input » History » Version 2
Adam Klama, 06/21/2026 02:34 PM
| 1 | 1 | Adam Klama | # RBC Input |
|---|---|---|---|
| 2 | |||
| 3 | ## Overview |
||
| 4 | An **RBC Input** decodes a **Reflected Binary Code** — better known as |
||
| 5 | [**Gray code**](https://en.wikipedia.org/wiki/Gray_code) — from a set of single-bit |
||
| 6 | inputs into an ordinary integer. |
||
| 7 | |||
| 8 | Gray code is an encoding where consecutive values differ by only **one** bit. It is |
||
| 9 | common on absolute rotary/position encoders and gear-position selectors because |
||
| 10 | only one line changes at a time, so the reading never glitches through a wrong |
||
| 11 | value while the switch moves between positions. |
||
| 12 | |||
| 13 | Each listed input supplies one bit of the Gray code; the input converts the whole |
||
| 14 | set to a plain binary number you can act on. |
||
| 15 | |||
| 16 | ## Prerequisites |
||
| 17 | - The **source inputs** that supply the bits — usually |
||
| 18 | [Digital Inputs](Digital-Input.md), one per encoder/switch line. Create them |
||
| 19 | first. |
||
| 20 | - Each source is read as a bit: a non-zero value is `1`, zero is `0`. |
||
| 21 | - Know the **order** of the lines from most- to least-significant bit. |
||
| 22 | |||
| 23 | ## Add it in the app |
||
| 24 | 1. Add a new input and choose **RBC Input** as the type. |
||
| 25 | 2. Give it a clear **alias** (e.g. `Gear Position`). |
||
| 26 | 3. Add the **bit inputs** in order, most-significant bit first. |
||
| 27 | 4. Check the decoded number against each physical switch position. |
||
| 28 | |||
| 29 | ## Settings reference |
||
| 30 | |||
| 31 | | Setting | Meaning | Unit | Range / values | Notes | |
||
| 32 | |---|---|---|---|---| |
||
| 33 | | **Bit inputs** | Ordered list of single-bit inputs forming the Gray code | — | list of input ids (uint32) | Each input is one bit. The **list order** sets bit significance; the input converts the Gray code to a binary value. | |
||
| 34 | |||
| 35 | **Gray → binary:** the most-significant bit is taken as-is; each lower binary bit |
||
| 36 | is the running XOR of the higher binary bit with the next Gray bit. The result is |
||
| 37 | the ordinary integer (e.g. an 8-position encoder decodes to `0`–`7`). If the value |
||
| 38 | counts the wrong way for your wiring, reverse the order the inputs are listed in. |
||
| 39 | |||
| 40 | ## Common settings |
||
| 41 | RBC Input also uses the shared setting — alias. See |
||
| 42 | [Common IO Settings](../Common-IO-Settings.md). |
||
| 43 | |||
| 44 | ## Example — 3-line Gray-coded gear selector |
||
| 45 | A selector exposes three Gray-coded digital lines, `G2`, `G1`, `G0`. |
||
| 46 | |||
| 47 | 1. Type **RBC Input**, alias `Gear Position`. |
||
| 48 | 2. Add the **bit inputs** in order `G2` (MSB), `G1`, `G0` (LSB). |
||
| 49 | 3. The input converts the Gray code to a binary value `0`–`7`, one per position, |
||
| 50 | with only one line changing between adjacent gears. |
||
| 51 | |||
| 52 | ## Troubleshooting |
||
| 53 | - **Decoded number counts the wrong way:** the bit order is reversed for your |
||
| 54 | wiring — change the order the inputs are listed in. |
||
| 55 | - **One position is always wrong / stuck:** check that line's source input on its |
||
| 56 | own; a stuck bit usually means a wiring or threshold problem at the source. |
||
| 57 | - **Values jump by more than one between positions:** the lines are not actually |
||
| 58 | Gray-coded (or one is mis-ordered) — verify the encoder's coding. |
||
| 59 | - **Unexpected code values:** confirm every intended line is in the list and none |
||
| 60 | is listed twice. |
||
| 61 | |||
| 62 | ## Related |
||
| 63 | - [Digital Input](Digital-Input.md) — the per-line bit sources. |
||
| 64 | - [Mux Input](Mux-Input.md) — select one of several inputs by an index. |
||
| 65 | - [Analog Switch Input](Analog-Switch-Input.md) — decode a multi-position switch on |
||
| 66 | a single analog pin. |