【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 "math.h"
-
- #define SCREEN_WIDTH 240
- #define SCREEN_HEIGHT 240
- TFT_eSPI tft = TFT_eSPI();
- int mode = 0; // **当前模式编号**
-
- void setup() {
- Serial.begin(115200);
- tft.init();
- tft.setRotation(2);
- tft.fillScreen(TFT_BLACK);
- }
-
- void drawMinimalGeometry() {
- tft.fillScreen(TFT_BLACK);
- int size = random(30, 100);
- int x = random(40, SCREEN_WIDTH - 40);
- int y = random(40, SCREEN_HEIGHT - 40);
- 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.fillTriangle(x, y, x + size, y, x + size / 2, y - size, color);
- }
- }
-
- void drawDataVisualization() {
- tft.fillScreen(TFT_BLACK);
- for (int i = 0; i < 10; i++) {
- int barHeight = random(30, SCREEN_HEIGHT - 50);
- uint16_t color = tft.color565(random(50, 255), random(50, 255), random(50, 255));
- tft.fillRect(i * 20 + 20, SCREEN_HEIGHT - barHeight, 15, barHeight, color);
- }
- }
-
- void drawParticleFlow() {
- tft.fillScreen(TFT_BLACK);
- for (int i = 0; i < 100; i++) {
- int x = random(10, SCREEN_WIDTH - 10);
- int y = random(10, SCREEN_HEIGHT - 10);
- uint16_t color = tft.color565(random(100, 255), random(100, 255), random(100, 255));
- tft.drawPixel(x + sin(i * 0.1) * 20, y + cos(i * 0.1) * 20, color);
- }
- }
-
- void loop() {
- mode = random(0, 3); // **随机选择模式**
-
- if (mode == 0) {
- drawMinimalGeometry(); // 极简几何模式
- } else if (mode == 1) {
- drawDataVisualization(); // 数据可视化模式
- } else {
- drawParticleFlow(); // 粒子流动模式
- }
-
- delay(1000);
- }
复制代码
|