TFT

i
注意: このページは終了したプロダクトを参照している。
LGPL-2.1V1.0.6 Arduino, Adafruit2026/07/02
Arduino

Arduino TFTグラフィックディスプレイに、テキストや、画像、図形を表示する。

このライブラリは、ST7735チップセットベースのほとんどのTFTディスプレイで利用できる。

リポジトリ

TFTライブラリはArduino IDE 1.0.5以降に付属する。

このライブラリを使うと、ArduinoボードとArduino TFT LCD screenが通信することができる。スクリーンに線や画像、テキストなどの表示プロセスを簡易化することができる。

Arduino TFTライブラリはAdafruit GFXAdafruit ST7735ライブラリを拡張している。GFXライブラリは描画ルーチンで、ST7735ライブラリはArduino TFTのスクリーンを制御する。Arduino用の拡張は、できるだけProcessing APIに似せている。

ボード上にはSDカードスロットがあり、SDライブラリを用いることで利用できる。

TFTライブラリは、スクリーンやSDカードとの通信にSPIライブラリを使っているので、すべてのスケッチでインクルードする必要がある。

このライブラリを使うためには、以下を宣言する。

#include <SPI.h> 
#include <TFT.h>

ライブラリの利用

スクリーンを利用するには2つの設定方法がある。一つはArduinoのハードウェアSPIインタフェースを利用する方法で、もう一つは、全てのピンを手動で指定する方法である。2つの利用方法による機能面での差分はないが、ハードウェアSPIを使う方が大幅に高速である。

TFTモジュール上のSDカードを使う場合は、ハードウェアSPIを利用する必要がある。全てのライブラリの例題ではハードウェアSPIを理容師ている。

UnoでハードウェアSPIを使うときは、CSとDC、RESETピンだけを宣言する。MOSI(11番ピン)とSCLK(13番ピン)は既に定義されている。

1
2
3
4
5
#define CS   10
#define DC   9
#define RESET  8

TFT myScreen = TFT(CS, DC, RESET);

LeonardでハードウェアSPIを使うときは、以下のようにピンを宣言する。

1
2
3
4
5
#define CS   7
#define DC   0
#define RESET  1

TFT myScreen = TFT(CS, DC, RESET);

ハードウェアSPIを利用しない場合は、任意の利用可能なピンを使うことができる。このときは、CSとCD、RESET以外に、MOSIとSCLKも宣言しなければならない。

1
2
3
4
5
6
7
#define SCLK 4
#define MOSI 5
#define CS   6
#define DC   7
#define RESET 8

TFT myScreen = TFT(CS, DC, MOSI, SCLK, RESET);

Arduino EsploraとTFTライブラリを使う

Arduino EsploraにはTFT用に設計されたソケットがあるり、スクリーン用に利用するピンは固定されているので、Esplora専用のオブジェクトが作成される。この場合は、EsploraTFTというオブジェクトを通して、Esploraに接続したスクリーンを参照することができる。

Processingとの類似性

Processingは、デザイナやアーティスト、学生などが利用するオープンソースソフトウェア環境である。Processingの主な出力は、PCやブラウザ上のグラフィックウインドウである。ProcessingとTFT間の移行をスムーズに行うため、図形やテキストの表示のためのプリミティブは、できるだけProcessinに似せて作ってある。

使用例

ArduinoとEsplora向けのライブラリの利用例がライブラリの使用例のページにある。

互換性

このライブラリは全てのアーキテクチャで互換性がある。全てのArduinoボードで利用可能。

このライブラリを利用するには、Arduino IDEのライブラリマネージャを使い インストールする。

TFT()

名称

TFT.TFT()

説明

TFTスクリーンに描画するための基底クラス。スケッチで、TFTクラスのインスタンスを作成するために使用する。

Arduino Esploraを使うときは、これを呼び出す必要はない。スクリーンに対する全ての参照は、EsploraTFTによって行われる。

書式

TFT::TFT(uint8_t CS, uint8_t RS, uint8_t RST);

Adafruit_ST7735::Adafruit_ST7735(uint8_t cs, uint8_t rs, uint8_t sid, uint8_t sclk, uint8_t rst);

引数

CS/csチップセレクト用のピン番号。
RS/rs使用するピン番号。
RST/rstリセット用のピン番号。
sidハードウェアSPIを利用しないときの、MOSI用ピン。
sclkハードウェアSPIを利用しないときの、クロック用ピン。

戻り値

なし。

使用例

 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
#include <SPI.h>
#include <TFT.h>            // Arduino LCD library

#define cs   10
#define dc   9
#define rst  8

TFT screen = TFT(cs, dc, rst);

void setup() {
  // initialize the screen
  screen.begin();

  // make the background black
  screen.background(0,0,0);

  // set the stroke color to white
  screen.stroke(255,255,255);

  // turn off fill coloring
  screen.noFill();

  // draw a rectangle in the center of screen
  screen.line(screen.width()/2-5, screen.height()/2-5, 10, 10);
}

void loop() {

}
EsploraTFT

名称

EsploraTFT

説明

Arduino Esploraボードを使うときに生成される、TFTクラスのインスタンスの名称。

書式

EsploraTFT;

引数

なし。

戻り値

なし。

使用例

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
#include <Esplora.h>
#include <SPI.h>
#include <TFT.h>            // Arduino LCD library

void setup() {
  // initialize the screen
  EsploraTFT.begin();

  // make the background white
  EsploraTFT.background(255,255,255);
}

void loop() {

}
begin()

名称

TFT.begin()

説明

描画する前にArduino GLCDスクリーンを初期化するために呼び出す必要がある。

書式

void TFT::begin();

引数

なし。

戻り値

なし。

使用例

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
#include <SPI.h>
#include <TFT.h>            // Arduino LCD library

#define cs   10
#define dc   9
#define rst  8

TFT screen = TFT(cs, dc, rst);

void setup() {
  // initialize the screen
  screen.begin();

  // make the background white
  screen.background(255,255,255);
}

void loop() {

}
background()

名称

TFT.background()

説明

LCDに表示されているすべてのものを、指定した色で塗りつぶす。loop()の中で使って、スクリーンをクリアするのに使うことができる。

background()は、赤と緑、青のそれぞれを8ビットの値で指定できるが、指定した色を忠実に再現できるわけではない。赤と青は5ビット(32段階)に、緑は6ビット(64段階)に変換される。

書式

void Adafruit_GFX::background(uint8_t red, uint8_t green, uint8_t blue);

引数

red
0-255。
green0-255。
blue0-255。

戻り値

なし。

使用例

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
#include <SPI.h>
#include <TFT.h>            // Arduino LCD library

#define cs   10
#define dc   9
#define rst  8

TFT screen = TFT(cs, dc, rst);

void setup() {
  // initialize the screen
  screen.begin();

  // make the background white
  screen.background(255,255,255);
}

void loop() {

}
stroke()

名称

TFT.stroke()

説明

スクリーンにオブジェクトを描画する前に呼び出し、線や図形の枠線の色を設定する。

stroke()は、赤と緑、青のそれぞれを8ビットの値で指定できるが、指定した色を忠実に再現できるわけではない。赤と青は5ビット(32段階)に、緑は6ビット(64段階)に変換される。

書式

void Adafruit_GFX::stroke(color c);

引数

red
0-255。
green0-255。
blue0-255。

戻り値

なし。

使用例

 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
#include <SPI.h>
#include <TFT.h>            // Arduino LCD library

#define cs   10
#define dc   9
#define rst  8

TFT screen = TFT(cs, dc, rst);

void setup() {
  // initialize the screen
  screen.begin();

  // make the background black
  screen.background(0,0,0);

  // set the stroke color to white
  screen.stroke(255,255,255);

  // draw a box with a white outline in the middle of the screen
  screen.rect(screen.width()/2+10,screen.height()/2+10,screen.width()/2-10,screen.height()/2-10);
}

void loop() {

}
noStroke()

名称

TFT.noStroke()

説明

この関数を呼び出した後は、表示される図形の枠線の色が消える。

書式

void Adafruit_GFX::noStroke();

引数

なし。

戻り値

なし。

使用例

 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
#include <SPI.h>
#include <TFT.h>            // Arduino TFT library

#define cs   10
#define dc   9
#define rst  8

TFT screen = TFT(cs, dc, rst);

void setup() {
  // initialize the screen
  screen.begin();

  // make the background black
  screen.background(0,0,0);

  // turn the stroke off
  screen.noStroke();

  // set the fill color to white
  screen.fill(255,255,255);

  // draw a rectangle in the center of screen
  screen.line(screen.width()/2-5, screen.height()/2-5, 10, 10);
}

void loop() {

}
fill()

名称

TFT.fill()

説明

スクリーンにオブジェクトを描画する前に呼び出し、図形や文字の色を設定する。

fill()は、赤と緑、青のそれぞれを8ビットの値で指定できるが、指定した色を忠実に再現できるわけではない。赤と青は5ビット(32段階)に、緑は6ビット(64段階)に変換される。

書式

void Adafruit_GFX::fill(uint8_t red, uint8_t green, uint8_t blue);

引数

red
0-255。
green0-255。
blue0-255。

戻り値

なし。

使用例

 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
#include <SPI.h>
#include <TFT.h>            // Arduino TFT library

#define cs   10
#define dc   9
#define rst  8

TFT screen = TFT(cs, dc, rst);


void setup() {
  // initialize the screen
  screen.begin();

  // make the background black
  screen.background(0,0,0);

  // set the stroke color to white
  screen.fill(255,255,255);

  // draw a white box in the screen center
  screen.rect(screen.width()/2+10,screen.height()/2+10,screen.width()/2-10,screen.height()/2-10);
}

void loop() {

}
noFill()

名称

TFT.noFill()

説明

この関数を呼び出した後は、表示される図形の塗りつぶしの色が消える。

書式

void Adafruit_GFX::noFill();

引数

なし。

戻り値

なし。

使用例

 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
#include <SPI.h>
#include <TFT.h>            // Arduino TFT library

#define cs   10
#define dc   9
#define rst  8

TFT screen = TFT(cs, dc, rst);

void setup() {
  // initialize the screen
  screen.begin();

  // make the background black
  screen.background(0,0,0);

  // turn the fill off
  screen.noFill();

  // set the stroke color to white
  screen.stroke(255,255,255);

  // draw a rectangle in the center of screen
  screen.line(screen.width()/2-5, screen.height()/2-5, 10, 10);
}

void loop() {

}
text()

名称

TFT.text()

説明

スクリーン上の、指定した座標に文字列を書く。

書式

void Adafruit_GFX::text(const char * text, int16_t x, int16_t y);

引数

textスクリーン上に書きたい文字列。
xスクリーン上に文字列を書き出す開始位置のX座標。
yスクリーン上に文字列を書き出す開始位置のY座標。

戻り値

なし。

使用例

 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
#include <SPI.h>
#include <TFT.h>            // Arduino TFT library

#define cs   10
#define dc   9
#define rst  8

TFT screen = TFT(cs, dc, rst);

void setup() {
  // initialize the screen
  screen.begin();

  // make the background black
  screen.background(0,0,0);

  // set the text color to white
  screen.stroke(255,255,255);

  // write text to the screen in the top left corner
  screen.text("Testing!", 0, 0);
}

void loop() {

}
setTextSize()

名称

TFT.setTextSize()

説明

文字列のサイズを設定する。デフォルトサイズは"1"である。サイズを1増やすと、高さが10ピクセル増える。size 1が10ピクセル、size 2が20ピクセル、…である。

書式

void Adafruit_GFX::setTextSize(uint8_t s);

引数

s1-5。

戻り値

なし。

使用例

 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 <SPI.h>
#include <TFT.h>            // Arduino TFT library

#define cs   10
#define dc   9
#define rst  8

TFT screen = TFT(cs, dc, rst);

void setup() {
  // initialize the screen
  screen.begin();

  // make the background black
  screen.background(0,0,0);

  // set the stroke color to white
  screen.fill(255,255,255);

  // default text size
  screen.setTextSize(1);
  // write text to the screen in the top left corner
  screen.text("Testing!", 0, 0);
  // increase text size
  screen.setTextSize(5);
  // write text to the screen below
  screen.text("BIG!", 0, 10);
}

void loop() {

}
point()

名称

TFT.point()

説明

指定した座標に点を描く。最初の引数は水平位置、2番目の引数は垂直位置である。

書式

void Adafruit_GFX::point(int16_t x, int16_t y);

引数

x水平位置。
y垂直位置。

戻り値

なし。

使用例

 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
#include <SPI.h>
#include <TFT.h>            // Arduino TFT library

#define cs   10
#define dc   9
#define rst  8

TFT screen = TFT(cs, dc, rst);

void setup() {
  // initialize the screen
  screen.begin();

  // make the background black
  screen.background(0,0,0);

  // set the stroke color to white
  screen.fill(255,255,255);

  // draw a pixel in the screen's center
  screen.point(screen.width()/2, screen.height()/2);
}

void loop() {

}
line()

名称

TFT.line()

説明

2点間に直線を描く。line()で描く線の色を変えるには、stroke()を使う。

書式

void Adafruit_GFX::line(int16_t x1, int16_t y1, int16_t x2, int16_t y2);

引数

x1直線を開始する水平位置。
y1直線を開始する垂直位置。
x2直線を終了する水平位置。
y2直線を終了する垂直位置。

戻り値

なし。

使用例

 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
#include <SPI.h>
#include <TFT.h>            // Arduino TFT library

#define cs   10
#define dc   9
#define rst  8

TFT screen = TFT(cs, dc, rst);

void setup() {
  // initialize the screen
  screen.begin();

  // make the background black
  screen.background(0,0,0);

  // set the stroke color to white
  screen.stroke(255,255,255);

  // draw a diagonal line across the screen's center
  screen.line(0, 0, 160, 124);
}

void loop() {

}
rect()

名称

TFT.rect()

説明

TFTスクリーンに長方形を描く。rect()は4つの引数をとる。最初の2つは左上の頂点の座標、残りの2つは幅と高さである。

書式

void Adafruit_GFX::rect(int16_t x, int16_t y, int16_t width, int16_t height);

引数

x長方形の水平位置。
y
長方形の垂直位置。
width
長方形の幅。
height長方形の高さ。

戻り値

なし。

使用例

 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
#include <SPI.h>
#include <TFT.h>            // Arduino TFT library

#define cs   10
#define dc   9
#define rst  8

TFT screen = TFT(cs, dc, rst);

void setup() {
  // initialize the screen
  screen.begin();

  // make the background black
  screen.background(0,0,0);

  // set the stroke color to white
  screen.stroke(255,255,255);

  // set the fill color to grey
  screen.fill(127,127,127);

  // draw a rectangle in the center of screen
  screen.rect(screen.width()/2-5, screen.height()/2-5, 10, 10);
}

void loop() {

}
width()

名称

TFT.width()

説明

TFTスクリーンの幅をピクセル単位で調べる。

書式

int16_t Adafruit_GFX::width(void);

引数

なし。

戻り値

スクリーンの幅(ピクセル)。

使用例

 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
#include <SPI.h>
#include <TFT.h>            // Arduino TFT library

#define cs   10
#define dc   9
#define rst  8

TFT screen = TFT(cs, dc, rst);

void setup() {
  // initialize the screen
  screen.begin();

  // make the background black
  screen.background(0,0,0);

  // set the stroke color to white
  screen.stroke(255,255,255);

  // set the fill color to grey
  screen.fill(127,127,127);

  // draw a rectangle in the center of screen
  screen.line(screen.width()/2-5, screen.height()/2-5, 10, 10);
}

void loop() {

}
height()

名称

TFT.height()

説明

TFTスクリーンの高さをピクセル単位で調べる。

書式

int16_t Adafruit_GFX::height(void);

引数

なし。

戻り値

スクリーンの高さ(ピクセル)。

使用例

 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
#include <SPI.h>
#include <TFT.h>            // Arduino TFT library

#define cs   10
#define dc   9
#define rst  8

TFT screen = TFT(cs, dc, rst);

void setup() {
  // initialize the screen
  screen.begin();

  // make the background black
  screen.background(0,0,0);

  // set the stroke color to white
  screen.stroke(255,255,255);

  // set the fill color to grey
  screen.fill(127,127,127);

  // draw a rectangle in the center of screen
  screen.line(screen.width()/2-5, screen.height()/2-5, 10, 10);
}

void loop() {

}
circle()

名称

TFT.circle()

説明

スクリーンに円を描く。

円は、その中心を指定して描かれる。このため、直径は常に奇数になる。

書式

void Adafruit_GFX::circle(int16_t x, int16_t y, int16_t r);

引数

x
円の中心のX座標。
y
円の中心のY座標。
r
円の半径。

戻り値

スクリーンの高さ(ピクセル)。

使用例

 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
#include <SPI.h>
#include <TFT.h>            // Arduino TFT library

#define cs   10
#define dc   9
#define rst  8

TFT screen = TFT(cs, dc, rst);

void setup() {
  // initialize the screen
  screen.begin();

  // make the background black
  screen.background(0,0,0);

  // set the stroke color to white
  screen.stroke(255,255,255);

  // set the fill color to grey
  screen.fill(127,127,127);

  // draw a circle in the center of screen
  screen.circle(screen.width()/2, screen.height()/2, 10);
}

void loop() {

}
image()

名称

TFT.image()

説明

スクリーン上の指定した位置に、SDカードに格納されているイメージを描く。

書式

void Adafruit_GFX::image(PImage & img, uint16_t x, uint16_t y);

引数

img
PImageのインスタンス。
x
描画位置のX座標。
y
描画位置のY座標。

戻り値

スクリーンの高さ(ピクセル)。

使用例

 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
// this example looks for a file named "logo.bmp"
//  on the SD card, and renders it to the screen
#include <Esplora.h>
#include <SPI.h>
#include <SD.h>
#include <TFT.h>            // Arduino TFT library

#define SD_CS    8  // Chip select line for SD card in Esplora

PImage logo;

void setup() {
  // initialize the screen
  EsploraTFT.begin();
  // initialize the SD card
  SD.begin(SD_CS);
  // set the background the black
  EsploraTFT.background(0, 0, 0);

  // load the image into the named instance of PImage
  logo = EsploraTFT.loadImage("arduino.bmp");

  // if it is a valid image file, turn the Esplora's LED green
   if (logo.isValid()) {
       Esplora.writeGreen(255);
  }
  else{
  // if it is not valid, turn the LED red
    Esplora.writeRed(255);
  }

  // draw the image on the screen starting at the top left corner
  EsploraTFT.image(logo, 0, 0);

}

void loop() {

}
loadImage()

名称

PImage.loadImage()

説明

PImageのインスタンスに、SDカードからイメージをロードする。TFTライブラリは、SDカードのルートディレクトリ上の .bmp ファイルを読み込み、スクリーン上に描画することができる。イメージは、スクリーンの解像度(160x128)よりも小さくても、大きくてもいい。しかし、イメージを操作するメソッドは用意されていない。SDカードにイメージを格納する前に、サイズを調整しなければならない。ロードできるイメージは24ビットのbmpイメージだけである。

書式

PImage PImage::loadImage(const char * fileName);

引数

fileName読み込みたいSDカード上のイメージの名前。

戻り値

ロードされたイメージ。

使用例

 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
// this example looks for a file named "logo.bmp"
//  on the SD card, and renders it to the screen
#include <Esplora.h>
#include <SD.h>
#include <SPI.h>
#include <TFT.h>            // Arduino TFT library

#define SD_CS    8  // Chip select line for SD card in Esplora

PImage logo;

void setup() {
  // initialize the screen
  EsploraTFT.begin();
  // initialize the SD card
  SD.begin(SD_CS);
  // set the background the black
  EsploraTFT.background(0, 0, 0);

  // load the image into the named instance of PImage
  logo = EsploraTFT.loadImage("arduino.bmp");

  // if it is a valid image file, turn the Esplora's LED green
   if (logo.isValid()) {
       Esplora.writeGreen(255);
  }
  else{
  // if it is not valid, turn the LED red
    Esplora.writeRed(255);
  }

  // draw the image on the screen starting at the top left corner
  EsploraTFT.image(logo, 0, 0);

}

void loop() {

}
PImage

名称

PImage

説明

SDカード上のビットマップイメージを描画するための基底クラス。PImageを追加うときには、SDライブラリをインクルードする必要がある。

書式

PImage image;

引数

imagePImageオブジェクトの名前。スクリーンにイメージを描画する際に参照する。

戻り値

なし。

使用例

 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
// this example looks for a file named "logo.bmp"
//  on the SD card, and renders it to the screen
#include <Esplora.h>
#include <SD.h>
#include <SPI.h>
#include <TFT.h>            // Arduino TFT library

#define SD_CS    8  // Chip select line for SD card in Esplora

PImage logo;

void setup() {
  // initialize the screen
  EsploraTFT.begin();
  // initialize the SD card
  SD.begin(SD_CS);
  // set the background the black
  EsploraTFT.background(0, 0, 0);

  // load the image into the named instance of PImage
  logo = EsploraTFT.loadImage("arduino.bmp");

  // if it is a valid image file, turn the Esplora's LED green
   if (logo.isValid()) {
       Esplora.writeGreen(255);
  }
  else{
  // if it is not valid, turn the LED red
    Esplora.writeRed(255);
  }

  // draw the image on the screen starting at the top left corner
  EsploraTFT.image(logo, 0, 0);

}

void loop() {

}
PImage.height()

名称

PImage.height()

説明

PImageオブジェクトの高さを調べる。

書式

int PImage::height();

引数

なし。

戻り値

イメージの高さ(ピクセル単位)。

使用例

 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
// this example looks for a file named "logo.bmp"
//  on the SD card, and renders it to the screen
#include <Esplora.h>
#include <SD.h>
#include <SPI.h>
#include <TFT.h>            // Arduino TFT library

#define SD_CS    8  // Chip select line for SD card in Esplora

PImage logo;

void setup() {
  // initialize the screen
  EsploraTFT.begin();
  // initialize the SD card
  SD.begin(SD_CS);
  // set the background the black
  EsploraTFT.background(0, 0, 0);

  // load the image into the named instance of PImage
  logo = EsploraTFT.loadImage("arduino.bmp");

  // if it is a valid image file, turn the Esplora's LED green
   if (logo.isValid()) {
       Esplora.writeGreen(255);
  }
  else{
  // if it is not valid, turn the LED red
    Esplora.writeRed(255);
  }


}

void loop() {
  // randomly draw the image on screen
  int x = random(EsploraTFT.width() - logo.width());
  int y = random(EsploraTFT.height() - logo.height());
  EsploraTFT.image(logo, x, y);
  delay(1500);

}
PImage.isValid()

名称

PImage.isValid()

説明

PImageのインスタンスが有効なビットマップファイルを参照しているか調べる。

書式

bool PImage::isValid();

引数

なし。

戻り値

有効(true)/無効(false)

使用例

 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
// this example looks for a file named "logo.bmp"
//  on the SD card, and renders it to the screen
#include <Esplora.h>
#include <SD.h>
#include <SPI.h>
#include <TFT.h>            // Arduino TFT library

#define SD_CS    8  // Chip select line for SD card in Esplora

PImage logo;

void setup() {
  // initialize the screen
  EsploraTFT.begin();
  // initialize the SD card
  SD.begin(SD_CS);
  // set the background the black
  EsploraTFT.background(0, 0, 0);

  // load the image into the named instance of PImage
  logo = EsploraTFT.loadImage("arduino.bmp");

  // if it is a valid image file, turn the Esplora's LED green
   if (logo.isValid()) {
       Esplora.writeGreen(255);
  }
  else{
  // if it is not valid, turn the LED red
    Esplora.writeRed(255);
  }

  // draw the image on the screen starting at the top left corner
  EsploraTFT.image(logo, 0, 0);

}

void loop() {

}
PImage.width()

名称

PImage.width()

説明

PImageオブジェクトの幅を調べる。

書式

int PImage::width();

引数

なし。

戻り値

イメージの幅(ピクセル単位)。

使用例

 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
// this example looks for a file named "logo.bmp"
//  on the SD card, and renders it to the screen
#include <Esplora.h>
#include <SD.h>
#include <SPI.h>
#include <TFT.h>            // Arduino TFT library

#define SD_CS    8  // Chip select line for SD card in Esplora

PImage logo;

void setup() {
  // initialize the screen
  EsploraTFT.begin();
  // initialize the SD card
  SD.begin(SD_CS);
  // set the background the black
  EsploraTFT.background(0, 0, 0);

  // load the image into the named instance of PImage
  logo = EsploraTFT.loadImage("arduino.bmp");

  // if it is a valid image file, turn the Esplora's LED green
   if (logo.isValid()) {
       Esplora.writeGreen(255);
  }
  else{
  // if it is not valid, turn the LED red
    Esplora.writeRed(255);
  }


}

void loop() {
  // randomly draw the image on screen
  int x = random(EsploraTFT.width() - logo.width());
  int y = random(EsploraTFT.height() - logo.height());
  EsploraTFT.image(logo, x, y);
  delay(1500);

}

オリジナルのページ

https://docs.arduino.cc/libraries/tft/

inserted by FC2 system