驴友花雕
发表于 2021-7-8 10:12:57
【Arduino】168种传感器模块系列实验(资料代码+仿真编程+图形编程)实验一百六十五:2.4寸TFT液晶触摸屏 彩屏模块 TFT-LCD 高清真彩显示屏项目二十五:显示触摸屏电话面板
实验场景图
驴友花雕
发表于 2021-7-8 11:01:03
【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
#defineBLACK 0x0000
#define BLUE 0x001F
#define RED 0xF800
#define GREEN 0x07E0
#define CYAN 0x07FF
#define MAGENTA 0xF81F
#define YELLOW0xFFE0
#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.Index) == *str) && (pgm_read_byte(&tfont16.Index) == *(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.Msk) & (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.Msk) & (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.Index) == *str) && (pgm_read_byte(&tfont24.Index) == *(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.Msk) & (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.Msk) & (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.Index) == *str) && (pgm_read_byte(&tfont32.Index) == *(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.Msk) & (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.Msk) & (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);
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, 0, ((my_lcd.Get_Display_Height() / cnum) - 16) / 2 + (my_lcd.Get_Display_Height() / cnum)*i, 2, color_mask, 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;
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);
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, BLACK, 1);
show_string(aspect_name, 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);
}
驴友花雕
发表于 2021-7-8 11:49:09
【Arduino】168种传感器模块系列实验(资料代码+仿真编程+图形编程)
实验一百六十五:2.4寸TFT液晶触摸屏 彩屏模块 TFT-LCD 高清真彩显示屏
项目二十六:显示动态中文——深圳市欢迎您
实验场景图
驴友花雕
发表于 2021-7-8 11:56:49
本帖最后由 驴友花雕 于 2021-7-8 12:19 编辑
【Arduino】168种传感器模块系列实验(资料代码+仿真编程+图形编程)
实验一百六十五:2.4寸TFT液晶触摸屏 彩屏模块 TFT-LCD 高清真彩显示屏
项目二十六:显示动态中文——深圳市欢迎您
实验场景图 之二
驴友花雕
发表于 2021-7-8 17:31:41
【Arduino】168种传感器模块系列实验(资料代码+仿真编程+图形编程)
实验一百六十五:2.4寸TFT液晶触摸屏 彩屏模块 TFT-LCD 高清真彩显示屏
项目二十六:显示动态中文——深圳市欢迎您
实验视频(1分30秒)
https://v.youku.com/v_show/id_XNTE3OTIxOTY4MA==.html
https://v.youku.com/v_show/id_XNTE3OTIxOTY4MA==.html
快乐生活
发表于 2021-7-19 11:03:37
驴友花雕 发表于 2021-6-28 18:59
【Arduino】168种传感器模块系列实验(资料代码+仿真编程+图形编程)
实验一百六十五:2.4寸 ...
哪里可以下载资料呢
驴友花雕
发表于 2021-7-20 05:08:19
快乐生活 发表于 2021-7-19 11:03
哪里可以下载资料呢
具体什么资料呢?
驴友花雕
发表于 2021-9-8 07:58:20
Arduino 系列传感器和执行器模块实验目录清单:
一块扩展板完成Arduino的10类37项实验(代码+图形+仿真)
https://mc.dfrobot.com.cn/thread-280845-1-1.html
连杆形式的腿机构十一种:盘点机器人行走背后的机械原理
https://mc.dfrobot.com.cn/thread-308097-1-1.html
【花雕动手做】超低成本,尝试五十元的麦克纳姆轮小车!
https://mc.dfrobot.com.cn/thread-307863-1-1.html
【花雕动手做】超迷你哦,用徽商香烟盒做个智能小车!
https://mc.dfrobot.com.cn/thread-307907-1-1.html
【花雕动手做】太搞笑啦,一支胶管制成二只蠕动机器人
https://mc.dfrobot.com.cn/thread-308046-1-1.html
【花雕动手做】快餐盒盖,极低成本搭建机器人实验平台
https://mc.dfrobot.com.cn/thread-308063-1-1.html
【花雕动手做】特别苗条,使用微波传感器控制的纤细小车
https://mc.dfrobot.com.cn/thread-308866-1-1.html
【花雕动手做】脑洞大开、五花八门的简易机器人66种
https://mc.dfrobot.com.cn/thread-307900-1-1.html
实验一百五十八:QMC5883L电子指南针罗盘模块 三轴磁场传感器GY-271
https://mc.dfrobot.com.cn/thread-308195-1-1.html
实验一百六十三:BMI160 6轴惯性运动传感器 16位3轴加速度+超低功耗3轴陀螺仪I2C/SPI 14LGA
https://mc.dfrobot.com.cn/thread-310371-1-1.html
实验一百六十五:2.4 英寸 TFT LCD 触摸屏模块 XPT2046 PCB ILI9341 240x320 像素 8 位 SPI 串口显示器
https://mc.dfrobot.com.cn/thread-309803-1-1.html
实验一百七十六:6mm大尺寸8x8LED方块方格点阵模块 可级联 红绿蓝白色 可选8级亮度
https://mc.dfrobot.com.cn/thread-309845-1-1.html
实验一百八十三:GY-530 VL53L0X 激光测距 ToF测距 飞行时间测距传感器模块 IIC通信协议
https://mc.dfrobot.com.cn/thread-310273-1-1.html
实验一百八十五:MAX4466声音传感器 驻极体话筒放大器 麦克风可调功放模块 microphone
https://mc.dfrobot.com.cn/thread-310193-1-1.html
实验一百八十九:TDA1308 硅麦克风 数字咪头放大模块 拾音器放大板 楼氏SUNLEPHANT
https://mc.dfrobot.com.cn/thread-310246-1-1.html
实验一百九十三:TCS34725颜色识别传感器 RGB IIC明光感应模块 ColorSensor
https://mc.dfrobot.com.cn/thread-310209-1-1.html
实验二百:RCWL-0515微波雷达感应开关 人体感应 智能感应探测传感器 12-15米远距离2.7G微波检测模块
https://mc.dfrobot.com.cn/thread-310313-1-1.html
实验二百零三:Air724UG合宙 Cat14G模块 DTU物联网UART串口通信数据TCP透传 核心板组合套餐
https://mc.dfrobot.com.cn/thread-310342-1-1.html
实验二百零九:Gravity: I2C & UART BC20 NB-IoT & GNSS通信模块 NB-IoT广域低功耗无线通信 GPS/北斗精准定位
https://mc.dfrobot.com.cn/thread-310433-1-1.html