Rotary Encoder
The Inkplate 6 MOTION includes a AS5600 magnetic rotary encoder, which allows precise rotation tracking. It is ideal for navigating menus or fine tuning numerical input values.
The dial made to interface with the rotary encoder is transparent! It's made this way so that the first onboard RGB LED can change it's color when it lights up!
AS5600
Arduino library for AS5600 and AS5600L magnetic rotation meter
Initializaiton
Before using the rotary encoder, it must be powered on and initialized.
// Enable power to the rotary encoder
inkplate.peripheralState(INKPLATE_PERIPHERAL_ROTARY_ENCODER, true);
delay(100);
// Initialize rotary encoder
inkplate.rotaryEncoder.begin();
inkplate.rotaryEncoder.begin()
Initializes the rotary encoder sensor for use. This function must be called before retrieving values.
Returns: Returns true if initialization was successful, otherwise false.
Reading the rotation angle
To get the current angle of the rotary encoder in degrees:
int currentValue = (int)(inkplate.rotaryEncoder.rawAngle() * AS5600_RAW_TO_DEGREES);
This will return the current rotational position of the encoder.
inkplate.rotaryEncoder.rawAngle()
Gets the raw angle value from the rotary encoder, which can be converted to degrees or radians.
Returns: Returns the raw angle as a 12-bit integer (0-4095).
You can use the following factors for conversion:
Conversion | Constant | Value |
---|---|---|
Raw to Degrees | AS5600_RAW_TO_DEGREES | 360.0 / 4096 (0.087890625 ) |
Raw to Radians | AS5600_RAW_TO_RADIANS | PI * 2.0 / 4096 (0.00153398079 ) |
Full Example
This example tracks the rotary encoder's angle and updates the display when the angle changes by 2 degrees:
Inkplate_6_MOTION_Rotary_Encoder.ino
Full rotary encoder example in the Inkplate library