基本的なグラフィカル関数

ピクセルを描く

  • drawPixel(int32_t x, int32_t y, uint32_t color);
  • (x, y)ピクセル座標 , color
#include"TFT_eSPI.h"
TFT_eSPI tft;
 
void setup() {
    tft.begin();
    tft.setRotation(3);
 
    tft.fillScreen(TFT_RED); //Red background
    tft.drawPixel(4,7,TFT_BLACK); //drawing a black pixel at (4,7)
}
 
void loop() {}

線を引く

  • drawLine(int32_t x0, int32_t y0, int32_t x1, int32_t y1, uint32_t color);
  • (x0, y0)から (x1, y1)まで線を描画 , color

#include"TFT_eSPI.h"
TFT_eSPI tft;
 
void setup() {
    tft.begin();
    tft.setRotation(3);
 
    tft.fillScreen(TFT_RED); //Red background
    tft.drawLine(0,0,160,120,TFT_BLACK); //drawing a black line from (0,0) to (160,120)
}
 
void loop() {}

横線と縦線を描く

  • 水平線
    drawFastHLine(int32_t x, int32_t y, int32_t w, uint32_t color);
  • 垂直線
    drawFastVLine(int32_t x, int32_t y, int32_t h, uint32_t color);
  • (x, y)は開始座標、wは水平線の幅、hは垂直線の高さ , color
#include"TFT_eSPI.h"
TFT_eSPI tft;
 
void setup() {
    tft.begin();
    tft.setRotation(3);
 
    tft.fillScreen(TFT_RED); //Red background
    tft.drawFastHLine(0,120,320,TFT_BLACK); 
	//A black horizontal line starting from (0, 120) , width of horizontal line , color
    tft.drawFastVLine(160,0,240,TFT_BLACK);
	// A black vertical line starting from (160, 0) , height of verical line , color
}
 
void loop() {}

長方形を描く

  • 枠だけ
    drawRect(int32_t x, int32_t y, int32_t w, int32_t h, uint32_t color);
  • 塗りつぶし
    fillRect(int32_t x, int32_t y, int32_t w, int32_t h, uint32_t color);
  • (x, y)は開始座標、wは幅、hは長方形の高さ、color
#include"TFT_eSPI.h"
TFT_eSPI tft;
 
void setup() {
    tft.begin();
    tft.setRotation(3);
 
    tft.fillScreen(TFT_RED); //Red background
    tft.drawRect(110,70,100,100,TFT_BLACK);
	//A 100x100 black rectangle starting from (110, 70)
}
 
void loop() {}

円を描く

  • 枠だけ
    drawCircle(int32_t x0, int32_t y0, int32_t r, uint32_t color);
  • 塗りつぶし
    fillCircle(int32_t x0, int32_t y0, int32_t r, uint32_t color);
  • (x0, y0)は原点、rは円の半径 , color

#include"TFT_eSPI.h"
TFT_eSPI tft;
 
void setup() {
    tft.begin();
    tft.setRotation(3);
 
    tft.fillScreen(TFT_RED); //Red background
    tft.drawCircle(160,120,50,TFT_BLACK); //A black circle origin at (160, 120)
}
 
void loop() {}

楕円を描く

  • 枠だけ
    drawEllipse(int16_t x0, int16_t y0, int32_t rx, int32_t ry, uint16_t color);
  • 塗りつぶし
    fillEllipse(int16_t x0, int16_t y0, int32_t rx, int32_t ry, uint16_t color);
  • (x0, y0)は楕円の原点、rxは横半径が、ryは垂直半径 , color
#include"TFT_eSPI.h"
TFT_eSPI tft;
 
void setup() {
    tft.begin();
    tft.setRotation(3);
 
    tft.fillScreen(TFT_RED); //Red background
    tft.drawCircle(160,120,50,TFT_BLACK); //A black circle origin at (160, 120)
}
 
void loop() {}

三角形を描く

  • 枠だけ
    drawTriangle(int32_t x0, int32_t y0, int32_t x1, int32_t y1, int32_t x2, int32_t y2, uint32_t color);
  • 塗りつぶし
    fillTriangle(int32_t x0, int32_t y0, int32_t x1, int32_t y1, int32_t x2, int32_t y2, uint32_t color);
  • (x0, y0)は最初の座標、(x1, y1)は2番目の座標、(x2, y2)は三角形の3番目の座標 , color
#include"TFT_eSPI.h"
TFT_eSPI tft;
 
void setup() {
    tft.begin();
    tft.setRotation(3);
 
    tft.fillScreen(TFT_RED); //Red background
    tft.drawTriangle(160,70,60,170,260,170,TFT_BLACK);
    //A triangle with points at (160, 70), (60, 170) and (260, 170)
}
 
void loop() {}

角丸長方形の描画

  • 枠だけ
    drawRoundRect(int32_t x, int32_t y, int32_t w, int32_t h, int32_t r, uint32_t color);
  • 塗りつぶし
    fillRoundRect(int32_t x, int32_t y, int32_t w, int32_t h, int32_t r, uint32_t color);
  • (x, y)開始座標、wは幅、hは高さ、rコーナー半径 , color
#include"TFT_eSPI.h"
TFT_eSPI tft;
 
void setup() {
    tft.begin();
    tft.setRotation(3);
 
    tft.fillScreen(TFT_RED); //Red background
    tft.drawRoundRect(110,70,100,100,10,TFT_BLACK);
    //A 100x100 black roudned rectangle starting from (110, 70)
}
 
void loop() {}

文字を描く

  • drawChar(int32_t x, int32_t y, uint16_t c, uint32_t color, uint32_t bg, uint8_t size)
  • (x, y)は開始位置、cは文字、colorは色、bgは背景色、sizeの大きさ
#include"TFT_eSPI.h"
TFT_eSPI tft;
 
void setup() {
    tft.begin();
    tft.setRotation(3);
 
    tft.fillScreen(TFT_RED); //Red background
    tft.drawChar(140,120,'A',TFT_BLACK, TFT_RED,2); //Draw a black character A from (140,120)
    tft.drawChar(155,120,'B',TFT_BLACK, TFT_RED,2); //Draw a black character B from (155,120)
    tft.drawChar(170,120,'C',TFT_BLACK, TFT_RED,2); //Draw a black character C from (170,120)
}
 
void loop() {}

文字列の描画

  • drawString(const String& string, int32_t poX, int32_t poY);
  • stringはテキスト文字列、(poX, poY)は開始座標
  • tft.setTextColor(TFT_BLACK);で文字色を設定
  • tft.setTextSize(1); で文字サイズを設定
#include"TFT_eSPI.h"
TFT_eSPI tft;
 
void setup() {
  tft.begin();
  tft.setRotation(3);
 
  tft.fillScreen(TFT_RED); //Red background
 
  tft.setTextColor(TFT_BLACK);          //sets the text color to black
  tft.setTextSize(1);                   //sets the size of text
  tft.drawString("Hello world!", 0, 0); //prints strings from (0, 0)
  tft.setTextSize(2);
  tft.drawString("Hello world!", 0, 10);
}
 
void loop() {}

画面全体を塗りつぶす

  • fillScreen(uint32_t color);
#include"TFT_eSPI.h"
TFT_eSPI tft;
 
void setup() {
  tft.begin();
  tft.setRotation(3);
}
 
void loop() {
    //Looping through color R-G-B
    tft.fillScreen(TFT_RED);
    delay(1000);
    tft.fillScreen(TFT_GREEN);
    delay(1000);
    tft.fillScreen(TFT_BLUE);
    delay(1000);
}
 
void loop() {}