pdf-icon

Encoder

M5Dial Encoder related APIs and case programs.

Example


#include "M5Dial.h"

void setup() {
    auto cfg = M5.config();
    M5Dial.begin(cfg, true, false);
    M5Dial.Display.setTextColor(GREEN);
    M5Dial.Display.setTextDatum(middle_center);
    M5Dial.Display.setTextFont(&fonts::Orbitron_Light_32);
    M5Dial.Display.setTextSize(2);
}

long oldPosition = -999;

void loop() {
    M5Dial.update();
    long newPosition = M5Dial.Encoder.read();
    if (newPosition != oldPosition) {
        M5Dial.Speaker.tone(8000, 20);
        M5Dial.Display.clear();
        oldPosition = newPosition;
        Serial.println(newPosition);
        M5Dial.Display.drawString(String(newPosition),
                                  M5Dial.Display.width() / 2,
                                  M5Dial.Display.height() / 2);
    }
    if (M5Dial.BtnA.wasPressed()) {
        M5Dial.Encoder.readAndReset();
    }
    if (M5Dial.BtnA.pressedFor(5000)) {
        M5Dial.Encoder.write(100);
    }
}

begin

Syntax:

void begin();

Description:

  • Initialize Encoder IO

This can be initialized by setting the parameter enableEncoder to true when calling M5Dial.begin.

M5Dial.begin(m5::M5Unified::config_t cfg, bool enableEncoder,bool enableRFID)

Parameters:

  • null

Return:

  • null

read

Syntax:

int32_t read()

Description:

  • Read current encoder value

Parameters:

  • null

Return:

  • int32_t:Current encoder value

write

Syntax:

void write(int32_t p)

Description:

  • Write to update encoder value

Parameters:

  • int32_t p:Updated encoder values

Return:

  • null

readAndReset

Syntax:

int32_t readAndReset()

Description:

  • Reset current encoder value

Parameters:

  • null

Return:

  • int32_t:Encoder value before reset
On This Page