37款传感器与执行器的提法,在网络上广泛流传,其实Arduino能够兼容的传感器模块肯定是不止这37种的。鉴于本人手头积累了一些传感器和执行器模块,依照实践出真知(一定要动手做)的理念,以学习和交流为目的,这里准备逐一动手尝试系列实验,不管成功(程序走通)与否,都会记录下来—小小的进步或是搞不掂的问题,希望能够抛砖引玉。
【Arduino】168种传感器模块系列实验(资料代码+仿真编程+图形编程)
实验一百五十六:2.4寸TFT液晶触摸屏 彩屏模块 TFT-LCD 高清真彩显示屏
Adafruit_TFTLCD库相关函数
class Adafruit_TFTLCD : public Adafruit_GFX { public: Adafruit_TFTLCD(uint8_t cs, uint8_t cd, uint8_t wr, uint8_t rd, uint8_t rst); Adafruit_TFTLCD(void); void begin(uint16_t id = 0x9325); void drawPixel(int16_t x, int16_t y, uint16_t color); void drawFastHLine(int16_t x0, int16_t y0, int16_t w, uint16_t color); void drawFastVLine(int16_t x0, int16_t y0, int16_t h, uint16_t color); void fillRect(int16_t x, int16_t y, int16_t w, int16_t h, uint16_t c); void fillScreen(uint16_t color); void reset(void); void setRegisters8(uint8_t *ptr, uint8_t n); void setRegisters16(uint16_t *ptr, uint8_t n); void setRotation(uint8_t x); void setAddrWindow(int x1, int y1, int x2, int y2); void pushColors(uint16_t *data, uint8_t len, boolean first); uint16_t color565(uint8_t r, uint8_t g, uint8_t b), readPixel(int16_t x, int16_t y), readID(void); uint32_t readReg(uint8_t r); private: void init(),
1、创建对象
- Adafruit_TFTLCD tft(LCD_CS, LCD_CD, LCD_WR, LCD_RD, LCD_RESET);
- void setup(void) {
- tft.reset();
- tft.begin(0x9341);
- }
首先创建了一个Adafruit_TFTLCD对象,名为tft,管脚定义这里省去了。
begin方法中的0x9341表示改TFT LCD的驱动为ILI9341,其它的这里不做介绍
2、屏幕
- void fillScreen(uint16_t color);
- uint16_t width(); //屏幕的宽度
- uint16_t height(); //屏幕的高度
全屏填充颜色color,再次之前显示的内容会被挡住
案例
- tft.fillScreen(BLACK);
- delay(1000);
- tft.fillScreen(RED);
- delay(1000);
- tft.fillScreen(BLUE);
- delay(1000);
3、点
- void drawPixel(int16_t x, int16_t y, uint16_t color);
复制代码
在点(x,y)上画一个颜色为color的像素点。
案例
- tft.drawPixel(1,1,RED);
- tft.drawPixel(10,10,RED);
- tft.drawPixel(20,20,RED);
- tft.drawPixel(40,40,RED);
- tft.drawPixel(60,60,RED);
4、线
- void drawLine(int16_t x0, int16_t y0, int16_t x1, int16_t y1, uint16_t color);
- void drawFastHLine(int16_t x0, int16_t y0, int16_t w, uint16_t color);
- void drawFastVLine(int16_t x0, int16_t y0, int16_t h, uint16_t color);
最简单的是两点确定一条直线,当然也可以确定一个点、方向、长度,后两个是画水平线或者铅锤线。
案例
- tft.drawFastHLine(10,10,170,RED);
- tft.drawFastVLine(10,10,170,RED);
- tft.drawLine(10,10,100,180,RED);
5、矩形&&圆角矩形
- void drawRect(int16_t x, int16_t y, int16_t w, int16_t h, uint16_t c);
- void fillRect(int16_t x, int16_t y, int16_t w, int16_t h, uint16_t c);
- void drawRoundRect(int16_t x, int16_t y, int16_t w, int16_t h, int16_t radius, uint16_t color);
- void fillRoundRect(int16_t x, int16_t y, int16_t w, int16_t h, int16_t radius, uint16_t color);
drawRect的矩形直画出边框,内部不填充,如果需要内部填充颜色则需要使用fillRect
圆角矩形则是多了一个设置圆角半径的参数raduis,是否填充与上面一样。
案例
- tft.drawRect(10,10,150,100,RED);
- tft.fillRect(10,120,150,100,RED);
- tft.drawRoundRect(10,10,150,100,10,RED);
- tft.fillRoundRect(10,120,150,100,10,RED);
6、圆形
- void drawCircle(uint16_t x0, uint16_t y0, uint16_t r, uint16_t color);
- void fillCircle(uint16_t x0, uint16_t y0, uint16_t r, uint16_t color);
这个就比较简单,圆心坐标(x0,y0),半径r,颜色color
案例
- tft.drawCircle(100,100,50,WHITE);
- tft.fillCircle(100,260,50,BLUE);
7、三角形
- void drawTriangle(uint16_t x0, uint16_t y0, uint16_t x1, uint16_t y1, uint16_t x2, uint16_t y2, uint16_t color);
- void fillTriangle(uint16_t x0, uint16_t y0, uint16_t x1, uint16_t y1, uint16_t x2, uint16_t y2, uint16_t color);
三角形需要确定三个顶点以及颜色
案例
- tft.drawTriangle(10,10,100,15,180,100,GREEN);
- tft.fillTriangle(10,110,100,115,180,200,GREEN);
8、字符&&英文文本
- void drawChar(uint16_t x, uint16_t y, char c, uint16_t color, uint16_t bg, uint8_t size);
- void setCursor(uint16_t x0, uint16_t y0); //字体左上角顶点坐标
- void setTextColor(uint16_t color); //字体前景色
- void setTextColor(uint16_t color, uint16_t backgroundcolor);//字体前景色与背景色
- void setTextSize(uint8_t size); //字体大小放法因子
- void setTextWrap(boolean w); //是否自动换行,默认为true,滚动显示设置为false
drawChar只能显示单个字符,需要确定左上角顶点坐标(x,y),字符c,颜色color,前景色color,背景色bg,大小size,大小为1时表示5 * 8像素,为2就表示10 * 16
自定义字体不支持背景色,可在此之前绘制填充颜色的形状,如圆角矩形
案例
- tft.fillScreen(GREEN);
- tft.drawChar(150,10,'A',RED,WHITE,5);
- tft.setCursor(10,50);
- tft.print("AB 3.14"); //默认前景色white、无背景色、大小为1
- tft.setCursor(10,80);
- tft.setTextSize( 4);
- tft.print("AB 3.14");
- tft.setCursor(10,115);
- tft.setTextColor(RED); //背景色不做设置
- tft.setTextSize( 4);
- tft.print("AB你好3.141516");
- tft.setCursor(10,180);
- tft.setTextColor(RED, WHITE);
- tft.setTextSize( 4);
- tft.setTextWrap(false);
- tft.print("AB你好3.141516");
可以看到默认的字体不支持中文,需要使用中文的改日再补上
9、旋转
- void setRotation(uint8_t rotation);
旋转参数可以是0、1、2或3,分别对应0,90,180或270度。
对于属于Arduino屏蔽的显示,旋转值0将显示设置为竖屏(高)模式,旋转值2也是纵向模式,。旋转1是横屏模式,,而旋转3也是横屏模式。
案例
- //tft.setRotation(1); //注释和未注释的情况下做对比
- tft.fillScreen(GREEN);
- tft.drawChar(150,10,'A',RED,WHITE,5);
- tft.setCursor(10,50);
- tft.print("AB 3.14"); //默认前景色white、无背景色、大小为1
- tft.setCursor(10,80);
- tft.setTextSize( 4);
- tft.print("AB 3.14");
- tft.setCursor(10,115);
- tft.setTextColor(RED); //背景色不做设置
- tft.setTextSize( 4);
- tft.print("AB你好3.141516");
- tft.setCursor(10,180);
- tft.setTextColor(RED, WHITE);
- tft.setTextSize( 4);
- tft.setTextWrap(false);
- tft.print("AB你好3.141516");
【Arduino】168种传感器模块系列实验(资料代码+仿真编程+图形编程)
实验一百五十三:2.4寸TFT液晶触摸屏 彩屏模块 TFT-LCD 高清真彩显示屏
项目二十一:几何图形的点线面循环
/* 【Arduino】168种传感器模块系列实验(资料代码+仿真编程+图形编程) 实验一百五十三:2.4寸TFT液晶触摸屏 彩屏模块 TFT-LCD 高清真彩显示屏 项目二十一:几何图形的点线面循环 模块直插,引脚用法如下: LCD_CS LCD_CD LCD_WR LCD_RD LCD_RST SD_SS SD_DI SD_DO SD_SCK Arduino Uno A3 A2 A1 A0 A4 10 11 12 13 LCD_D0 LCD_D1 LCD_D2 LCD_D3 LCD_D4 LCD_D5 LCD_D6 LCD_D7 Arduino Uno 8 9 2 3 4 5 6 7 */ #include <Adafruit_GFX.h> // Core graphics library #include <Adafruit_TFTLCD.h> // Hardware-specific library #include <TouchScreen.h> #define LCD_CS A3 #define LCD_CD A2 #define LCD_WR A1 #define LCD_RD A0 #define LCD_RESET A4 Adafruit_TFTLCD tft(LCD_CS, LCD_CD, LCD_WR, LCD_RD, LCD_RESET); #define BLACK 0x0000 #define BLUE 0x001F #define RED 0xF800 #define GREEN 0x07E0 #define WHITE 0xFFFF void setup(void) { tft.reset(); tft.begin(0x9341); tft.fillScreen(BLACK); } void loop() { // 点 tft.drawPixel(1, 1, RED); tft.drawPixel(10, 10, RED); tft.drawPixel(20, 20, RED); tft.drawPixel(40, 40, RED); tft.drawPixel(60, 60, RED); delay(500); // 线 tft.drawFastHLine(10, 10, 170, RED); tft.drawFastVLine(10, 10, 170, RED); tft.drawLine(10, 10, 100, 180, RED); delay(500); // 矩形 tft.drawRect(10, 10, 150, 100, RED); tft.fillRect(10, 120, 150, 100, RED); delay(500); // 圆角矩形 tft.drawRoundRect(10, 10, 150, 100, 10, RED); tft.fillRoundRect(10, 120, 150, 100, 10, RED); delay(500); // 圆形 tft.drawCircle(100, 100, 50, WHITE); tft.fillCircle(100, 260, 50, BLUE); delay(500); // 三角形 tft.drawTriangle(10, 10, 100, 15, 180, 100, GREEN); tft.fillTriangle(10, 110, 100, 115, 180, 200, GREEN); delay(500); //旋转 tft.setRotation(0); delay(500); //字符与文本 tft.fillScreen(GREEN); tft.drawChar(150, 10, 'A', RED, WHITE, 5); tft.setCursor(10, 50); tft.print("AB 3.14"); //默认前景色white、无背景色、大小为1 tft.setCursor(10, 80); tft.setTextSize( 4); tft.print("AB 3.14"); tft.setCursor(10, 115); tft.setTextColor(RED); //背景色不做设置 tft.setTextSize( 4); tft.print("AB 3.141516"); tft.setCursor(10, 180); tft.setTextColor(RED, WHITE); tft.setTextSize( 4); tft.setTextWrap(false); tft.print("AB 3.141516"); delay(500); //屏幕 tft.fillScreen(BLACK); delay(1000); tft.fillScreen(GREEN); delay(1000); //旋转 tft.setRotation(1); delay(500); tft.fillScreen(RED); delay(1000); tft.fillScreen(BLUE); delay(1000); //旋转 tft.setRotation(2); delay(500); tft.fillScreen(BLACK); delay(1000); //旋转 tft.setRotation(0); delay(500); }
【Arduino】168种传感器模块系列实验(资料代码+仿真编程+图形编程)
实验一百五十六:2.4寸TFT液晶触摸屏 彩屏模块 TFT-LCD 高清真彩显示屏
项目二十一:几何图形的点线面循环
实验动态图 https://imagemc.dfrobot.com.cn/data/attachment/forum/202107/08/065538kdc22d3yesy0b3uo.gif
【Arduino】168种传感器模块系列实验(资料代码+仿真编程+图形编程)
实验一百五十六:2.4寸TFT液晶触摸屏 彩屏模块 TFT-LCD 高清真彩显示屏
项目二十二:使用 Arduino 2.4 触摸屏创建简易绘画应用程序
实验开源代码
/* 【Arduino】168种传感器模块系列实验(资料代码+仿真编程+图形编程) 实验一百五十三:2.4寸TFT液晶触摸屏 彩屏模块 TFT-LCD 高清真彩显示屏 项目二十二:使用 Arduino 2.4 触摸屏创建简易绘画应用程序 模块直插,引脚用法如下: LCD_CS LCD_CD LCD_WR LCD_RD LCD_RST SD_SS SD_DI SD_DO SD_SCK Arduino Uno A3 A2 A1 A0 A4 10 11 12 13 LCD_D0 LCD_D1 LCD_D2 LCD_D3 LCD_D4 LCD_D5 LCD_D6 LCD_D7 Arduino Uno 8 9 2 3 4 5 6 7 */ #include <Adafruit_GFX.h> #include <Adafruit_TFTLCD.h> #include <TouchScreen.h> #if defined(__SAM3X8E__) #undef __FlashStringHelper::F(string_literal) #define F(string_literal) string_literal #endif #define YP A2 #define XM A1 #define YM 6 #define XP 7 #define TS_MINX 150 #define TS_MINY 120 #define TS_MAXX 920 #define TS_MAXY 940 TouchScreen ts = TouchScreen(XP, YP, XM, YM, 300); #define LCD_CS A3 #define LCD_CD A2 #define LCD_WR A1 #define LCD_RD A0 #define LCD_RESET A4 #define BLACK 0x0000 #define BLUE 0x001F #define RED 0xF800 #define GREEN 0x07E0 #define CYAN 0x07FF #define MAGENTA 0xF81F #define YELLOW 0xFFE0 #define WHITE 0xFFFF Adafruit_TFTLCD tft(LCD_CS, LCD_CD, LCD_WR, LCD_RD, LCD_RESET); #define BOXSIZE 40 #define PENRADIUS 3 int oldcolor, currentcolor; void setup(void) { Serial.begin(9600); tft.reset(); tft.begin(0x9341); tft.fillScreen(BLACK); tft.fillRect(0, 0, BOXSIZE, BOXSIZE, RED); tft.fillRect(BOXSIZE, 0, BOXSIZE, BOXSIZE, YELLOW); tft.fillRect(BOXSIZE * 2, 0, BOXSIZE, BOXSIZE, GREEN); tft.fillRect(BOXSIZE * 3, 0, BOXSIZE, BOXSIZE, CYAN); tft.fillRect(BOXSIZE * 4, 0, BOXSIZE, BOXSIZE, BLUE); tft.fillRect(BOXSIZE * 5, 0, BOXSIZE, BOXSIZE, MAGENTA); tft.drawRect(0, 0, BOXSIZE, BOXSIZE, WHITE); currentcolor = RED; pinMode(13, OUTPUT); } #define MINPRESSURE 10 #define MAXPRESSURE 1000 void loop() { digitalWrite(13, HIGH); TSPoint p = ts.getPoint(); digitalWrite(13, LOW); pinMode(XM, OUTPUT); pinMode(YP, OUTPUT); if (p.z > MINPRESSURE && p.z < MAXPRESSURE) { if (p.y < (TS_MINY - 5)) { tft.fillRect(0, BOXSIZE, tft.width(), tft.height() - BOXSIZE, BLACK); } p.x = map(p.x, TS_MINX, TS_MAXX, tft.width(), 0); p.y = map(p.y, TS_MINY, TS_MAXY, tft.height(), 0); if (p.y < BOXSIZE) { oldcolor = currentcolor; if (p.x < BOXSIZE) { currentcolor = RED; tft.drawRect(0, 0, BOXSIZE, BOXSIZE, WHITE); } else if (p.x < BOXSIZE * 2) { currentcolor = YELLOW; tft.drawRect(BOXSIZE, 0, BOXSIZE, BOXSIZE, WHITE); } else if (p.x < BOXSIZE * 3) { currentcolor = GREEN; tft.drawRect(BOXSIZE * 2, 0, BOXSIZE, BOXSIZE, WHITE); } else if (p.x < BOXSIZE * 4) { currentcolor = CYAN; tft.drawRect(BOXSIZE * 3, 0, BOXSIZE, BOXSIZE, WHITE); } else if (p.x < BOXSIZE * 5) { currentcolor = BLUE; tft.drawRect(BOXSIZE * 4, 0, BOXSIZE, BOXSIZE, WHITE); } else if (p.x < BOXSIZE * 6) { currentcolor = MAGENTA; tft.drawRect(BOXSIZE * 5, 0, BOXSIZE, BOXSIZE, WHITE); } if (oldcolor != currentcolor) { if (oldcolor == RED) tft.fillRect(0, 0, BOXSIZE, BOXSIZE, RED); if (oldcolor == YELLOW) tft.fillRect(BOXSIZE, 0, BOXSIZE, BOXSIZE, YELLOW); if (oldcolor == GREEN) tft.fillRect(BOXSIZE * 2, 0, BOXSIZE, BOXSIZE, GREEN); if (oldcolor == CYAN) tft.fillRect(BOXSIZE * 3, 0, BOXSIZE, BOXSIZE, CYAN); if (oldcolor == BLUE) tft.fillRect(BOXSIZE * 4, 0, BOXSIZE, BOXSIZE, BLUE); if (oldcolor == MAGENTA) tft.fillRect(BOXSIZE * 5, 0, BOXSIZE, BOXSIZE, MAGENTA); } } if (((p.y - PENRADIUS) > BOXSIZE) && ((p.y + PENRADIUS) < tft.height())) { tft.fillCircle(p.x, p.y, PENRADIUS, currentcolor); } } tft.setRotation(3); }
【Arduino】168种传感器模块系列实验(资料代码+仿真编程+图形编程)
实验一百五十三:2.4寸TFT液晶触摸屏 彩屏模块 TFT-LCD 高清真彩显示屏
项目二十二:使用 Arduino 2.4 触摸屏创建简易绘画应用程序
实验场景图
【Arduino】168种传感器模块系列实验(资料代码+仿真编程+图形编程)
实验一百五十三:2.4寸TFT液晶触摸屏 彩屏模块 TFT-LCD 高清真彩显示屏
项目二十三:两个按钮的极简开关板
实验开源代码
/* 【Arduino】168种传感器模块系列实验(资料代码+仿真编程+图形编程) 实验一百五十三:2.4寸TFT液晶触摸屏 彩屏模块 TFT-LCD 高清真彩显示屏 项目二十三:两个按钮的极简开关板 模块直插,引脚用法如下: LCD_CS LCD_CD LCD_WR LCD_RD LCD_RST SD_SS SD_DI SD_DO SD_SCK Arduino Uno A3 A2 A1 A0 A4 10 11 12 13 LCD_D0 LCD_D1 LCD_D2 LCD_D3 LCD_D4 LCD_D5 LCD_D6 LCD_D7 Arduino Uno 8 9 2 3 4 5 6 7 */ #if 1 #include <Adafruit_GFX.h> #include <MCUFRIEND_kbv.h> MCUFRIEND_kbv tft; #include <TouchScreen.h> #define MINPRESSURE 200 #define MAXPRESSURE 1000 // 所有触摸屏和接线都是不同的 const int XP = 6, XM = A2, YP = A1, YM = 7; //ID=0x9341 const int TS_LEFT = 907, TS_RT = 136, TS_TOP = 942, TS_BOT = 139; TouchScreen ts = TouchScreen(XP, YP, XM, YM, 300); Adafruit_GFX_Button on_btn, off_btn; int pixel_x, pixel_y; //更新全局变量 bool Touch_getXY(void) { TSPoint p = ts.getPoint(); pinMode(YP, OUTPUT); //恢复共享引脚 pinMode(XM, OUTPUT); digitalWrite(YP, HIGH); //因为 TFT 控制引脚 digitalWrite(XM, HIGH); bool pressed = (p.z > MINPRESSURE && p.z < MAXPRESSURE); if (pressed) { pixel_x = map(p.x, TS_LEFT, TS_RT, 0, tft.width()); //kbv 对我有意义 pixel_y = map(p.y, TS_TOP, TS_BOT, 0, tft.height()); } return pressed; } #define BLACK 0x0000 #define BLUE 0x001F #define RED 0xF800 #define GREEN 0x07E0 #define CYAN 0x07FF #define MAGENTA 0xF81F #define YELLOW 0xFFE0 #define WHITE 0xFFFF void setup(void) { Serial.begin(9600); tft.reset(); tft.begin(0x9341); tft.fillScreen(BLACK); tft.setRotation(2); // 翻转180度,对应硬件 delay(500); on_btn.initButton(&tft, 60, 200, 100, 40, WHITE, CYAN, BLACK, "ON", 2); off_btn.initButton(&tft, 180, 200, 100, 40, WHITE, CYAN, BLACK, "OFF", 2); on_btn.drawButton(false); off_btn.drawButton(false); tft.fillRect(40, 80, 160, 80, RED); } // 两个按钮很简单 void loop(void) { bool down = Touch_getXY(); on_btn.press(down && on_btn.contains(pixel_x, pixel_y)); off_btn.press(down && off_btn.contains(pixel_x, pixel_y)); if (on_btn.justReleased()) on_btn.drawButton(); if (off_btn.justReleased()) off_btn.drawButton(); if (on_btn.justPressed()) { on_btn.drawButton(true); tft.fillRect(40, 80, 160, 80, GREEN); } if (off_btn.justPressed()) { off_btn.drawButton(true); tft.fillRect(40, 80, 160, 80, RED); } } #endif
【Arduino】168种传感器模块系列实验(资料代码+仿真编程+图形编程)
实验一百五十三:2.4寸TFT液晶触摸屏 彩屏模块 TFT-LCD 高清真彩显示屏
项目二十三:两个按钮的极简开关板
Arduino实验场景图
【Arduino】168种传感器模块系列实验(资料代码+仿真编程+图形编程)
实验一百五十三:2.4寸TFT液晶触摸屏 彩屏模块 TFT-LCD 高清真彩显示屏
项目二十四:动态环形百分比图表
实验开源代码
/* 【Arduino】168种传感器模块系列实验(资料代码+仿真编程+图形编程) 实验一百五十三:2.4寸TFT液晶触摸屏 彩屏模块 TFT-LCD 高清真彩显示屏 项目二十四:动态环形百分比图表 模块直插,引脚用法如下: LCD_CS LCD_CD LCD_WR LCD_RD LCD_RST SD_SS SD_DI SD_DO SD_SCK Arduino Uno A3 A2 A1 A0 A4 10 11 12 13 LCD_D0 LCD_D1 LCD_D2 LCD_D3 LCD_D4 LCD_D5 LCD_D6 LCD_D7 Arduino Uno 8 9 2 3 4 5 6 7 */ #include "Adafruit_GFX.h" #include "MCUFRIEND_kbv.h" #include "Temperature.h" MCUFRIEND_kbv tft; #define PI 3.1415926535897932384626433832795 int n, f; int j, j2; int i, i2; int pct = 0; int d[5] = {10, 60, 16, 9, 10}; uint16_t col[5] = {0x7006, 0xF986, 0x6905, 0x7FF7, 0x024D}; void setup() { tft.reset(); Serial.begin(9600); tft.begin(0x9341); tft.invertDisplay(true); tft.setTextSize(2); } void loop() { tft.fillScreen(0x0042); tft.setRotation(1); for (int p = 0; p < 4000; p++) { j = 120 * (sin(PI * p / 2000)); i = 120 * (cos(PI * p / 2000)); j2 = 60 * (sin(PI * p / 2000)); i2 = 60 * (cos(PI * p / 2000)); tft.drawLine(i2 + 160, j2 + 160, i + 160, j + 160, col[n]); } n = 0; for (int a = 0; a < 5; a++) { pct += d[n] * 40; f = 4000 - pct; for (int b = 0; b < f; b++) { j = 120 * (sin(PI * b / 2000)); i = 120 * (cos(PI * b / 2000)); j2 = 60 * (sin(PI * b / 2000)); i2 = 60 * (cos(PI * b / 2000)); tft.drawLine(i2 + 160, j2 + 160, i + 160, j + 160, col[n + 1]); } tft.fillCircle(380, 100 + (30 * n), 10, col[n]); tft.setTextColor(0xffff); tft.setCursor(400, 94 + (30 * n)); tft.print(d[n]); tft.print("%"); n++; } while (1); }
项目二十四:动态环形百分比图表
Arduino实验场景图
【Arduino】168种传感器模块系列实验(资料代码+仿真编程+图形编程)
实验一百五十三:2.4寸TFT液晶触摸屏 彩屏模块 TFT-LCD 高清真彩显示屏
项目二十五:显示触摸屏电话面板
实验开源代码
/* 【Arduino】168种传感器模块系列实验(资料代码+仿真编程+图形编程) 实验一百五十三:2.4寸TFT液晶触摸屏 彩屏模块 TFT-LCD 高清真彩显示屏 项目二十五:显示触摸屏电话面板 模块直插,引脚用法如下: LCD_CS LCD_CD LCD_WR LCD_RD LCD_RST SD_SS SD_DI SD_DO SD_SCK Arduino Uno A3 A2 A1 A0 A4 10 11 12 13 LCD_D0 LCD_D1 LCD_D2 LCD_D3 LCD_D4 LCD_D5 LCD_D6 LCD_D7 Arduino Uno 8 9 2 3 4 5 6 7 */ #include <TouchScreen.h> //导入触摸库 #include <LCDWIKI_GUI.h> //Core graphics library #include <LCDWIKI_KBV.h> //Hardware-specific library //if the IC model is known or the modules is unreadable,you can use this constructed function LCDWIKI_KBV my_lcd(ILI9341, A3, A2, A1, A0, A4); //model,cs,cd,wr,rd,reset //if the IC model is not known and the modules is readable,you can use this constructed function //LCDWIKI_KBV my_lcd(240,320,A3,A2,A1,A0,A4);//width,height,cs,cd,wr,rd,reset /* r g b */ #define BLACK 0x0000 /* 0, 0, 0 */ #define BLUE 0x001F /* 0, 0, 255 */ #define RED 0xF800 /* 255, 0, 0 */ #define GREEN 0x07E0 /* 0, 255, 0 */ #define CYAN 0x07FF /* 0, 255, 255 */ #define MAGENTA 0xF81F /* 255, 0, 255 */ #define YELLOW 0xFFE0 /* 255, 255, 0 */ #define WHITE 0xFFFF /* 255, 255, 255 */ #define NAVY 0x000F /* 0, 0, 128 */ #define DARKGREEN 0x03E0 /* 0, 128, 0 */ #define DARKCYAN 0x03EF /* 0, 128, 128 */ #define MAROON 0x7800 /* 128, 0, 0 */ #define PURPLE 0x780F /* 128, 0, 128 */ #define OLIVE 0x7BE0 /* 128, 128, 0 */ #define LIGHTGREY 0xC618 /* 192, 192, 192 */ #define DARKGREY 0x7BEF /* 128, 128, 128 */ #define ORANGE 0xFD20 /* 255, 165, 0 */ #define GREENYELLOW 0xAFE5 /* 173, 255, 47 */ #define PINK 0xF81F /* 255, 0, 255 */ /******************* UI details */ #define BUTTON_R 25 //the radius of button #define BUTTON_SPACING_X 25 //the horizontal distance between button #define BUTTON_SPACING_Y 5 //the vertical distance between button #define EDG_Y 5 //lower edge distance #define EDG_X 20 //left and right distance #define YP A2 // must be an analog pin, use "An" notation! #define XM A1 // must be an analog pin, use "An" notation! #define YM 6 // can be a digital pin #define XP 7 // can be a digital pin //X 的触摸灵敏度 #define TS_MINX 124 #define TS_MAXX 906 //Y 的触摸灵敏度 #define TS_MINY 83 #define TS_MAXY 893 // 有一个状态行,例如 FONA 是否在工作 #define STATUS_X 10 #define STATUS_Y 65 //按下时的触摸灵敏度 #define MINPRESSURE 10 #define MAXPRESSURE 1000 TouchScreen ts = TouchScreen(XP, YP, XM, YM, 300); typedef struct _button_info { uint8_t button_name[10]; uint8_t button_name_size; uint16_t button_name_colour; uint16_t button_colour; uint16_t button_x; uint16_t button_y; } button_info; //按钮的定义 button_info phone_button[15] = { "1", 3, BLACK, CYAN, EDG_X + BUTTON_R - 1, my_lcd.Get_Display_Height() - EDG_Y - 4 * BUTTON_SPACING_Y - 9 * BUTTON_R - 1, "2", 3, BLACK, CYAN, EDG_X + 3 * BUTTON_R + BUTTON_SPACING_X - 1, my_lcd.Get_Display_Height() - EDG_Y - 4 * BUTTON_SPACING_Y - 9 * BUTTON_R - 1, "3", 3, BLACK, CYAN, EDG_X + 5 * BUTTON_R + 2 * BUTTON_SPACING_X - 1, my_lcd.Get_Display_Height() - EDG_Y - 4 * BUTTON_SPACING_Y - 9 * BUTTON_R - 1, "4", 3, BLACK, CYAN, EDG_X + BUTTON_R - 1, my_lcd.Get_Display_Height() - EDG_Y - 3 * BUTTON_SPACING_Y - 7 * BUTTON_R - 1, "5", 3, BLACK, CYAN, EDG_X + 3 * BUTTON_R + BUTTON_SPACING_X - 1, my_lcd.Get_Display_Height() - EDG_Y - 3 * BUTTON_SPACING_Y - 7 * BUTTON_R - 1, "6", 3, BLACK, CYAN, EDG_X + 5 * BUTTON_R + 2 * BUTTON_SPACING_X - 1, my_lcd.Get_Display_Height() - EDG_Y - 3 * BUTTON_SPACING_Y - 7 * BUTTON_R - 1, "7", 3, BLACK, CYAN, EDG_X + BUTTON_R - 1, my_lcd.Get_Display_Height() - EDG_Y - 2 * BUTTON_SPACING_Y - 5 * BUTTON_R - 1, "8", 3, BLACK, CYAN, EDG_X + 3 * BUTTON_R + BUTTON_SPACING_X - 1, my_lcd.Get_Display_Height() - EDG_Y - 2 * BUTTON_SPACING_Y - 5 * BUTTON_R - 1, "9", 3, BLACK, CYAN, EDG_X + 5 * BUTTON_R + 2 * BUTTON_SPACING_X - 1, my_lcd.Get_Display_Height() - EDG_Y - 2 * BUTTON_SPACING_Y - 5 * BUTTON_R - 1, "*", 3, BLACK, PINK, EDG_X + BUTTON_R - 1, my_lcd.Get_Display_Height() - EDG_Y - BUTTON_SPACING_Y - 3 * BUTTON_R - 1, "0", 3, BLACK, CYAN, EDG_X + 3 * BUTTON_R + BUTTON_SPACING_X - 1, my_lcd.Get_Display_Height() - EDG_Y - BUTTON_SPACING_Y - 3 * BUTTON_R - 1, "#", 3, BLACK, PINK, EDG_X + 5 * BUTTON_R + 2 * BUTTON_SPACING_X - 1, my_lcd.Get_Display_Height() - EDG_Y - BUTTON_SPACING_Y - 3 * BUTTON_R - 1, "end", 2, BLACK, RED, EDG_X + BUTTON_R - 1, my_lcd.Get_Display_Height() - EDG_Y - BUTTON_R - 1, "call", 2, BLACK, GREEN, EDG_X + 3 * BUTTON_R + BUTTON_SPACING_X - 1, my_lcd.Get_Display_Height() - EDG_Y - BUTTON_R - 1, "dele", 2, BLACK, LIGHTGREY, EDG_X + 5 * BUTTON_R + 2 * BUTTON_SPACING_X - 1, my_lcd.Get_Display_Height() - EDG_Y - BUTTON_R - 1, }; //显示字符串 void show_string(uint8_t *str, int16_t x, int16_t y, uint8_t csize, uint16_t fc, uint16_t bc, boolean mode) { my_lcd.Set_Text_Mode(mode); my_lcd.Set_Text_Size(csize); my_lcd.Set_Text_colour(fc); my_lcd.Set_Text_Back_colour(bc); my_lcd.Print_String(str, x, y); } //检查是否按下 boolean is_pressed(int16_t x1, int16_t y1, int16_t x2, int16_t y2, int16_t px, int16_t py) { if ((px > x1 && px < x2) && (py > y1 && py < y2)) { return true; } else { return false; } } //显示主菜单 void show_menu(void) { uint16_t i; for (i = 0; i < sizeof(phone_button) / sizeof(button_info); i++) { my_lcd.Set_Draw_color(phone_button[i].button_colour); my_lcd.Fill_Circle(phone_button[i].button_x, phone_button[i].button_y, BUTTON_R); show_string(phone_button[i].button_name, phone_button[i].button_x - strlen(phone_button[i].button_name)*phone_button[i].button_name_size * 6 / 2 + 1, phone_button[i].button_y - phone_button[i].button_name_size * 8 / 2 + 1, phone_button[i].button_name_size, phone_button[i].button_name_colour, BLACK, 1); } my_lcd.Set_Draw_color(BLACK); my_lcd.Fill_Rectangle(1, 1, my_lcd.Get_Display_Width() - 2, 3); my_lcd.Fill_Rectangle(1, 29, my_lcd.Get_Display_Width() - 2, 31); my_lcd.Fill_Rectangle(1, 1, 3, 31); my_lcd.Fill_Rectangle(my_lcd.Get_Display_Width() - 4, 1, my_lcd.Get_Display_Width() - 2, 31); } void setup(void) { Serial.begin(9600); my_lcd.Init_LCD(); Serial.println(my_lcd.Read_ID(), HEX); my_lcd.Fill_Screen(BLUE); show_menu(); } uint16_t text_x = 10, text_y = 6, text_x_add = 6 * phone_button[0].button_name_size, text_y_add = 8 * phone_button[0].button_name_size; uint16_t n = 0; void loop(void) { uint16_t i; digitalWrite(13, HIGH); TSPoint p = ts.getPoint(); digitalWrite(13, LOW); pinMode(XM, OUTPUT); pinMode(YP, OUTPUT); if (p.z > MINPRESSURE && p.z < MAXPRESSURE) { //p.x = my_lcd.Get_Display_Width()-map(p.x, TS_MINX, TS_MAXX, my_lcd.Get_Display_Width(), 0); //p.y = my_lcd.Get_Display_Height()-map(p.y, TS_MINY, TS_MAXY, my_lcd.Get_Display_Height(), 0); p.x = map(p.x, TS_MINX, TS_MAXX, 0, my_lcd.Get_Display_Width()); p.y = map(p.y, TS_MINY, TS_MAXY, 0, my_lcd.Get_Display_Height()); // } for (i = 0; i < sizeof(phone_button) / sizeof(button_info); i++) { //按下按钮 if (is_pressed(phone_button[i].button_x - BUTTON_R, phone_button[i].button_y - BUTTON_R, phone_button[i].button_x + BUTTON_R, phone_button[i].button_y + BUTTON_R, p.x, p.y)) { my_lcd.Set_Draw_color(DARKGREY); my_lcd.Fill_Circle(phone_button[i].button_x, phone_button[i].button_y, BUTTON_R); show_string(phone_button[i].button_name, phone_button[i].button_x - strlen(phone_button[i].button_name)*phone_button[i].button_name_size * 6 / 2 + 1, phone_button[i].button_y - phone_button[i].button_name_size * 8 / 2 + 1, phone_button[i].button_name_size, WHITE, BLACK, 1); delay(100); my_lcd.Set_Draw_color(phone_button[i].button_colour); my_lcd.Fill_Circle(phone_button[i].button_x, phone_button[i].button_y, BUTTON_R); show_string(phone_button[i].button_name, phone_button[i].button_x - strlen(phone_button[i].button_name)*phone_button[i].button_name_size * 6 / 2 + 1, phone_button[i].button_y - phone_button[i].button_name_size * 8 / 2 + 1, phone_button[i].button_name_size, phone_button[i].button_name_colour, BLACK, 1); if (i < 12) { if (n < 13) { show_string(phone_button[i].button_name, text_x, text_y, phone_button[i].button_name_size, GREENYELLOW, BLACK, 1); text_x += text_x_add - 1; n++; } } else if (12 == i) //节目通话结束 { my_lcd.Set_Draw_color(BLUE); my_lcd.Fill_Rectangle(0, 33, my_lcd.Get_Display_Width() - 1, 42); show_string("Calling ended", CENTER, 33, 1, OLIVE, BLACK, 1); } else if (13 == i) //显示呼叫 { my_lcd.Set_Draw_color(BLUE); my_lcd.Fill_Rectangle(0, 33, my_lcd.Get_Display_Width() - 1, 42); show_string("Calling...", CENTER, 33, 1, OLIVE, BLACK, 1); } else if (14 == i) //删除按钮 { if (n > 0) { my_lcd.Set_Draw_color(BLUE); text_x -= (text_x_add - 1); my_lcd.Fill_Rectangle(text_x, text_y, text_x + text_x_add - 1, text_y + text_y_add - 2); n--; } } } } } }
【Arduino】168种传感器模块系列实验(资料代码+仿真编程+图形编程)
实验一百五十三:2.4寸TFT液晶触摸屏 彩屏模块 TFT-LCD 高清真彩显示屏
项目二十五:显示触摸屏电话面板
实验场景图
【Arduino】168种传感器模块系列实验(资料代码+仿真编程+图形编程)
实验一百五十三:2.4寸TFT液晶触摸屏 彩屏模块 TFT-LCD 高清真彩显示屏
项目二十六:显示动态中文——深圳市欢迎您
实验开源代码
/* 【Arduino】168种传感器模块系列实验(资料代码+仿真编程+图形编程) 实验一百五十三:2.4寸TFT液晶触摸屏 彩屏模块 TFT-LCD 高清真彩显示屏 项目二十六:显示动态中文——深圳市欢迎您 模块直插,引脚用法如下: LCD_CS LCD_CD LCD_WR LCD_RD LCD_RST SD_SS SD_DI SD_DO SD_SCK Arduino Uno A3 A2 A1 A0 A4 10 11 12 13 LCD_D0 LCD_D1 LCD_D2 LCD_D3 LCD_D4 LCD_D5 LCD_D6 LCD_D7 Arduino Uno 8 9 2 3 4 5 6 7 */ #include <LCDWIKI_GUI.h> //Core graphics library #include <LCDWIKI_KBV.h> //Hardware-specific library #include "font.h" //if the IC model is known or the modules is unreadable,you can use this constructed function LCDWIKI_KBV my_lcd(ILI9341, A3, A2, A1, A0, A4); //model,cs,cd,wr,rd,reset //if the IC model is not known and the modules is readable,you can use this constructed function //LCDWIKI_KBV my_lcd(240,320,A3,A2,A1,A0,A4);//width,height,cs,cd,wr,rd,reset #define BLACK 0x0000 #define BLUE 0x001F #define RED 0xF800 #define GREEN 0x07E0 #define CYAN 0x07FF #define MAGENTA 0xF81F #define YELLOW 0xFFE0 #define WHITE 0xFFFF char *aspect_name[] = {"PORTRAIT", "LANDSCAPE", "PORTRAIT_REV", "LANDSCAPE_REV"}; char *color_name[] = { "BLUE", "GREEN", "RED", "WHITE" , "CYAN", "MAGENTA", "YELLOW"}; uint16_t color_mask[] = { 0x001F, 0x07E0, 0xF800, 0xFFFF, 0x07FF, 0xF81F, 0xFFE0 }; void show_16font(uint16_t x, uint16_t y, uint16_t fc, uint16_t bc, uint8_t *str, uint8_t mode) { uint16_t i, j, k, c_num, color = 0; boolean first = true; c_num = sizeof(tfont16) / sizeof(typFNT_GB16); for (k = 0; k < c_num; k++) { //pgm_read_byte if ((pgm_read_byte(&tfont16[k].Index[0]) == *str) && (pgm_read_byte(&tfont16[k].Index[1]) == *(str + 1))) { my_lcd.Set_Addr_Window(x, y, x + 16 - 1, y + 16 - 1); for (j = 0; j < 32; j++) { for (i = 0; i < 8; i++) { if (mode) //叠加模式 { if (pgm_read_byte(&tfont16[k].Msk[j]) & (0x80 >> i)) { my_lcd.Set_Draw_color(fc); my_lcd.Draw_Pixel(x + ((j * 8 + i) % 16), y + ((j * 8 + i) / 16)); } // x++; // if((x-x0)==16) // { // x = x0; // y++; // } } else //非叠加模式 { if (pgm_read_byte(&tfont16[k].Msk[j]) & (0x80 >> i)) { color = fc; } else { color = bc; } my_lcd.Push_Any_Color(&color, 1, first, 0); first = false; } } } } } } void show_24font(uint16_t x, uint16_t y, uint16_t fc, uint16_t bc, uint8_t *str, uint8_t mode) { uint16_t i, j, k, c_num, color; boolean first = true; c_num = sizeof(tfont24) / sizeof(typFNT_GB24); for (k = 0; k < c_num; k++) { if ((pgm_read_byte(&tfont24[k].Index[0]) == *str) && (pgm_read_byte(&tfont24[k].Index[1]) == *(str + 1))) { my_lcd.Set_Addr_Window(x, y, x + 24 - 1, y + 24 - 1); for (j = 0; j < 72; j++) { for (i = 0; i < 8; i++) { if (mode) //叠加模式 { if (pgm_read_byte(&tfont24[k].Msk[j]) & (0x80 >> i)) { my_lcd.Set_Draw_color(fc); my_lcd.Draw_Pixel(x + ((j * 8 + i) % 24), y + ((j * 8 + i) / 24)); } // x++; // if((x-x0)==32) // { // x = x0; // y++; // } } else //非叠加模式 { if (pgm_read_byte(&tfont24[k].Msk[j]) & (0x80 >> i)) { color = fc; } else { color = bc; } my_lcd.Push_Any_Color(&color, 1, first, 0); first = false; } } } } } } void show_32font(uint16_t x, uint16_t y, uint16_t fc, uint16_t bc, uint8_t *str, uint8_t mode) { uint16_t i, j, k, c_num, color; boolean first = true; c_num = sizeof(tfont32) / sizeof(typFNT_GB32); for (k = 0; k < c_num; k++) { if ((pgm_read_byte(&tfont32[k].Index[0]) == *str) && (pgm_read_byte(&tfont32[k].Index[1]) == *(str + 1))) { my_lcd.Set_Addr_Window(x, y, x + 32 - 1, y + 32 - 1); for (j = 0; j < 128; j++) { for (i = 0; i < 8; i++) { if (mode) //叠加模式 { if (pgm_read_byte(&tfont32[k].Msk[j]) & (0x80 >> i)) { my_lcd.Set_Draw_color(fc); my_lcd.Draw_Pixel(x + ((j * 8 + i) % 32), y + ((j * 8 + i) / 32)); } // x++; // if((x-x0)==32) // { // x = x0; // y++; // } } else //非叠加模式 { if (pgm_read_byte(&tfont32[k].Msk[j]) & (0x80 >> i)) { color = fc; } else { color = bc; } my_lcd.Push_Any_Color(&color, 1, first, 0); first = false; } } } } } } void show_chinese(uint16_t x, uint16_t y, uint16_t fc, uint16_t bc, uint8_t *str, uint16_t csize, uint8_t mode) { int i = 0; if (x > (my_lcd.Get_Display_Width() - csize) || y > (my_lcd.Get_Display_Height() - csize)) { return; } while (*str != '\0') { // i += 5; // my_lcd.Draw_Fast_VLine(i, 10, 100); if (csize == 32) { show_32font(x, y, fc, bc, str, mode); } else if (csize == 24) { show_24font(x, y, fc, bc, str, mode); } else { show_16font(x, y, fc, bc, str, mode); } str += 3; x += csize; } } void show_chinese_test(void) { uint16_t i; my_lcd.Set_Rotation(1); show_chinese(0, 10, RED, BLACK, "深圳市欢迎您", 16, 1); show_chinese(0, 26, RED, BLACK, "深圳市欢迎您", 24, 1); show_chinese(0, 50, RED, BLACK, "深圳市欢迎您", 32, 1); show_chinese(0, 82, GREEN, BLACK, "深圳市欢迎您", 16, 1); show_chinese(0, 98, GREEN, BLACK, "深圳市欢迎您", 24, 1); show_chinese(0, 122, GREEN, BLACK, "深圳市欢迎您", 32, 1); show_chinese(0, 154, BLUE, BLACK, "深圳市欢迎您", 16, 1); show_chinese(0, 170, BLUE, BLACK, "深圳市欢迎您", 24, 1); show_chinese(0, 194, BLUE, BLACK, "深圳市欢迎您", 32, 1); for (i = 1; i <= my_lcd.Get_Display_Width(); i++) { my_lcd.Vert_Scroll(0, my_lcd.Get_Display_Width(), i); delay(10); } delay(2000); my_lcd.Fill_Screen(BLACK); show_chinese(0, 10, RED, WHITE, "深圳市欢迎您", 16, 0); show_chinese(0, 26, RED, WHITE, "深圳市欢迎您", 24, 0); show_chinese(0, 50, RED, WHITE, "深圳市欢迎您", 32, 0); show_chinese(0, 82, GREEN, WHITE, "深圳市欢迎您", 16, 0); show_chinese(0, 98, GREEN, WHITE, "深圳市欢迎您", 24, 0); show_chinese(0, 122, GREEN, WHITE, "深圳市欢迎您", 32, 0); show_chinese(0, 154, BLUE, WHITE, "深圳市欢迎您", 16, 0); show_chinese(0, 170, BLUE, WHITE, "深圳市欢迎您", 24, 0); show_chinese(0, 194, BLUE, WHITE, "深圳市欢迎您", 32, 0); delay(1000); } void show_pic(void) { int i; my_lcd.Set_Addr_Window(my_lcd.Get_Display_Width() - 40 - 40, 20, my_lcd.Get_Display_Width() - 40 - 1, 59); my_lcd.Push_Any_Color(penguin_pic, 1600, 1, 1); } void windowScroll(int16_t x, int16_t y, int16_t wid, int16_t ht, int16_t dx, int16_t dy, uint16_t *buf) { if (dx) { for (int16_t row = 0; row < ht; row++) { my_lcd.Read_GRAM(x, y + row, buf, wid, 1); my_lcd.Set_Addr_Window(x, y + row, x + wid - 1, y + row); my_lcd.Push_Any_Color(buf + dx, wid - dx, 1, 0); my_lcd.Push_Any_Color(buf + 0, dx, 0, 0); } } if (dy) { for (int16_t col = 0; col < wid; col++) { my_lcd.Read_GRAM(x + col, y, buf, 1, ht); my_lcd.Set_Addr_Window(x + col, y, x + col, y + ht - 1); my_lcd.Push_Any_Color(buf + dy, ht - dy, 1, 0); my_lcd.Push_Any_Color(buf + 0, dy, 0, 0); } } } void show_string(uint8_t *str, int16_t x, int16_t y, uint8_t csize, uint16_t fc, uint16_t bc, boolean mode) { my_lcd.Set_Text_Mode(mode); my_lcd.Set_Text_Size(csize); my_lcd.Set_Text_colour(fc); my_lcd.Set_Text_Back_colour(bc); my_lcd.Print_String(str, x, y); } void color_test() { int n, i; int cnum = sizeof(color_mask) / sizeof(uint16_t); for (i = 0; i < cnum; i++) { for (n = 0; n < 32; n++) { my_lcd.Set_Draw_color(n * 8, n * 8, n * 8); my_lcd.Set_Draw_color(my_lcd.Get_Draw_color()&color_mask[i]); my_lcd.Fill_Rectangle(n * my_lcd.Get_Display_Width() / 32, (my_lcd.Get_Display_Height() / cnum)*i, (n + 1)*my_lcd.Get_Display_Width() / 32, (my_lcd.Get_Display_Height() / cnum) * (i + 1)); } show_string(color_name[i], 0, ((my_lcd.Get_Display_Height() / cnum) - 16) / 2 + (my_lcd.Get_Display_Height() / cnum)*i, 2, color_mask[i], BLACK, 1); } delay(500); } void text_test(void) { show_string("Hello World!", 0, 0, 1, RED, BLACK, 0); my_lcd.Set_Text_colour(YELLOW); my_lcd.Set_Text_Size(2); my_lcd.Print_Number_Float(01234.56789, 4, 0, 8, '.', 0, ' '); show_string("ABCDEF123456", 0, 24, 3, BLUE, BLACK, 0); show_string("Good", 0, 56, 5, GREEN, BLACK, 0); show_string("By utilizing breath", 0, 96, 2, GREEN, BLACK, 0); show_string("we soften our experiences.", 0, 112, 1, GREEN, BLACK, 0); show_string("If we dam them up,", 0, 120, 1, GREEN, BLACK, 0); show_string("our lives will stagnate,", 0, 128, 1, GREEN, BLACK, 0); show_string("but we keep them flowing,", 0, 136, 1, GREEN, BLACK, 0); show_string("we allow more newness", 0, 144, 1, GREEN, BLACK, 0); show_string("and greater experiences", 0, 152, 1, GREEN, BLACK, 0); show_string("to blossom.Yes OK", 0, 160, 1, GREEN, BLACK, 0); } void setup() { Serial.begin(9600); my_lcd.Init_LCD(); Serial.println(my_lcd.Read_ID(), HEX); my_lcd.Fill_Screen(BLACK); // show_chinese_test(); // show_pic(); } void loop() { uint16_t max_scroll, rotation, i, n; my_lcd.Set_Rotation(0); uint16_t scrollbuf[my_lcd.Get_Display_Height()]; show_chinese_test(); delay(250); for (rotation = 0; rotation < 4; rotation++) { my_lcd.Set_Rotation(rotation); my_lcd.Fill_Screen(BLACK); //text color_test(); my_lcd.Fill_Screen(BLACK); delay(500); text_test(); delay(500); for (n = 0; n < 32; n++) { my_lcd.Set_Draw_color(n * 8, n * 8, n * 8); my_lcd.Set_Draw_color(my_lcd.Get_Draw_color()&color_mask[rotation]); my_lcd.Fill_Rectangle(n * my_lcd.Get_Display_Width() / 32, 48, (n + 1)*my_lcd.Get_Display_Width() / 32, 112); } show_string("COLOR TESTING", 50, 72, 2, color_mask[rotation + 1], BLACK, 1); show_string(aspect_name[rotation], 0, 184, 2, WHITE, BLACK, 0); show_pic(); show_string("VERTICAL SCROLL UP", 0, 168, 2, YELLOW, BLACK, 0); if (my_lcd.Get_Rotation() & 1) { max_scroll = my_lcd.Get_Display_Width(); } else { max_scroll = my_lcd.Get_Display_Height(); } for (i = 1; i <= max_scroll; i++) { my_lcd.Vert_Scroll(0, max_scroll, i); delay(10); } my_lcd.Vert_Scroll(0, max_scroll, 0); show_string("VERTICAL SCROLL DN", 0, 168, 2, GREEN, BLACK, 0); for (i = 1; i <= max_scroll; i++) { my_lcd.Vert_Scroll(0, max_scroll, 0 - i); delay(10); } delay(500); my_lcd.Vert_Scroll(0, max_scroll, 0); if (!(rotation & 1)) { show_string("ONLY THE COLOR BAND", 0, 200, 2, BLUE, BLACK, 0); for (i = 1; i <= 64; i++) { my_lcd.Vert_Scroll(48, 64, i); delay(20); } delay(500); my_lcd.Vert_Scroll(0, max_scroll, 0); } show_string("SOFTWARE SCROLL", 0, 216, 2, YELLOW, BLACK, 0); for (int16_t i = my_lcd.Get_Display_Width(), dx = 4, dy = 0; i > 0; i -= dx) { windowScroll(0, 216, my_lcd.Get_Display_Width(), 16, dx, dy, scrollbuf); } delay(1000); } my_lcd.Invert_Display(true); delay(1000); my_lcd.Invert_Display(false); my_lcd.Fill_Screen(BLACK); }
【Arduino】168种传感器模块系列实验(资料代码+仿真编程+图形编程)
实验一百五十三:2.4寸TFT液晶触摸屏 彩屏模块 TFT-LCD 高清真彩显示屏
项目二十六:显示动态中文——深圳市欢迎您
实验场景图 https://imagemc.dfrobot.com.cn/data/attachment/forum/202107/08/114904ww7x7qjwjvn8a1q9.gif
【Arduino】168种传感器模块系列实验(资料代码+仿真编程+图形编程)
实验一百五十三:2.4寸TFT液晶触摸屏 彩屏模块 TFT-LCD 高清真彩显示屏
项目二十六:显示动态中文——深圳市欢迎您
实验场景图 之二 https://imagemc.dfrobot.com.cn/data/attachment/forum/202107/08/115644rvtovda4jdtu9bbd.gif
【Arduino】168种传感器模块系列实验(资料代码+仿真编程+图形编程)
实验一百六十五:2.4寸TFT液晶触摸屏 彩屏模块 TFT-LCD 高清真彩显示屏
项目二十六:显示动态中文——深圳市欢迎您
实验视频(1分30秒)
https://v.youku.com/v_show/id_XNTE3OTIxOTY4MA==.html
标签:动手做,153,Arduino,button,LCD,uint16,tft,my,define From: https://www.cnblogs.com/eagler8/p/17539357.html