You can initialize a RotaryEncoder instance in two ways depending on whether you want to handle hardware pin configuration immediately or manually later.
- With Hardware Initialization: Pass the two encoder pins and a
LatchMode. This automatically configures the pins, enables internal pull-up resistors, and establishes the initial position. - Without Hardware Initialization: Use the constructor that only takes a
LatchMode. This is useful if you want to configure pins manually or use a different initialization strategy.
Use NO_PIN (defined as -1) to skip hardware configuration for a specific pin.
// Hardware initialization (recommended)
RotaryEncoder encoder(2, 3, RotaryEncoder::LatchMode::FOUR0);
// Manual initialization (no hardware setup)
RotaryEncoder encoder(RotaryEncoder::LatchMode::FOUR0);