pdf-icon

Arduino入門

2. デバイス&サンプル

キャンバス管理

面板パネルパラメータ参数

isEPD

関数プロトタイプ:

bool isEPD(void)

機能説明:

  • パネルがEPDかどうかをチェックします

戻り値:

  • bool:EPD状態
    • true:EPDである
    • false:EPDでない

height

関数プロトタイプ:

int32_t height(void)

機能説明:

  • 現在のパネルの高さを取得します

引数:

  • null

戻り値:

  • int32_t:現在のパネルのピクセル高さ

width

関数プロトタイプ:

int32_t width (void)

機能説明:

  • 現在のパネルの幅を取得します

引数:

  • null

戻り値:

  • int32_t:現在のパネルのピクセル幅

popState

関数プロトタイプ:

void popState(void)

機能説明:

  • 表示属性情報(テキストフォント、カーソル位置など)を一時保存し、pushStateで復元します。

引数:

  • null

戻り値:

  • null

pushState

関数プロトタイプ:

void pushState(void)

機能説明:

  • 以前にpopStateで一時保存した表示属性情報を復元します

引数:

  • null

戻り値:

  • null

setBrightness

関数プロトタイプ:

void setBrightness(uint8_t brightness)

機能説明:

  • 表示パネルの明るさを設定します

引数:

  • brightness:指定する明るさの値(0-255)

戻り値:

  • null

getBrightness

関数プロトタイプ:

uint8_t getBrightness(void)

機能説明:

引数:

  • null

戻り値:

  • uint8_t:明るさの値

setEpdMode

関数プロトタイプ:

void setEpdMode(epd_mode_t epd_mode)

機能説明:

  • EPDモードを設定します

引数:

  • epd_mode:指定するEPDモード

戻り値:

  • null

getEpdMode

関数プロトタイプ:

epd_mode_t getEpdMode(void)

機能説明:

  • setEpdModeで設定したEPDモードを取得します(電子ペーパー製品のみ)

引数:

  • null

戻り値:

  • epd_mode_t:EPDモード値(epd_mode_tについて)

setResolution

関数プロトタイプ1:

bool setResolution(uint16_t logical_width = 0, uint16_t logical_height = 0, float refresh_rate = 0.0f, uint16_t output_width = 0, uint16_t output_height = 0, uint_fast8_t scale_w = 0, uint_fast8_t scale_h = 0, uint32_t pixel_clock = 74250000)

関数プロトタイプ2:

bool setResolution( const config_resolution_t& cfg_resolution )

機能説明:

  • 解像度を設定します。M5AtomDisplay専用です。

引数:

  • logical_width:論理幅
  • logical_height:論理高さ
  • refresh_rate:リフレッシュレート
  • output_width:出力幅
  • output_height:出力高さ
  • scale_w:スケール幅
  • scale_h:スケール高さ
  • pixel_clock:ピクセルクロック周波数
  • cfg_resolution:解像度設定構造体
説明:
cfg_resolutionは上記のすべてのパラメータを含みます。

戻り値:

  • bool
    • true:解像度設定成功
    • false:解像度設定失敗

setRotation

関数プロトタイプ:

void setRotation(uint_fast8_t r)

機能説明:

  • 表示の回転角度を設定します

引数:

  • r:回転角度(0-7)

戻り値:

  • null
説明:
1.回転角度は90°の倍数です。
2.0~3は時計回り、4~7は反時計回り(デフォルト値は1)。
3.表示前に回転角度を設定する必要があります。

getRotation

関数プロトタイプ:

uint8_t getRotation(void)

機能説明:

引数:

  • null

戻り値:

  • uint8_t:現在の回転値
    • 0:0度
    • 1:90度
    • 2:180度
    • 3:270度
    • 4:-0度
    • 5:-90度
    • 6:-180度
    • 7:-270度

カラー

setBaseColor

関数プロトタイプ:

void setBaseColor(T c)

機能説明:

  • ベースカラーを設定します。スクロール機能使用時に描画領域外の色を指定できます。

引数:

  • c:指定するベースカラー

戻り値:

  • null
説明:
1.ベースカラーは通常、スクロール領域外の色塗りに使用されます。
2.ベースカラーの値はパネルのカラーデプスや設定によりRGBや他のカラーフォーマットとなります。

getBaseColor

関数プロトタイプ:

uint32_t getBaseColor(void)

機能説明:

  • setBaseColorで設定したベースカラーを取得します

引数:

  • null

戻り値:

  • uint32_t:ベースカラー値

setColor

関数プロトタイプ1:

void setColor(uint8_t r, uint8_t g, uint8_t b)

関数プロトタイプ2:

void setColor(T color)

機能説明:

  • 描画塗りつぶし色を設定します。fillCircleなどで色パラメータが未設定の場合、この関数で設定した色で塗りつぶし円を描画します。

引数:

  • r:赤成分(0-255)
  • g:緑成分(0-255)
  • b:青成分(0-255)
  • color:カラーコード

戻り値:

  • null

setRawColor

関数プロトタイプ:

void setRawColor(uint32_t c)

機能説明:

  • 生のカラー値を設定します。RGBカラーコードを直接使用する場合に適用されます。

引数:

  • c:カラーコード

戻り値:

  • null

getRawColor

関数プロトタイプ:

uint32_t getRawColor(void)

機能説明:

  • setRawColorで設定した生のカラー値を取得します

引数:

  • null

戻り値:

  • uint32_t:生のカラー値

setColorDepth

関数プロトタイプ1:

void setColorDepth(uint8_t bpp)

関数プロトタイプ2:

void* setColorDepth(color_depth_t depth)

機能説明:

  • カラーデプスを設定します

引数:

  • bpp: ピクセルあたりのビット数
    • 1: 1ビット
    • 2: 2ビット
    • 4: 4ビット
    • 8: 8ビット
    • 16: 16ビット
    • 24: 24ビット
    • 32: 32ビット
  • depth: カラーデプス(color_depth_tについて)
注意事項:
パレットや電子ペーパー製品を使用する場合、カラーデプスは最大8ビットです。

getColorDepth

関数プロトタイプ:

color_depth_t getColorDepth(void)

機能説明:

引数:

  • null

戻り値:

  • color_depth_t:カラーデプス値

getPalette

関数プロトタイプ:

RGBColor* getPalette(void)

機能説明:

  • 現在のパレット情報を取得します

引数:

  • null

戻り値:

  • RGBColor*:bgr888_t構造体へのポインタ、現在のパレットの最初の色を指します

getPaletteCount

関数プロトタイプ:

uint32_t getPaletteCount(void)

機能説明:

  • パレットの色数を取得します

引数:

  • null

戻り値:

  • uint32_t:パレットの色数

画面クリア

clear

関数プロトタイプ:

void clear(const T &color)

機能説明

  • 表示をクリアします。色を指定した場合、その色で画面を初期化します。clearDisplayfillScreenと同じ効果です。

引数:

戻り値:

  • null

clearDisplay

関数プロトタイプ:

void clearDisplay(uint32_t color = 0)

機能説明:

  • 表示をクリアします。色を指定した場合、その色で画面を初期化します。指定しない場合はデフォルト色を使用します。fillScreenclearと同じ効果です。

引数:

戻り値:

  • null

fillScreen

関数プロトタイプ:

void fillScreen(const T &color)

機能説明:

  • 表示をクリアします。色を指定した場合、その色で画面を初期化します。clearclearDisplayと同じ効果です。

引数:

  • color:塗りつぶしカラー

戻り値:

  • null

座標設定

setCursor

関数プロトタイプ1:

void setCursor(int16_t x, int16_t y)

関数プロトタイプ2:

void setCursor(int16_t x, int16_t y, uint8_t font)
void setCursor( int32_t x, int32_t y, const IFont* font)

機能説明:

  • カーソル位置を設定します

引数:

  • x:カーソルx座標
  • y:カーソルy座標
  • font:テキストフォント形式

戻り値:

  • null

getCursorX

関数プロトタイプ:

int32_t getCursorX(void)

機能説明:

  • 現在のカーソルのx座標位置を取得します

引数:

  • null

戻り値:

  • int32_t:現在のカーソルのx座標位置

getCursorY

関数プロトタイプ:

int32_t getCursorY(void)

機能説明:

  • 現在のカーソルのy座標位置を取得します

引数:

  • null

戻り値:

  • int32_t:現在のカーソルのy座標位置

setPivot

関数プロトタイプ:

void setPivot(float x, float y)

機能説明:

  • 基準点座標を設定します

引数:

  • x:基準点x座標
  • y:基準点y座標

戻り値:

  • null

getPivotX

関数プロトタイプ:

float getPivotX(void)

機能説明:

  • x軸の中心点座標を取得します

引数:

  • null

戻り値:

  • float:x軸の中心点座標

getPivotY

関数プロトタイプ:

float getPivotY(void)

機能説明:

  • y軸の中心点座標を取得します

引数:

  • null

戻り値:

  • float:y軸の中心点座標

キャンバス領域選択

setAddrWindow

関数プロトタイプ:

void setAddrWindow(int32_t x, int32_t y, int32_t w, int32_t h)

機能説明:

注意事項:
setWindowと同じ機能ですが、パラメータが異なります。setAddrWindowは画面外のオーバーフローをチェックしますが、setWindowはチェックしません。

引数:

  • x:指定するx座標
  • y:指定するy座標
  • w:指定する幅
  • h:指定する高さ

戻り値:

  • null

setWindow

注意事項:
setAddrWindowと同じ機能ですが、パラメータが異なります。setAddrWindowは画面外のオーバーフローをチェックしますが、setWindowはチェックしません。

関数プロトタイプ:

void setWindow(uint_fast16_t xs, uint_fast16_t ys, uint_fast16_t xe, uint_fast16_t ye)

機能説明:

引数:

  • xs:開始点x座標
  • ys:開始点y座標
  • xe:終了点x座標
  • ye:終了点y座標

戻り値:

  • null

setAddrWindow

関数プロトタイプ:

void setAddrWindow(int32_t x, int32_t y, int32_t w, int32_t h)

機能説明:

注意事項:
setWindowと同じ機能ですが、パラメータが異なります。setAddrWindowは画面外のオーバーフローをチェックしますが、setWindowはチェックしません。

引数:

  • x:指定するx座標
  • y:指定するy座標
  • w:指定する幅
  • h:指定する高さ

戻り値:

  • null

setWindow

注意事項:
setAddrWindowと同じ機能ですが、パラメータが異なります。setAddrWindowは画面外のオーバーフローをチェックしますが、setWindowはチェックしません。

関数プロトタイプ:

void setWindow(uint_fast16_t xs, uint_fast16_t ys, uint_fast16_t xe, uint_fast16_t ye)

機能説明:

引数:

  • xs:開始点x座標
  • ys:開始点y座標
  • xe:終了点x座標
  • ye:終了点y座標

戻り値:

  • null

setClipRect

関数プロトタイプ:

void setClipRect(int32_t x, int32_t y, int32_t w, int32_t h)

機能説明:

  • 描画領域のクリッピング矩形を指定します

引数:

  • x:指定するx座標
  • y:指定するy座標
  • w:指定する幅
  • h:指定する高さ

戻り値:

  • null

getClipRect

関数プロトタイプ:

void getClipRect(int32_t *x, int32_t *y, int32_t *w, int32_t *h)

機能説明:

  • setClipRectで設定したクリッピング領域を取得します

引数:

  • x:x座標へのポインタ
  • y:y座標へのポインタ
  • w:幅へのポインタ
  • h:高さへのポインタ

戻り値:

  • null

clearClipRect

関数プロトタイプ:

void clearClipRect(void)

機能説明:

引数:

  • null

戻り値:

  • null

キャンバススクロール

scroll

関数プロトタイプ:

void scroll(int_fast16_t dx, int_fast16_t dy)

機能説明:

  • 表示画面をスクロールします

引数:

  • dx:X軸方向のスクロール距離
  • dy:Y軸方向のスクロール距離

戻り値:

  • null

サンプルプログラム:

cpp
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31
#include <Arduino.h>
#include <M5GFX.h>

M5GFX display;
uint16_t x;
uint16_t y;
bool flag = false;

void setup()
{
    display.begin();
    display.drawString("        Scrolling...      ", 0, 0, &fonts::lgfxJapanGothic_24);
}

void loop()
{
    if(flag)
    {
        for (int i=-53; i<=53; i+=1) {
            display.scroll(0, -2);
            if(i>=53){ flag = false; }
        }
    }
    else
    {
       for (int i=-53; i<=53; i+=1) {
            display.scroll(0, 2);
            if(i>=53){ flag = true; }
        } 
    }
}

setTextScroll

関数プロトタイプ:

void setTextScroll(bool scroll)

機能説明:

  • テキストスクロールを設定します

引数:

  • scroll:テキストスクロールフラグ

戻り値:

  • null

setScrollRect

注意事項:
テキストスクロール範囲を設定するにはsetTextScroll(true)を使用してください。

関数プロトタイプ:

void setScrollRect(int32_t x, int32_t y, int32_t w, int32_t h, const T& color)

機能説明:

  • テキストスクロール範囲を設定します

引数:

  • x:スクロール範囲開始点x座標
  • y:スクロール範囲開始点y座標
  • w:スクロール幅
  • h:スクロール高さ
  • color:スクロールカラー

戻り値:

  • null

getScrollRect

関数プロトタイプ:

void getScrollRect(int32_t *x, int32_t *y, int32_t *w, int32_t *h)

機能説明:

  • setScrollRectで設定したスクロール領域を取得します

引数:

  • x:x座標へのポインタ
  • y:y座標へのポインタ
  • w:幅へのポインタ
  • h:高さへのポインタ

戻り値:

  • null

clearScrollRect

関数プロトタイプ:

void clearScrollRect(void)

機能説明:

  • setScrollRectで描画したスクロール矩形をクリアします

引数:

  • null

戻り値:

  • null

サンプルプログラム 1 :

cpp
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32
#include <Arduino.h>
#include <M5GFX.h>

M5GFX display;
uint32_t count = 0;

void setup() {
    display.begin();
    display.setRotation(1);
    if(display.isEPD())
    {
        display.setColorDepth(8);//電子ペーパー製品は最大8ビットのビット深度をサポートします。
        display.setEpdMode(epd_fastest);
    }
    else
    {
        display.setColorDepth(16);
    }

    display.fillScreen(TFT_WHITE);
    display.setBaseColor(TFT_WHITE);
    display.setTextFont(&fonts::FreeMonoBoldOblique18pt7b);
    display.setTextColor(TFT_BLACK);
    display.setTextScroll(true);
    display.setScrollRect(0, 0, display.width(), display.height());
}

void loop() {
  display.printf("Scroll: %d\n", count);
  count++;
  delay(500);
}
  • 以下の2つのサンプルプログラムの最終的な実現を比較することで、Canvasを使用する利点が分かります。

サンプルプログラム 2 (Display):

cpp
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40
#include <Arduino.h>
#include <M5GFX.h>

M5GFX display;
uint16_t w;
uint16_t h;
static constexpr char text[] = "Hello world ! This is M5Stack scroll test.";
static constexpr size_t textlen = sizeof(text) / sizeof(text[0]);
int textpos = 0;
int scrollstep = 2;

void setup()
{
  display.begin();
  display.setRotation(3);
  display.setBaseColor(TFT_WHITE);
  display.fillScreen(TFT_WHITE);
  display.setFont(&fonts::FreeMonoBoldOblique24pt7b);
  display.setTextColor(TFT_BLACK);
  w = display.width() / 2;
  h = display.height() / 2;
}

void loop()
{
  int32_t cursor_x = display.getCursorX() - scrollstep;
  if (cursor_x <= 0)
  {
    textpos = 0;
    cursor_x = 0;
  }

  display.setCursor(cursor_x, h-24);
  display.scroll(-scrollstep, 0);
  while (textpos < textlen && cursor_x <= display.width())
  {
    display.print(text[textpos++]);
    cursor_x = display.getCursorX();
  }
}

サンプルプログラム 3 (Canvas):

cpp
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47
#include <Arduino.h>
#include <M5GFX.h>

M5GFX display;
M5Canvas canvas(&display);
uint16_t w;
uint16_t h;
static constexpr char text[] = "Hello world ! This is M5Stack scroll test.";
static constexpr size_t textlen = sizeof(text) / sizeof(text[0]);
int textpos = 0;
int scrollstep = 2;

void setup()
{
  display.begin();
  display.setRotation(3);
  display.fillScreen(TFT_WHITE);

  canvas.createSprite(display.width() + 64, 108);
  canvas.fillSprite(TFT_WHITE);
  canvas.setBaseColor(TFT_WHITE);
  canvas.setFont(&fonts::FreeMonoBoldOblique24pt7b);
  canvas.setTextColor(TFT_BLACK);
  canvas.setTextSize(1.5);
}

void loop()
{
  int32_t cursor_x = canvas.getCursorX() - scrollstep;
  if (cursor_x <= 0)
  {
    textpos = 0;
    cursor_x = display.width();
  }

  canvas.setCursor(cursor_x, 0);
  canvas.scroll(-scrollstep, 0);
  while (textpos < textlen && cursor_x <= display.width())
  {
    canvas.setColor(TFT_BLACK);
    canvas.print(text[textpos++]);
    cursor_x = canvas.getCursorX();
  }

  int y = (display.height() - canvas.height()) >> 1;
  canvas.pushSprite(&display, 0, y);
}

カスタム処理

effect

関数プロトタイプ:

void effect(int32_t x, int32_t y, int32_t w, int32_t h, TFunc&& effector)

機能説明:

  • 指定した矩形範囲にカスタム変換関数で効果処理を行います

引数:

  • x:矩形開始点x座標
  • y:矩形開始点y座標
  • w:矩形幅
  • h:矩形高さ
  • effector:変換関数(ユーザー定義)

戻り値:

  • null
On This Page