Skip to content

Rotary encoder — current position (encoder_get)

What it does: Returns the current position of the encoder already recalculated according to the set scale.

encoder_get

Inputs

  • Field index: encoder instance selection.

Output

  • Number: current position of the selected encoder.

When to use it

  • When reading user input from a rotary controller.
  • For incremental control of values (brightness, volume, setpoint).

Tips and pitfalls

  • The position is a shared value changed in an interrupt, therefore it is read atomically in the implementation.
  • At high rotation speed, it may be necessary to adjust the mechanics or filtration.

Usage example

example_encoder.png

Open example in ESP IDE

Generated Python example

value = encoder1.position