當前位置: 首頁>>編程示例 >>用法及示例精選 >>正文


Arduino TFT - rect()用法及代碼示例

說明

在 TFT 屏幕上繪製一個矩形。 rect()有4個參數,前兩個是形狀的左上角,後兩個是形狀的寬度和高度。

用法

screen.rect(xStart, yStart, width, height);

參數

xStart: int, 線條開始的水平位置 yStart: int, 線條開始的垂直位置 width: int, 矩形的寬度 height: int, 矩形的高度

返回

示例

#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() {

}

相關用法


注:本文由純淨天空篩選整理自arduino.cc大神的英文原創作品 TFT - rect()。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。