pdf-icon

Arduino入門

2. デバイス&サンプル

図形描画

線形図形

drawArc

関数プロトタイプ1:

void drawArc(int32_t x, int32_t y, int32_t r0, int32_t r1, float angle0, float angle1)

関数プロトタイプ2:

void drawArc(int32_t x, int32_t y, int32_t r0, int32_t r1, float angle0, float angle1, const T &color)

機能説明:

  • 円弧を描画します。r0、r1が異なる場合は太い円弧を描画します。

引数:

  • x:円弧中心の x 座標
  • y:円弧中心の y 座標
  • r0:内円半径
  • r1:外円半径
  • angle0:円弧の開始角度
  • angle1:円弧の終了角度
  • color:円弧の色(カラーコード 参照)

戻り値:

  • null

drawBezier

関数プロトタイプ1:

void drawBezier( int32_t x0, int32_t y0, int32_t x1, int32_t y1, int32_t x2, int32_t y2, const T& color)

関数プロトタイプ2:

void drawBezier( int32_t x0, int32_t y0, int32_t x1, int32_t y1, int32_t x2, int32_t y2)

関数プロトタイプ3:

void drawBezier( int32_t x0, int32_t y0, int32_t x1, int32_t y1, int32_t x2, int32_t y2, int32_t x3, int32_t y3, const T& color)

関数プロトタイプ4:

void drawBezier( int32_t x0, int32_t y0, int32_t x1, int32_t y1, int32_t x2, int32_t y2, int32_t x3, int32_t y3, const T& color)

機能説明:

  • ベジェ曲線を描画します。3点型と4点型の2種類があります。

引数:

  • xN: 描画点の x 座標
  • yN:描画点の y 座標
  • color:曲線の色(カラーコード 参照)

戻り値:

  • null

drawCircle

関数プロトタイプ1:

void drawCircle( int32_t x, int32_t y, int32_t r)

関数プロトタイプ2:

void drawCircle( int32_t x, int32_t y, int32_t r, const T& color)

機能説明:

  • 円を描画します

引数:

  • x:円の中心 x 座標
  • y:円の中心 y 座標
  • r:円の半径
  • color:円の色(カラーコード 参照)

戻り値:

  • null

drawEllipse

関数プロトタイプ1:

void drawEllipse( int32_t x, int32_t y, int32_t rx, int32_t ry)

関数プロトタイプ2:

void drawEllipse( int32_t x, int32_t y, int32_t rx, int32_t ry, const T& color)

機能説明:

  • 楕円を描画します

引数:

  • x:楕円中心の x 座標
  • y:楕円中心の y 座標
  • rx:楕円の長半径
  • ry:楕円の短半径
  • color:楕円の色(カラーコード 参照)

戻り値:

  • null

drawEllipseArc

関数プロトタイプ1:

void drawEllipseArc( int32_t x, int32_t y, int32_t r0x, int32_t r1x, int32_t r0y, int32_t r1y, float angle0, float angle1)

関数プロトタイプ2:

void drawEllipseArc( int32_t x, int32_t y, int32_t r0x, int32_t r1x, int32_t r0y, int32_t r1y, float angle0, float angle1, const T& color)

機能説明:

  • 楕円弧を描画します。r0、r1が異なる場合は太い楕円弧を描画します。

引数:

  • x:楕円弧中心の x 座標
  • y:楕円弧中心の y 座標
  • r0x:内楕円の x 半径
  • r1x:内楕円の y 半径
  • r0y:外楕円の x 半径
  • r1y:外楕円の y 半径
  • angle0:開始角度
  • angle1:終了角度
  • color:楕円弧の色(カラーコード 参照)

戻り値:

  • null

drawFastHLine

関数プロトタイプ1:

void drawFastHLine( int32_t x, int32_t y, int32_t w)

関数プロトタイプ2:

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

機能説明:

  • 水平線を描画します

引数:

  • x:始点 x 座標
  • y:始点 y 座標
  • w:線の長さ
  • color:線の色(カラーコード 参照)

戻り値:

  • null

drawFastVLine

関数プロトタイプ1:

void drawFastVLine( int32_t x, int32_t y, int32_t w)

関数プロトタイプ2:

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

機能説明:

  • 垂直線を描画します

引数:

  • x:始点 x 座標
  • y:始点 y 座標
  • w:線の長さ
  • color:線の色(カラーコード 参照)

戻り値:

  • null

drawLine

関数プロトタイプ1:

void drawLine( int32_t x0, int32_t y0, int32_t x1, int32_t y1)

関数プロトタイプ2:

void drawLine( int32_t x0, int32_t y0, int32_t x1, int32_t y1, const T& color)

機能説明:

  • 直線を描画します

引数:

  • x0:始点 x 座標
  • y0:始点 y 座標
  • x1:終点 x 座標
  • y1:終点 y 座標
  • color:線の色(カラーコード 参照)

戻り値:

  • null

drawGradientHLine

関数プロトタイプ:

void drawGradientHLine( int32_t x, int32_t y, int32_t w, const T& colorstart, const T& colorend) 

機能説明:

  • 水平グラデーション線を描画します

引数:

  • x:始点 x 座標
  • y:始点 y 座標
  • w:線の幅
  • colorstart:開始色
  • colorend:終了色

戻り値:

  • null

drawGradientLine

関数プロトタイプ:

void drawGradientLine ( int32_t x0, int32_t y0, int32_t x1, int32_t y1, const T& colorstart, const T& colorend )

機能説明:

  • 2点間のグラデーション線を描画します

引数:

  • x0:始点 x 座標
  • y0:始点 y 座標
  • x1:終点 x 座標
  • y1:終点 y 座標
  • colorstart:開始色
  • colorend:終了色

戻り値:

  • null

drawGradientVLine

関数プロトタイプ:

void drawGradientVLine( int32_t x, int32_t y, int32_t h, const T& colorstart, const T& colorend) 

機能説明:

  • 垂直グラデーション線を描画します

引数:

  • x:始点 x 座標
  • y:始点 y 座標
  • h:線の高さ
  • colorstart:開始色
  • colorend:終了色

戻り値:

  • null

drawPixel

関数プロトタイプ1:

void drawPixel( int32_t x, int32_t y)

関数プロトタイプ2:

void drawPixel( int32_t x, int32_t y, const T& color)

機能説明:

  • ピクセルを1つ描画します

引数:

戻り値:

  • null

drawTriangle

関数プロトタイプ1:

void drawTriangle( int32_t x0, int32_t y0, int32_t x1, int32_t y1, int32_t x2, int32_t y2)

関数プロトタイプ2:

void drawTriangle( int32_t x0, int32_t y0, int32_t x1, int32_t y1, int32_t x2, int32_t y2, const T& color)

機能説明:

  • 三角形を描画します

引数:

  • xN:三角形頂点の x 座標
  • yN:三角形頂点の y 座標
  • color:三角形の色(カラーコード 参照)

戻り値:

  • null

塗りつぶし図形

fillAffine

関数プロトタイプ1:

void fillAffine(const float matrix[6], int32_t w, int32_t h)

関数プロトタイプ2:

void fillAffine(const float matrix[6], int32_t w, int32_t h, const T& color)

機能説明:

  • アフィン変換領域を塗りつぶします

引数:

  • matrix:アフィン変換行列
  • w:画像の幅
  • h:画像の高さ
  • color:塗りつぶし色(カラーコード 参照)

戻り値:

  • null

fillArc

関数プロトタイプ1:

void fillArc( int32_t x, int32_t y, int32_t r0, int32_t r1, float angle0, float angle1)

関数プロトタイプ2:

void fillArc( int32_t x, int32_t y, int32_t r0, int32_t r1, float angle0, float angle1, const T& color)

機能説明:

  • 弧形領域を塗りつぶします

引数:

  • x:弧形領域中心の x 座標
  • y:弧形領域中心の y 座標
  • r0:内半径
  • r1:外半径
  • angle0:開始角度
  • angle1:終了角度
  • color:塗りつぶし色(カラーコード 参照)

戻り値:

  • null

fillCircle

関数プロトタイプ1:

void fillCircle( int32_t x, int32_t y, int32_t r)

関数プロトタイプ2:

void fillCircle( int32_t x, int32_t y, int32_t r, const T& color)

機能説明:

  • 塗りつぶし円を描画します

引数:

  • x:円の中心 x 座標
  • y:円の中心 y 座標
  • r:円の半径
  • color:円の色(カラーコード 参照)

戻り値:

  • null

fillEllipse

関数プロトタイプ1:

void fillEllipse( int32_t x, int32_t y, int32_t rx, int32_t ry)

関数プロトタイプ2:

void fillEllipse( int32_t x, int32_t y, int32_t rx, int32_t ry, const T& color)

機能説明:

  • 塗りつぶし楕円を描画します

引数:

  • x:楕円中心の x 座標
  • y:楕円中心の y 座標
  • rx:楕円の長半径
  • ry:楕円の短半径
  • color:楕円の色(カラーコード 参照)

戻り値:

  • null

fillEllipseArc

関数プロトタイプ1:

void fillEllipseArc( int32_t x, int32_t y, int32_t r0x, int32_t r1x, int32_t r0y, int32_t r1y, float angle0, float angle1)

関数プロトタイプ2:

void fillEllipseArc( int32_t x, int32_t y, int32_t r0x, int32_t r1x, int32_t r0y, int32_t r1y, float angle0, float angle1, const T& color)

機能説明:

  • 塗りつぶし楕円弧を描画します。r0、r1が異なる場合は太い楕円弧を描画します。

引数:

  • x:楕円弧中心の x 座標
  • y:楕円弧中心の y 座標
  • r0x:内楕円の x 半径
  • r1x:内楕円の y 半径
  • r0y:外楕円の x 半径
  • r1y:外楕円の y 半径
  • angle0:開始角度
  • angle1:終了角度
  • color:楕円弧の色(カラーコード 参照)

戻り値:

  • null

fillRect

関数プロトタイプ1:

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

関数プロトタイプ2:

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

機能説明:

  • 塗りつぶし矩形を描画します

引数:

  • x:矩形始点の x 座標
  • y:矩形始点の y 座標
  • w:矩形の幅
  • h:矩形の高さ
  • color:矩形の色(カラーコード 参照)

戻り値:

  • null

fillRectAlpha

関数プロトタイプ:

void fillRectAlpha(int32_t x, int32_t y, int32_t w, int32_t h, uint8_t alpha, const T& color)

機能説明:

  • 透明度付き塗りつぶし矩形を描画します

引数:

  • x:矩形始点の x 座標
  • y:矩形始点の y 座標
  • w:矩形の幅
  • h:矩形の高さ
  • alpha:透明度(0-255)
  • color:矩形の色(カラーコード 参照)

戻り値:

  • null

fillRoundRect

関数プロトタイプ1:

void fillRoundRect( int32_t x, int32_t y, int32_t w, int32_t h, int32_t r)

関数プロトタイプ2:

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

機能説明:

  • 角丸塗りつぶし矩形を描画します

引数:

  • x:矩形始点の x 座標
  • y:矩形始点の y 座標
  • w:矩形の幅
  • h:矩形の高さ
  • r:角丸半径
  • color:矩形の色(カラーコード 参照)

戻り値:

  • null

fillTriangle

関数プロトタイプ1:

void fillTriangle( int32_t x0, int32_t y0, int32_t x1, int32_t y1, int32_t x2, int32_t y2)

関数プロトタイプ2:

void fillTriangle( int32_t x0, int32_t y0, int32_t x1, int32_t y1, int32_t x2, int32_t y2, const T& color)

機能説明:

  • 塗りつぶし三角形を描画します

引数:

  • xN:三角形頂点の x 座標
  • yN:三角形頂点の y 座標
  • color:三角形の色(カラーコード 参照)

戻り値:

  • null

floodFill

関数プロトタイプ1:

void floodFill( int32_t x, int32_t y)

関数プロトタイプ2:

void floodFill( int32_t x, int32_t y, const T& color)

機能説明:

  • 指定座標の近似色領域を塗りつぶします

引数:

  • x:指定点の x 座標
  • y:指定点の y 座標
  • color:塗りつぶし色(カラーコード 参照)

戻り値:

  • null

paint

関数プロトタイプ1:

void paint( int32_t x, int32_t y)

関数プロトタイプ2:

void paint( int32_t x, int32_t y, const T& color)

機能説明:

  • 指定位置に色を描画します。floodFill と同じ機能です。

引数:

  • x:指定位置の x 座標
  • y:指定位置の y 座標
  • color:指定位置の色(カラーコード 参照)

戻り値:

  • null

copyRect

関数プロトタイプ:

void copyRect(uint32_t dst_x, uint32_t dst_y, uint32_t w, uint32_t h, uint32_t src_x, uint32_t src_y)

機能説明:

  • 矩形範囲をコピーします

引数:

  • dst_x:コピー先 x 座標
  • dst_y:コピー先 y 座標
  • w:矩形の幅
  • h:矩形の高さ
  • src_x:コピー元 x 座標
  • src_y:コピー元 y 座標

戻り値:

  • null

特殊図形

progressBar

関数プロトタイプ:

void progressBar(int x, int y, int w, int h, uint8_t val)

機能説明:

  • 青色のプログレスバーを表示します

引数:

  • x:プログレスバー始点の x 座標
  • y:プログレスバー始点の y 座標
  • w:プログレスバーの幅
  • h:プログレスバーの高さ
  • val:進捗値(0 - 100)

戻り値:

  • null

qrcode

関数プロトタイプ:

void qrcode(const char *string, uint16_t x = 50, uint16_t y = 10, uint8_t width = 220, uint8_t version = 6)
void qrcode(const String &string, uint16_t x = 50, uint16_t y = 10, uint8_t width = 220, uint8_t version = 6)

機能説明:

  • 指定した文字列情報からQRコードを生成します

引数:

  • string:QRコードにする文字列
  • x:QRコード始点の x 座標
  • y:QRコード始点の y 座標
  • width:QRコードの幅
  • version:QRコードのバージョン(デフォルトは6)

戻り値:

  • 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 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52
#include <Arduino.h>
#include <M5GFX.h>
#include <M5Unified.h>

M5GFX display;

void setup() {
    display.begin();
    display.setRotation(3);
    display.clear(TFT_WHITE);
    delay(1000);
    uint16_t x = display.width() / 2;
    uint16_t y = display.height() / 2;

    display.drawArc(x, y, 100, 200, 0, 90, TFT_BLACK);
    display.drawBezier(0, 0, x/2, 0, x/2, y/2, TFT_VIOLET);
    display.drawBezier(0, 0, x/2, 0, x/2, y, 0, y, TFT_DARKGREEN);
    display.drawCircle(x, y, 200, TFT_BLACK);
    display.drawEllipse(x, y, 300, 200);
    display.drawEllipseArc(x, y, 100, 200, 200, 300, 180, 270);
    display.drawFastHLine(0, y/2, x);
    display.drawFastVLine(x/2, 0, y);
    display.drawLine(0, 0, x, y);
    display.drawGradientHLine(x, y/2*3, x, TFT_BLUE, TFT_RED);
    display.drawGradientVLine(x/2*3, y, y, TFT_BLUE, TFT_RED);
    display.drawGradientLine(x, y, x*2, y*2, TFT_BLUE, TFT_RED);
    display.drawTriangle(x/2, 0, x/4, y/2, x/2, y);

    static float Affine_mat[9] = {1, 0, 0,
                                  0, 1, y,
                                  0, 0, 1  };
    display.fillAffine(Affine_mat, x/4, y/4, TFT_RED);

    display.fillArc(x, y, 100, 200, 90, 180, TFT_ORANGE);
    display.fillCircle(x, y, 100, TFT_YELLOW);
    display.fillEllipse(x, y, 100, 50, TFT_BLACK);
    display.fillEllipseArc(x, y, 100, 200, 200, 300, 270, 360, TFT_SKYBLUE);
    display.fillRect(x/4, y, x/4, y/4, TFT_PINK);
    display.fillRectAlpha(x/4, y/4*5, x/4, y/4, 85, TFT_PINK);
    display.fillRoundRect(0, y/4*5, x/4, y/4, 30, TFT_GREEN);
    display.fillTriangle(0, 0, x/4, y/2, 0, y, TFT_BLUE);

    display.progressBar(x, 0, x, 40, 66);
    display.qrcode("Hello! This is M5Stack.", x/2*3, y/4, y/4*3);

    delay(2000);
    display.floodFill(x/4, y/2+10, TFT_MAGENTA);
    display.paint(x/4, y/2-10, TFT_CYAN);
}

void loop() {
}

write and read

getStartCount

関数プロトタイプ:

uint32_t getStartCount(void)

機能説明:

  • パネルが startWrite を呼び出した回数を取得します

引数:

  • null

戻り値:

  • uint32_t:呼び出し回数

readPixel

関数プロトタイプ:

uint16_t readPixel(int32_t x, int32_t y)

機能説明:

  • 指定座標のカラーコードを読み取ります。カラーコード形式は RGB565 です

引数:

  • x:指定 x 座標
  • y:指定 y 座標

戻り値:

  • uint16_t:読み取ったカラーコード

readPixelRGB

関数プロトタイプ:

RGBColor readPixelRGB(int32_t x, int32_t y)

機能説明:

  • 指定座標のカラーコードを読み取ります。カラーコード形式は RGB888 です

引数:

  • x:指定 x 座標
  • y:指定 y 座標

戻り値:

  • RGBColor:読み取ったカラーコード

readRect

関数プロトタイプ:

void readRect( int32_t x, int32_t y, int32_t w, int32_t h, T* data)

機能説明:

  • 指定矩形領域のカラーデータを読み取ります

引数:

  • x:指定 x 座標
  • y:指定 y 座標
  • w:指定幅
  • h:指定高さ
  • data:読み取ったカラーデータを格納するバッファ

戻り値:

  • null

readRectRGB

関数プロトタイプ:

void readRectRGB( int32_t x, int32_t y, int32_t w, int32_t h, RGBColor* data)

機能説明:

  • 指定矩形領域のカラーデータを読み取ります。カラーコード形式は RGB888 です

引数:

  • x:指定 x 座標
  • y:指定 y 座標
  • w:指定幅
  • h:指定高さ
  • data:読み取ったカラーデータを格納するバッファ

戻り値:

  • null

startWrite

関数プロトタイプ:

void startWrite(bool transaction = true)

機能説明:

  • SPI バス上で CS(チップセレクト信号)を宣言します。endWrite と組み合わせて使用します。startWrite を宣言することで M5GFX は DMA バッファを効率的に利用できます。
注意事項:
SD カードアクセス機能とは同時に使用できません。複数の描画タスクがある場合は個別に制御してください。

引数:

  • transaction:トランザクションを有効にするかどうかのフラグ。デフォルトは true(有効)。

戻り値:

  • null

endWrite

関数プロトタイプ:

void endWrite(void)

機能説明

  • SPI バス上で CS(チップセレクト信号)を解除します。startWrite とセットで使用します。

引数:

  • null

戻り値:

  • null
注意事項:
下記の関数は startWrite および endWrite と組み合わせて使用してください。

pushBlock

注意事項:
M5GFX ライブラリのデータ定義については draw/push と write 関数の違い を参照してください

関数プロトタイプ:

void pushBlock( const T& color, uint32_t length)

機能説明:

引数:

  • color:線の色
  • length:線の長さ

戻り値:

  • null

pushPixels

関数プロトタイプ1:

void pushPixels(T* data, int32_t len )

関数プロトタイプ2:

void pushPixels(const uint16_t* data, int32_t len, bool swap)
void pushPixels(const void*     data, int32_t len, bool swap)

機能説明:

引数:

  • data:ピクセルデータ
  • len:データ長
  • swap:バイトスワップするかどうか(オプション)

戻り値:

  • null

pushPixelsDMA

関数プロトタイプ1:

void pushPixelsDMA(T* data, int32_t len )

関数プロトタイプ2:

void pushPixelsDMA(const uint16_t* data, int32_t len, bool swap)
void pushPixelsDMA(const void*     data, int32_t len, bool swap)

機能説明:

引数:

  • data:ピクセルデータ
  • len:データ長
  • swap:バイトスワップするかどうか(オプション)

戻り値:

  • null

writeColor

関数プロトタイプ:

void writeColor( const T& color, uint32_t length)

機能説明:

注意事項:
この関数は startWrite および endWrite と組み合わせて使用してください。

引数:

  • color:描画色
  • length:描画ピクセル長

戻り値:

  • null

writeFastHLine

関数プロトタイプ1:

void writeFastHLine( int32_t x, int32_t y, int32_t w)

関数プロトタイプ2:

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

機能説明:

  • 水平線を描画します

引数:

  • x:始点 x 座標
  • y:始点 y 座標
  • w:線の幅
  • color:線の色

戻り値:

  • null

writeFastVLine

関数プロトタイプ1:

void writeFastVLine( int32_t x, int32_t y, int32_t w)

関数プロトタイプ2:

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

機能説明:

  • 垂直線を描画します

引数:

  • x:始点 x 座標
  • y:始点 y 座標
  • w:線の幅
  • color:線の色

戻り値:

  • null

writeFillRect

関数プロトタイプ1:

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

関数プロトタイプ2:

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

機能説明:

  • 塗りつぶし矩形を描画します

引数:

  • x:矩形始点の x 座標
  • y:矩形始点の y 座標
  • w:矩形の幅
  • h:矩形の高さ
  • color:矩形の色

戻り値:

  • null

writeFillRectPreclipped

関数プロトタイプ1:

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

関数プロトタイプ2:

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

機能説明:

  • 事前にクリッピングされた塗りつぶし矩形を描画します

引数:

  • x:矩形始点の x 座標
  • y:矩形始点の y 座標
  • w:矩形の幅
  • h:矩形の高さ
  • color:矩形の色

戻り値:

  • null

writeIndexedPixels

関数プロトタイプ:

void writeIndexedPixels(const uint8_t* data, T* palette, int32_t len, uint8_t depth = 8)

機能説明:

  • パレットカラーを使って画像データを描画します

引数:

  • data:画像データ
  • paltte:パレットポインタ
  • len:画像データ長
  • depth:カラーデプス

戻り値:

  • null

writePixel

関数プロトタイプ1:

void writePixel(int32_t x, int32_t y)

関数プロトタイプ2:

void writePixel(int32_t x, int32_t y, const T& color)

機能説明:

  • クリッピング領域内にピクセルを1つ描画します

引数:

  • x:ピクセル x 座標
  • y:ピクセル y 座標
  • color:ピクセルの色

戻り値:

  • null

writePixels

関数プロトタイプ1:

void writePixels(const T* data, int32_t len)

関数プロトタイプ2:

void writePixels(const uint16_t* data, int32_t len, bool swap)
void writePixels(const void*     data, int32_t len, bool swap)

機能説明:

  • クリッピング領域内にピクセルを描画します。データは左上から順に行ごとに描画されます。

引数:

  • data:画像データ
  • len:画像データ長
  • color:ピクセルの色
  • swap:バイトスワップフラグ

戻り値:

  • null

writePixelsDMA

関数プロトタイプ1:

void writePixelsDMA(const T* data, int32_t len)

関数プロトタイプ2:

void writePixelsDMA(const uint16_t* data, int32_t len, bool swap)
void writePixelsDMA(const void*     data, int32_t len, bool swap)

機能説明:

  • クリッピング領域内に DMA でピクセルを描画します。データは左上から順に行ごとに描画されます。

引数:

  • data:画像データ
  • len:画像データ長
  • color:ピクセルの色
  • swap:バイトスワップフラグ

戻り値:

  • 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 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70
#include <Arduino.h>
#include <M5GFX.h>
#include <M5Unified.h>

M5GFX display;
const size_t data_len = 1320;
static uint16_t r_data;
RGBColor rgb_data;

void setup() {
    display.begin();
    display.setColorDepth(16);
    display.setRotation(1);
    display.clear(TFT_WHITE);
    display.setTextFont(&fonts::FreeSansOblique12pt7b);
    display.setTextColor(TFT_BLACK);
    delay(500);
    uint16_t x = display.width() / 2;
    uint16_t y = display.height() / 2;

    uint16_t w_data[data_len];
    for(int i=0; i<data_len; i++)
    {
        w_data[i] = 0;//BLACK
    }

    display.drawCenterString("Write Read Test", x, y);
    delay(1000);
    display.startWrite(true);
    display.writeFillRect(21, 21, 280, 10, TFT_RED);
    display.writeFillRectPreclipped(31, 31, 260, 10, TFT_BLUE);
    display.writeFastHLine(51, 51, 220, TFT_GREEN);
    display.writeFastHLine(51, 190, 220, TFT_GREEN);
    display.writeFastVLine(51, 51, 140, TFT_GREEN);
    display.writeFastVLine(270, 51, 140, TFT_GREEN);
    delay(500);
    for(int i=41; i<=280; i++)
    {
        for(int j=41; j<=50; j++)
        {
            display.writePixel(i, j, TFT_GREEN);
        }        
    }
    display.setWindow(51, 51, 270, 190);
    // By choosing to use the following code, you can clearly see the differences between setWindow and setAddrWindow.
    // display.setAddrWindow(51,51,270,190);
    display.pushBlock(TFT_ORANGE, data_len);
    display.writePixels(w_data, data_len, 0);//Has the same effect as the following code
    // display.pushPixels(w_data, data_len, 0);
    // display.writePixelsDMA(w_data, data_len, 0);
    delay(500);
    display.writeColor(TFT_DARKGREEN, data_len);//660 indicates that three rows of pixels have been drawn within the specified rectangular area.
    display.endWrite();

    auto color_565 = display.readPixel(21, 21);
    auto color_RGB = display.readPixelRGB(21, 21);
    display.setTextFont(&fonts::Font0);
    display.setCursor(21, 200);
    display.printf("565code: %#X, R:%d, G:%d, B:%d\n", color_565, color_RGB.r, color_RGB.g, color_RGB.b);

    display.readRect(25, 25, 1, 1, &r_data);
    display.readRectRGB(25, 25, 1, 1, &rgb_data);
    display.setCursor(21, 215);
    display.printf("888code: %#X\n", &r_data);
    display.setCursor(75, 230);
    display.printf("R:%d, G:%d, B:%d", &rgb_data.r, &rgb_data.g, &rgb_data.b);
}

void loop() {
}
On This Page