【Arduino】189种传感器模块系列实验(资料代码+仿真编程+图形编程)
实验二百四十九:1.28寸圆形彩色TFT显示屏 高清IPS 模块 240*240 SPI接口GC9A01驱动
项目之一百零四:ESP32+GC9A01之点、线、面动态图形的综合绘图测试
实验开源代码
- /*
- 【Arduino】189种传感器模块系列实验(资料代码+仿真编程+图形编程)
- 实验二百四十九:1.28寸圆形彩色TFT显示屏 高清IPS 模块 240*240 SPI接口GC9A01驱动
- 项目之一百零四:ESP32+GC9A01之点、线、面动态图形的综合绘图测试
- */
-
- // GC9A01---------- ESP32
- // RST ------------ NC(复位引脚,此处未连接)
- // CS ------------- D4(片选引脚,连接到ESP32的D4引脚)
- // DC ------------- D2(数据/命令选择引脚,连接到ESP32的D2引脚)
- // SDA ------------ D23 (green)(主数据输出引脚,连接到ESP32的D23引脚,绿色线)
- // SCL ------------ D18 (yellow)(时钟信号引脚,连接到ESP32的D18引脚,黄色线)
- // GND ------------ GND(接地引脚,连接到ESP32的接地端)
- // VCC -------------3V3(电源引脚,连接到ESP32的3.3V电源)
-
- #include <TFT_eSPI.h>
- #include "SPI.h"
-
- #define SCREEN_WIDTH 240
- #define SCREEN_HEIGHT 240
-
- TFT_eSPI tft = TFT_eSPI();
-
- void setup() {
- Serial.begin(115200);
- tft.init();
- tft.setRotation(2);
- tft.fillScreen(TFT_BLACK);
- }
-
- void drawRandomDots() {
- for (int i = 0; i < 100; i++) {
- int x = random(0, SCREEN_WIDTH);
- int y = random(0, SCREEN_HEIGHT);
- uint16_t color = tft.color565(random(50, 255), random(50, 255), random(50, 255));
- tft.drawPixel(x, y, color);
- }
- }
-
- void drawMovingLines() {
- for (int i = 0; i < SCREEN_WIDTH; i += 10) {
- uint16_t color = tft.color565(random(100, 255), random(100, 255), random(100, 255));
- tft.drawLine(i, 0, SCREEN_WIDTH - i, SCREEN_HEIGHT, color);
- delay(20);
- }
- }
-
- void drawFilledShapes() {
- for (int i = 0; i < 5; i++) {
- int x = random(30, SCREEN_WIDTH - 30);
- int y = random(30, SCREEN_HEIGHT - 30);
- int size = random(20, 50);
- uint16_t color = tft.color565(random(50, 255), random(50, 255), random(50, 255));
-
- if (random(0, 2) == 0) {
- tft.fillRect(x, y, size, size, color);
- } else {
- tft.fillCircle(x, y, size / 2, color);
- }
- }
- }
-
- void loop() {
- tft.fillScreen(TFT_BLACK);
-
- drawRandomDots();
- delay(500);
-
- drawMovingLines();
- delay(500);
-
- drawFilledShapes();
- delay(500);
- }
复制代码
|