1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

M5StackのUnit EncoderをM5Unifiedと共に使うClass

Last updated at Posted at 2023-11-09

はじめに

前回、M5StackのUnit Encoderのファームウェアをアップデートしました。追加された機能が使えて、いつも利用しているM5Unifiedと連携できるクラスがほしかったので作りました。M5Unifiedの書き方に準じつつ、Unit EncoderのExampleのメンバ関数とだいたい同じ感じになるようにしています。

ライブラリ共有

GitHubにリポジトリを作りました。lib/UnitEncoder_Class/UnitEncoder_Class.cppが該当します。platformioのプロジェクトの形になってます。

初期化

setup関数でbegin()をコールしてください。PORT.AのI2Cに繋がっているものとして初期化されます。

main.cpp
#include <M5Unified.h>
#include <UnitEncoder_Class.hpp>

m5::UnitEncoder_Class UnitEncoder;

void setup()
{
  auto cfg = M5.config();
  M5.begin(cfg);
  UnitEncoder.begin();
}

メンバ関数

setEncoderMode (V1.1)

void setEncoderMode(encoder_mode_t mode);

ロータリーエンコーダーのモードを設定します。

パラメータ

  • mode :
name 説明
m5::UnitEncoder_Class::encoder_mode_t::mode_pulse 時計回りはカウントアップ、反時計回りはカウントダウンします。
m5::UnitEncoder_Class::encoder_mode_t::mode_ab 絶対角度

getEncoderValue

signed short int getEncoderValue();

ロータリーエンコーダーの値を取得します。setEncoderMode()の設定によって取得できる値は変わります。

戻り値

  • ロータリーエンコーダーの値

setEncoderValue (V1.1)

bool setEncoderValue(signed short int value);

ロータリーエンコーダーの値を設定します。起動直後は0が設定されています。

パラメータ

  • value : -32768 ~ 32767

戻り値

  • 成功したかどうか

getButtonStatus

bool getButtonStatus();

ボタンが押されているかどうかを取得します。

戻り値

  • 押下状態

setLEDColor

void setLEDColor(uint8_t index, uint32_t color);

LED色を設定します。

パラメータ

  • index : LED番号
    • 0: すべてのLED
    • 1: LED1
    • 2: LED2
    • その他: 未定義
  • color : 0x00RRGGBBの順のフルカラー指定

resetCounter (V1.1)

bool resetCounter();

リセットします。

戻り値

  • 成功したかどうか

おわりに

今後も手持ちのM5Stackモジュールを、M5Unified対応にして使っていきたいと思います。少ししか持っていませんけど。

1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?