当前位置: 首页>>代码示例 >>用法及示例精选 >>正文


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()。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。