Skip to content

RotaryEncoder

Talbot edited this page Feb 20, 2022 · 7 revisions

Class Name

RotaryEncoderT

Description

A rotating control (incremental quadrature encoder) where the turning action generates a signal CW (Clockwise) or CCW (Counter clockwise). Note that although the rotating knob is similar, this is not to be confused with a rotating potentiometers (absolute positioning) or a multi-position switch. Common examples of rotary encoders are HSI Course knobs, altimeter pressure settings and tacan digit selectors.

Standard Template Name

RotaryEncoder

Constructor

RotaryEncoderT(const char* msg, const char* decArg, const char* incArg, char pinA, char pinB)

  • msg - The message to send to DCS when the encoder is turned.
  • decArg - The argument to send to DCS when the encoder is decremented (turned CCW).
  • incArg - The argument to send to DCS when the encoder is increments (turned CW).
  • pinA - The pin connected to rotary quadrature signal pin A.
  • pinB - The pin connected to rotary quadrature signal pin B.

Template

template <unsigned long pollIntervalMs = POLL_EVERY_TIME, StepsPerDetent stepsPerDetent = ONE_STEP_PER_DETENT>

  • pollIntervalMs - Time in milliseconds between times this control should be sampled. Increase for less time sensitive controls to lower the CPU load required for this control.
  • stepsPerDetent - Number of steps signaled by your encoded per physical position detent. Match this to your hardware to avoid experiencing multiple "turns" in DCS when your rotary is turned. Constants ONE_STEP_PER_DETENT, TWO_STEPS_PER_DETENT, FOUR_STEPS_PER_DETENT and EIGHT_STEPS_PER_DETENT are defined.

Wiring Notes

Note that there are a few common variants of rotary encoders. Firstly the encoder must be a quadrature incremental encoder. Mechanical encoders are the simplest, with just 2 pins and ground required, however be aware that these can have debouncing issues with arduinos and can be difficult to tune. Optical encoders require extra pins for power, but product cleaner signals and are recommended for use.

Also note that the sampling rate of your arduino must be sufficiently fast to detect every change in the encoder position. If you have any slow code in your loop you may experience missed turns.

Lastly, note that many rotary encoders include a push button which can be utilized in DCS BIOS but is to be wired up as a separate button independent of this control.

Example 1

DcsBios::RotaryEncoder hsiCrsKnob("HSI_CRS_KNOB", "-3200", "+3200", 1, 2);

Example 2

typedef DcsBios::RotaryEncoderT<POLL_EVERY_TIME, DcsBios::FOUR_STEPS_PER_DETENT> FourStepRotaryEncoder; // A custom rotary encoder with four quadrature steps per physical detent.

FourStepRotaryEncoder tacan1("TACAN_1", "DEC", "INC", 0, 1);