71428浏览
楼主: 驴友花雕

[项目] 【Arduino】168种传感器模块系列实验(165)---2.4寸TFT液晶触...

[复制链接]

驴友花雕  中级技神
 楼主|

发表于 2021-6-26 12:33:11

【Arduino】168种传感器模块系列实验(资料代码+仿真编程+图形编程)
  实验一百六十五:2.4寸TFT液晶触摸屏 彩屏模块 TFT-LCD 高清真彩显示屏
  项目之二:清屏显示黑、白、红、绿、蓝色

  1. /*
  2.   【Arduino】168种传感器模块系列实验(资料代码+仿真编程+图形编程)
  3.   实验一百六十五:2.4寸TFT液晶触摸屏 彩屏模块 TFT-LCD 高清真彩显示屏
  4.   项目之二:清屏显示黑、白、红、绿、蓝色
  5.   模块直插,引脚用法如下:
  6.   LCD_CS LCD_CD LCD_WR LCD_RD LCD_RST SD_SS SD_DI SD_DO SD_SCK
  7.   Arduino Uno A3 A2 A1 A0 A4 10 11 12 13
  8.   LCD_D0 LCD_D1 LCD_D2 LCD_D3 LCD_D4 LCD_D5 LCD_D6 LCD_D7
  9.   Arduino Uno 8 9 2 3 4 5 6 7
  10. */
  11. #include <LCDWIKI_GUI.h> //导入核心图形库
  12. #include <LCDWIKI_KBV.h> //导入特定硬件的库
  13. //如果 IC 模型已知或模块不可读,则可以使用此构造函数
  14. LCDWIKI_KBV mylcd(ILI9341, A3, A2, A1, A0, A4); //模型、CS、CD、WR、RD、重置
  15. //如果 IC 模型未知且模块可读,则可以使用此构造函数
  16. //LCDWIKI_KBV mylcd(240,320,A3,A2,A1,A0,A4);//宽度、高度、cs、cd、wr、rd、重置
  17. void setup() {
  18.   Serial.begin(9600);
  19.   mylcd.Init_LCD(); //初始化液晶显示器
  20.   Serial.println(mylcd.Read_ID(), HEX);
  21.   mylcd.Fill_Screen(0xFFFF); //显示白色
  22. }
  23. void loop() {
  24.   //依次显示黑、白、红、绿、蓝
  25.   mylcd.Fill_Screen(0, 0, 0);
  26.   mylcd.Fill_Screen(255, 255, 255);
  27.   mylcd.Fill_Screen(255, 0, 0);
  28.   mylcd.Fill_Screen(0, 255, 0);
  29.   mylcd.Fill_Screen(0, 0, 255);
  30.   delay(3000);
  31.   mylcd.Fill_Screen(0x0000);
  32.   delay(1000);
  33.   mylcd.Fill_Screen(0xFFFF);
  34.   delay(1000);
  35.   mylcd.Fill_Screen(0xF800);
  36.   delay(1000);
  37.   mylcd.Fill_Screen(0x07E0);
  38.   delay(1000);
  39.   mylcd.Fill_Screen(0x001F);
  40.   delay(1000);
  41. }
复制代码


回复

使用道具 举报

驴友花雕  中级技神
 楼主|

发表于 2021-6-26 12:35:23

【Arduino】168种传感器模块系列实验(资料代码+仿真编程+图形编程)
  实验一百六十五:2.4寸TFT液晶触摸屏 彩屏模块 TFT-LCD 高清真彩显示屏
  项目之二:清屏显示黑、白、红、绿、蓝色

动图 【Arduino】168种传感器模块系列实验(165)---2.4寸TFT液晶触...图1

回复

使用道具 举报

驴友花雕  中级技神
 楼主|

发表于 2021-6-27 07:56:56

【Arduino】168种传感器模块系列实验(资料代码+仿真编程+图形编程)
  实验一百六十五:2.4寸TFT液晶触摸屏 彩屏模块 TFT-LCD 高清真彩显示屏
  项目之三:使用图形库随机绘制各种图形,三角函数以及英文字符串

  1. /*
  2.   【Arduino】168种传感器模块系列实验(资料代码+仿真编程+图形编程)
  3.   实验一百六十五:2.4寸TFT液晶触摸屏 彩屏模块 TFT-LCD 高清真彩显示屏
  4.   项目之三:使用图形库随机绘制各种图形,三角函数以及英文字符串
  5.   模块直插,引脚用法如下:
  6.   LCD_CS LCD_CD LCD_WR LCD_RD LCD_RST SD_SS SD_DI SD_DO SD_SCK
  7.   Arduino Uno A3 A2 A1 A0 A4 10 11 12 13
  8.   LCD_D0 LCD_D1 LCD_D2 LCD_D3 LCD_D4 LCD_D5 LCD_D6 LCD_D7
  9.   Arduino Uno 8 9 2 3 4 5 6 7
  10. */
  11. #include <LCDWIKI_GUI.h> //导入核心图形库
  12. #include <LCDWIKI_KBV.h> //导入特定硬件库
  13. //如果 IC 模型已知或模块不可读,则可以使用此构造函数
  14. LCDWIKI_KBV my_lcd(ILI9341, A3, A2, A1, A0, A4); //模型、CS、CD、WR、RD、重置
  15. //如果 IC 模型未知且模块可读,则可以使用此构造函数
  16. //LCDWIKI_KBV my_lcd(240,320,A3,A2,A1,A0,A4);//屏幕宽度、高度、cs、cd、wr、rd、重置
  17. void show_string(uint8_t *str, int16_t x, int16_t y, uint8_t csize, uint16_t fc, uint16_t bc, boolean mode) {
  18.   my_lcd.Set_Text_Mode(mode);
  19.   my_lcd.Set_Text_Size(csize);
  20.   my_lcd.Set_Text_colour(fc);
  21.   my_lcd.Set_Text_Back_colour(bc);
  22.   my_lcd.Print_String(str, x, y);
  23. }
  24. //显示主图框
  25. unsigned long show_text(void) {
  26.   unsigned long time_start = micros();
  27.   my_lcd.Set_Draw_color(32, 0, 255);
  28.   my_lcd.Fill_Rectangle(0, 0, my_lcd.Get_Display_Width() - 1, 14);
  29.   show_string("---> Hello World <---", CENTER, 3, 1, 0x07E0, 0, 1);
  30.   my_lcd.Set_Draw_color(128, 128, 128);
  31.   my_lcd.Fill_Rectangle(0, my_lcd.Get_Display_Height() - 15, my_lcd.Get_Display_Width() - 1, my_lcd.Get_Display_Height() - 1);
  32.   show_string("* Universal Color TFT Display Library *", CENTER, my_lcd.Get_Display_Height() - 11, 1, 0xFFFF, 0, 1);
  33.   my_lcd.Set_Draw_color(255, 0, 0);
  34.   my_lcd.Draw_Rectangle(0, 15, my_lcd.Get_Display_Width() - 1, my_lcd.Get_Display_Height() - 16);
  35.   return micros() - time_start;
  36. }
  37. //显示三角函数
  38. unsigned long show_triangle_function(void) {
  39.   uint16_t i;
  40.   unsigned long time_start = micros();
  41.   //绘制十字准线
  42.   my_lcd.Set_Draw_color(0, 0, 255);
  43.   my_lcd.Draw_Fast_VLine(my_lcd.Get_Display_Width() / 2 - 1, 16, my_lcd.Get_Display_Height() - 32);
  44.   my_lcd.Draw_Fast_HLine(1, my_lcd.Get_Display_Height() / 2 - 1, my_lcd.Get_Display_Width() - 2);
  45.   for (i = 1; i <= (my_lcd.Get_Display_Height() - 32) / 2 / 10; i++) {
  46.     my_lcd.Draw_Fast_HLine(my_lcd.Get_Display_Width() / 2 - 1 - 2, my_lcd.Get_Display_Height() / 2 - 1 - i * 10, 5);
  47.     my_lcd.Draw_Fast_HLine(my_lcd.Get_Display_Width() / 2 - 1 - 2, my_lcd.Get_Display_Height() / 2 - 1 + i * 10, 5);
  48.   }
  49.   for (i = 1; i <= (my_lcd.Get_Display_Width() - 2) / 2 / 10; i++) {
  50.     my_lcd.Draw_Fast_VLine(my_lcd.Get_Display_Width() / 2 - 1 - i * 10, my_lcd.Get_Display_Height() / 2 - 1 - 2, 5);
  51.     my_lcd.Draw_Fast_VLine(my_lcd.Get_Display_Width() / 2 - 1 + i * 10, my_lcd.Get_Display_Height() / 2 - 1 - 2, 5);
  52.   }
  53.   // 绘制罪恶线(Draw sin lines)
  54.   show_string("sin", 5, 17, 1, 0x07FF, 0, 0);
  55.   my_lcd.Set_Draw_color(0, 255, 255);
  56.   for (i = 1; i < my_lcd.Get_Display_Width() - 2; i++) {
  57.     my_lcd.Draw_Pixel(i, my_lcd.Get_Display_Height() / 2 - 1 + (sin(((i * 1.13) * 3.14) / 180) * 95));
  58.   }
  59.   // 画cos线(Draw cos lines)
  60.   show_string("cos", 5, 25, 1, 0x07E0, 0, 0);
  61.   my_lcd.Set_Draw_color(0, 255, 0);
  62.   for (i = 1; i < my_lcd.Get_Display_Width() - 2; i++) {
  63.     my_lcd.Draw_Pixel(i, my_lcd.Get_Display_Height() / 2 - 1 + (cos(((i * 1.13) * 3.14) / 180) * 95));
  64.   }
  65.   // 绘制棕褐色线(Draw tan lines)
  66.   show_string("tan", 5, 33, 1, 0xFFE0, 0, 0);
  67.   my_lcd.Set_Draw_color(255, 255, 0);
  68.   for (i = 1; i < my_lcd.Get_Display_Width() - 2; i++) {
  69.     my_lcd.Draw_Pixel(i, my_lcd.Get_Display_Height() / 2 - 1 + (tan(((i * 1.13) * 3.14) / 180) * 10));
  70.   }
  71.   // 绘制婴儿床线(Draw cot lines)
  72.   show_string("cot", 5, 41, 1, 0xF800, 0, 0);
  73.   my_lcd.Set_Draw_color(255, 0, 0);
  74.   for (i = 1; i < my_lcd.Get_Display_Width() - 2; i++) {
  75.     my_lcd.Draw_Pixel(i, my_lcd.Get_Display_Height() / 2 - 1 + 1 / (tan(((i * 1.13) * 3.14) / 180) * 0.1));
  76.   }
  77.   return micros() - time_start;
  78. }
  79. // 绘制移动的正弦波(Draw a moving sinewave)
  80. unsigned long show_sinewave(void) {
  81.   uint16_t buf[my_lcd.Get_Display_Width() - 2], x = 1, i, y;
  82.   unsigned long time_start = micros();
  83.   int16_t wid = my_lcd.Get_Display_Width();
  84.   int16_t t;
  85.   float k;
  86.   if (wid == 320) {
  87.     t = 20;
  88.     k = 1.1;
  89.   }
  90.   else {
  91.     t = 15;
  92.     k = 0.7;
  93.   }
  94.   my_lcd.Set_Draw_color(0, 0, 255);
  95.   my_lcd.Draw_Fast_VLine(my_lcd.Get_Display_Width() / 2 - 1, 16, my_lcd.Get_Display_Height() - 32);
  96.   my_lcd.Draw_Fast_HLine(1, my_lcd.Get_Display_Height() / 2 - 1, my_lcd.Get_Display_Width() - 2);
  97.   for (i = 1; i < ((my_lcd.Get_Display_Width() - 2)*t); i++) {
  98.     x++;
  99.     if (x == my_lcd.Get_Display_Width() - 1) {
  100.       x = 1;
  101.     }
  102.     if (i > my_lcd.Get_Display_Width() - 1) {
  103.       if ((x == my_lcd.Get_Display_Width() / 2 - 1) || (buf[x - 1] == my_lcd.Get_Display_Height() / 2 - 1)) {
  104.         my_lcd.Set_Draw_color(0, 0, 255);
  105.       }
  106.       else {
  107.         my_lcd.Set_Draw_color(0, 0, 0);
  108.       }
  109.       my_lcd.Draw_Pixel(x, buf[x - 1]);
  110.     }
  111.     my_lcd.Set_Draw_color(255, 64, 255);
  112.     y = my_lcd.Get_Display_Height() / 2 - 1 + (sin(((i * k) * 3.14) / 180) * (90 - (i / 100)));
  113.     my_lcd.Draw_Pixel(x, y);
  114.     buf[x - 1] = y;
  115.   }
  116.   return micros() - time_start;
  117. }
  118. // 绘制一些实心矩形(Draw some filled rectangles)
  119. unsigned long show_fill_rectangle(void) {
  120.   uint16_t i;
  121.   unsigned long time_start = micros();
  122.   uint16_t side_len = (my_lcd.Get_Display_Height() - 40) / 5;
  123.   uint16_t x_spec = (my_lcd.Get_Display_Width() - 5 * side_len) / 2;
  124.   uint16_t y_spec = (my_lcd.Get_Display_Height() - 5 * side_len) / 2;
  125.   for (i = 0; i < 5; i++)
  126.   {
  127.     switch (i)
  128.     {
  129.       case 0:
  130.         my_lcd.Set_Draw_color(255, 0, 255);
  131.         break;
  132.       case 1:
  133.         my_lcd.Set_Draw_color(255, 0, 0);
  134.         break;
  135.       case 2:
  136.         my_lcd.Set_Draw_color(0, 255, 0);
  137.         break;
  138.       case 3:
  139.         my_lcd.Set_Draw_color(0, 0, 255);
  140.         break;
  141.       case 4:
  142.         my_lcd.Set_Draw_color(255, 255, 0);
  143.         break;
  144.       default:
  145.         break;
  146.     }
  147.     my_lcd.Fill_Rectangle(x_spec + i * side_len - 1, y_spec + i * side_len - 1, x_spec + (i + 1)*side_len - 1, y_spec + (i + 1)*side_len - 1);
  148.     my_lcd.Fill_Rectangle(x_spec + i * side_len - 1, y_spec + (5 - i)*side_len - 1, x_spec + (i + 1)*side_len - 1, y_spec + (4 - i)*side_len - 1);
  149.   }
  150.   return micros() - time_start;
  151. }
  152. // 绘制一些填充的圆角矩形(Draw some filled round rectangles)
  153. unsigned long show_fill_round_rectangle(void) {
  154.   uint16_t i;
  155.   unsigned long time_start = micros();
  156.   uint16_t side_len = (my_lcd.Get_Display_Height() - 40) / 5;
  157.   uint16_t x_spec = (my_lcd.Get_Display_Width() - 5 * side_len) / 2;
  158.   uint16_t y_spec = (my_lcd.Get_Display_Height() - 5 * side_len) / 2;
  159.   for (i = 0; i < 5; i++) {
  160.     switch (i) {
  161.       case 0:
  162.         my_lcd.Set_Draw_color(255, 0, 255);
  163.         break;
  164.       case 1:
  165.         my_lcd.Set_Draw_color(255, 0, 0);
  166.         break;
  167.       case 2:
  168.         my_lcd.Set_Draw_color(0, 255, 0);
  169.         break;
  170.       case 3:
  171.         my_lcd.Set_Draw_color(0, 0, 255);
  172.         break;
  173.       case 4:
  174.         my_lcd.Set_Draw_color(255, 255, 0);
  175.         break;
  176.       default:
  177.         break;
  178.     }
  179.     my_lcd.Fill_Round_Rectangle(x_spec + i * side_len - 1, y_spec + i * side_len - 1, x_spec + (i + 1)*side_len - 1, y_spec + (i + 1)*side_len - 1, 10);
  180.     my_lcd.Fill_Round_Rectangle(x_spec + i * side_len - 1, y_spec + (5 - i)*side_len - 1, x_spec + (i + 1)*side_len - 1, y_spec + (4 - i)*side_len - 1, 10);
  181.   }
  182.   return micros() - time_start;
  183. }
  184. // 画一些实心圆圈(Draw some filled circles)
  185. unsigned long show_fill_circle(void) {
  186.   uint16_t i;
  187.   unsigned long time_start = micros();
  188.   uint16_t r_len = (my_lcd.Get_Display_Height() - 40) / 5 / 2;
  189.   uint16_t x_spec = (my_lcd.Get_Display_Width() - 5 * r_len * 2) / 2;
  190.   uint16_t y_spec = (my_lcd.Get_Display_Height() - 5 * r_len * 2) / 2;
  191.   for (i = 0; i < 5; i++) {
  192.     switch (i) {
  193.       case 0:
  194.         my_lcd.Set_Draw_color(255, 0, 255);
  195.         break;
  196.       case 1:
  197.         my_lcd.Set_Draw_color(255, 0, 0);
  198.         break;
  199.       case 2:
  200.         my_lcd.Set_Draw_color(0, 255, 0);
  201.         break;
  202.       case 3:
  203.         my_lcd.Set_Draw_color(0, 0, 255);
  204.         break;
  205.       case 4:
  206.         my_lcd.Set_Draw_color(255, 255, 0);
  207.         break;
  208.       default:
  209.         break;
  210.     }
  211.     my_lcd.Fill_Circle(x_spec + r_len + i * r_len * 2 - 1, y_spec + r_len + i * r_len * 2 - 1, r_len);
  212.     my_lcd.Fill_Circle(x_spec + r_len + i * r_len * 2 - 1, y_spec + (5 - i)*r_len * 2 - r_len - 1, r_len);
  213.   }
  214.   return micros() - time_start;
  215. }
  216. // 画一些实心三角形(Draw some filled triangles)
  217. unsigned long show_fill_triangle(void) {
  218.   uint16_t i;
  219.   unsigned long time_start = micros();
  220.   uint16_t h_len = (my_lcd.Get_Display_Height() - 40) / 5;
  221.   uint16_t side_len = (h_len * 115) / 100;
  222.   uint16_t x_spec = (my_lcd.Get_Display_Width() - 5 * side_len) / 2;
  223.   uint16_t y_spec = (my_lcd.Get_Display_Height() - 5 * h_len) / 2;
  224.   for (i = 0; i < 5; i++) {
  225.     switch (i) {
  226.       case 0:
  227.         my_lcd.Set_Draw_color(255, 0, 255);
  228.         break;
  229.       case 1:
  230.         my_lcd.Set_Draw_color(255, 0, 0);
  231.         break;
  232.       case 2:
  233.         my_lcd.Set_Draw_color(0, 255, 0);
  234.         break;
  235.       case 3:
  236.         my_lcd.Set_Draw_color(0, 0, 255);
  237.         break;
  238.       case 4:
  239.         my_lcd.Set_Draw_color(255, 255, 0);
  240.         break;
  241.       default:
  242.         break;
  243.     }
  244.     my_lcd.Fill_Triangle(x_spec + i * side_len - 1, y_spec + (i + 1)*h_len - 1, x_spec + side_len / 2 + i * side_len - 1, y_spec + i * h_len - 1, x_spec + (i + 1)*side_len - 1, y_spec + (i + 1)*h_len - 1);
  245.     my_lcd.Fill_Triangle(x_spec + i * side_len - 1, y_spec + (5 - i)*h_len - 1, x_spec + side_len / 2 + i * side_len - 1, y_spec + (4 - i)*h_len - 1, x_spec + (i + 1)*side_len - 1, y_spec + (5 - i)*h_len - 1);
  246.   }
  247.   return micros() - time_start;
  248. }
  249. // 在图案中绘制一些线条(Draw some lines in a pattern)
  250. unsigned long show_grid_lines(void) {
  251.   uint16_t i;
  252.   unsigned long time_start = micros();
  253.   int16_t wid = my_lcd.Get_Display_Width();
  254.   float k;
  255.   if (wid == 320) {
  256.     k = 1.44;
  257.   }
  258.   else {
  259.     k = 1.6;
  260.   }
  261.   my_lcd.Set_Draw_color(255, 0, 0);
  262.   for (i = 16; i < my_lcd.Get_Display_Height() - 17; i += 5) {
  263.     my_lcd.Draw_Line(1, i, (i * k) - 10, my_lcd.Get_Display_Height() - 17);
  264.   }
  265.   my_lcd.Set_Draw_color(255, 0, 0);
  266.   for (i = my_lcd.Get_Display_Height() - 17; i > 16; i -= 5) {
  267.     my_lcd.Draw_Line(my_lcd.Get_Display_Width() - 2, i, (i * k) - 11, 16);
  268.   }
  269.   my_lcd.Set_Draw_color(0, 255, 255);
  270.   for (i = my_lcd.Get_Display_Height() - 16; i > 16; i -= 5) {
  271.     my_lcd.Draw_Line(1, i, (my_lcd.Get_Display_Height() - 17)*k + 10 - (i * k), 16);
  272.   }
  273.   my_lcd.Set_Draw_color(0, 255, 255);
  274.   for (int i = 15; i < my_lcd.Get_Display_Height() - 17; i += 5) {
  275.     my_lcd.Draw_Line(my_lcd.Get_Display_Width() - 2, i, (my_lcd.Get_Display_Height() - 17)*k + 10 - (i * k), my_lcd.Get_Display_Height() - 17);
  276.   }
  277.   return micros() - time_start;
  278. }
  279. // 绘制一些随机像素(Draw some random pixels)
  280. unsigned long show_random_pixels(void) {
  281.   uint16_t i;
  282.   unsigned long time_start = micros();
  283.   for (i = 0; i < 6000; i++) {
  284.     my_lcd.Set_Draw_color(random(255), random(255), random(255));
  285.     my_lcd.Draw_Pixel(2 + random(my_lcd.Get_Display_Width() - 4), 17 + random(my_lcd.Get_Display_Height() - 34));
  286.   }
  287.   return micros() - time_start;
  288. }
  289. // 画一些随机线(Draw some random lines)
  290. unsigned long show_random_lines(void) {
  291.   uint16_t i;
  292.   unsigned long time_start = micros();
  293.   for (i = 0; i < 300; i++) {
  294.     my_lcd.Set_Draw_color(random(255), random(255), random(255));
  295.     my_lcd.Draw_Line(2 + random(my_lcd.Get_Display_Width() - 4), 17 + random(my_lcd.Get_Display_Height() - 34), 2 + random(my_lcd.Get_Display_Width() - 4), 17 + random(my_lcd.Get_Display_Height() - 34));
  296.   }
  297.   return micros() - time_start;
  298. }
  299. // 绘制一些随机矩形(Draw some random rectangles)
  300. unsigned long show_random_rectangles(void) {
  301.   uint16_t i;
  302.   unsigned long time_start = micros();
  303.   for (i = 0; i < 150; i++) {
  304.     my_lcd.Set_Draw_color(random(255), random(255), random(255));
  305.     my_lcd.Draw_Rectangle(2 + random(my_lcd.Get_Display_Width() - 4), 17 + random(my_lcd.Get_Display_Height() - 34), 2 + random(my_lcd.Get_Display_Width() - 4), 17 + random(my_lcd.Get_Display_Height() - 34));
  306.   }
  307.   return micros() - time_start;
  308. }
  309. // 画一些随机的圆圈(Draw some random circles)
  310. unsigned long show_random_circles(void) {
  311.   uint16_t i;
  312.   unsigned long time_start = micros();
  313.   for (i = 0; i < 150; i++) {
  314.     my_lcd.Set_Draw_color(random(255), random(255), random(255));
  315.     my_lcd.Draw_Circle(41 + random(my_lcd.Get_Display_Width() - 82), 56 + random(my_lcd.Get_Display_Height() - 112), random(40));
  316.   }
  317.   return micros() - time_start;
  318. }
  319. // 画一些随机三角形(Draw some random triangles)
  320. unsigned long show_random_triangles(void) {
  321.   uint16_t i;
  322.   unsigned long time_start = micros();
  323.   for (i = 0; i < 150; i++) {
  324.     my_lcd.Set_Draw_color(random(255), random(255), random(255));
  325.     my_lcd.Draw_Triangle(2 + random(my_lcd.Get_Display_Width() - 4), 17 + random(my_lcd.Get_Display_Height() - 34), 2 + random(my_lcd.Get_Display_Width() - 4), 17 + random(my_lcd.Get_Display_Height() - 34), 2 + random(my_lcd.Get_Display_Width() - 4), 17 + random(my_lcd.Get_Display_Height() - 34));
  326.   }
  327.   return micros() - time_start;
  328. }
  329. // 画一些随机的圆角矩形(Draw some random round rectangles)
  330. unsigned long show_random_round_rectangles(void) {
  331.   uint16_t i;
  332.   unsigned long time_start = micros();
  333.   for (i = 0; i < 150; i++) {
  334.     my_lcd.Set_Draw_color(random(255), random(255), random(255));
  335.     my_lcd.Draw_Round_Rectangle(2 + random(my_lcd.Get_Display_Width() - 4), 17 + random(my_lcd.Get_Display_Height() - 34), 2 + random(my_lcd.Get_Display_Width() - 4), 17 + random(my_lcd.Get_Display_Height() - 34), 5);
  336.   }
  337.   return micros() - time_start;
  338. }
  339. // 绘制一些随机位图(Draw some random bit maps)
  340. unsigned long show_random_bit_map(void) {
  341.   uint16_t buf[48], i;
  342.   unsigned long time_start = micros();
  343.   int16_t len = (my_lcd.Get_Display_Height() * 3 / 4) / 6;
  344.   for (i = 0; i < 48; i++) {
  345.     my_lcd.Set_Draw_color(random(255), random(255), random(255));
  346.     buf[i] = my_lcd.Get_Draw_color();
  347.   }
  348.   for (i = 1; i <= 6; i++) {
  349.     my_lcd.Draw_Bit_Map(my_lcd.Get_Display_Width() / 2 - 1 - ((len / 2) * 4 / 3)*i, my_lcd.Get_Display_Height() / 2 - 1 - (len / 2)*i, 8, 6, buf, i * (len / 6));
  350.     delay(100);
  351.   }
  352.   return micros() - time_start;
  353. }
  354. //清屏运行统计(Clear the screen)
  355. void clear_screen(void) {
  356.   delay(2000);
  357.   my_lcd.Set_Draw_color(0, 0, 0);
  358.   my_lcd.Fill_Rectangle(1, 16, my_lcd.Get_Display_Width() - 2, my_lcd.Get_Display_Height() - 17);
  359. }
  360. unsigned long (*show_function[])(void) {
  361.   show_text,
  362.   show_triangle_function,
  363.   show_sinewave,
  364.   show_fill_rectangle,
  365.   show_fill_round_rectangle,
  366.   show_fill_circle,
  367.   show_fill_triangle,
  368.   show_grid_lines,
  369.   show_random_pixels,
  370.   show_random_lines,
  371.   show_random_rectangles,
  372.   show_random_round_rectangles,
  373.   show_random_circles,
  374.   show_random_triangles,
  375.   show_random_bit_map,
  376. };
  377. uint8_t *show_str[] =
  378. {
  379.   "show text                    :",
  380.   "show triangle function       :",
  381.   "show sinewave                :",
  382.   "show fill rectangle          :",
  383.   "show fill round rectangle    :",
  384.   "show fill circle             :",
  385.   "show fill triangle           :",
  386.   "show grid lines              :",
  387.   "show random pixels           :",
  388.   "show random lines            :",
  389.   "show random rectangles       :",
  390.   "show random round rectangles :",
  391.   "show random circles          :",
  392.   "show random triangles        :",
  393.   "show random bit_map          :"
  394. };
  395. //显示程序运行时间(display the running time of programs)
  396. unsigned long show_total_time(void) {
  397.   uint16_t i;
  398.   unsigned long buf[15];
  399.   unsigned long time_start = micros();
  400.   for (i = 0; i < 15; i++) {
  401.     buf[i] = show_function[i]();
  402.     clear_screen();
  403.   }
  404.   for (i = 0; i < 15; i++) {
  405.     show_string(show_str[i], (my_lcd.Get_Display_Width() - 260) / 2 - 1, (my_lcd.Get_Display_Height() - 150) / 2 + i * 10 - 1, 1, 0xFD20, 0, 1);
  406.     my_lcd.Set_Text_colour(0, 255, 0);
  407.     my_lcd.Print_Number_Int(buf[i], (my_lcd.Get_Display_Width() - 260) / 2 - 1 + 200, (my_lcd.Get_Display_Height() - 150) / 2 + i * 10 - 1, 0, ' ', 10);
  408.   }
  409.   delay(2000);
  410.   return micros() - time_start;
  411. }
  412. //显示结束和总运行时间(display ending and total running time)
  413. void show_end(unsigned long run_time) {
  414.   my_lcd.Fill_Screen(0, 255, 255);
  415.   my_lcd.Set_Draw_color(255, 0, 0);
  416.   my_lcd.Fill_Round_Rectangle(my_lcd.Get_Display_Width() / 2 - 1 - 120 + 1, my_lcd.Get_Display_Height() / 2 - 1 - 60 + 1, my_lcd.Get_Display_Width() / 2 - 1 + 120 - 1, my_lcd.Get_Display_Height() / 2 - 1 + 60 - 1, 5);
  417.   my_lcd.Set_Text_colour(0, 255, 255);
  418.   my_lcd.Set_Text_Size(1);
  419.   my_lcd.Set_Text_Mode(1);
  420.   my_lcd.Print_String("Running over!", CENTER, my_lcd.Get_Display_Height() / 2 - 1 - 40);
  421.   my_lcd.Print_String("That's ok!", CENTER, my_lcd.Get_Display_Height() / 2 - 1 - 30);
  422.   my_lcd.Print_String("After a few seconds,", CENTER, my_lcd.Get_Display_Height() / 2 - 1 - 20);
  423.   my_lcd.Print_String("it will restart.", CENTER, my_lcd.Get_Display_Height() / 2 - 1 - 10);
  424.   my_lcd.Print_String("Please wait ...", CENTER, my_lcd.Get_Display_Height() / 2 - 1);
  425.   my_lcd.Set_Text_colour(255, 255, 0);
  426.   my_lcd.Print_String("Total runtime(us):  ", my_lcd.Get_Display_Width() / 2 - 1 - 90, my_lcd.Get_Display_Height() / 2 - 1 + 40);
  427.   my_lcd.Set_Text_colour(0, 255, 0);
  428.   my_lcd.Print_Number_Int(run_time, my_lcd.Get_Display_Width() / 2 - 1 + 30, my_lcd.Get_Display_Height() / 2 - 1 + 40, 0, ' ', 10);
  429.   delay(2000);
  430. }
  431. void setup() {
  432.   Serial.begin(9600);
  433.   my_lcd.Init_LCD();
  434.   Serial.println(my_lcd.Read_ID(), HEX);
  435.   my_lcd.Fill_Screen(0x0);
  436.   my_lcd.Set_Rotation(1);
  437. }
  438. void loop() {
  439.   unsigned long total_time;
  440.   my_lcd.Fill_Screen(0x0);
  441.   total_time = show_total_time();
  442.   show_end(total_time);
  443. }
复制代码


回复

使用道具 举报

驴友花雕  中级技神
 楼主|

发表于 2021-6-27 08:32:52

项目之三:使用图形库随机绘制各种图形,三角函数以及英文字符串

实验情况动图1 【Arduino】168种传感器模块系列实验(165)---2.4寸TFT液晶触...图1

回复

使用道具 举报

驴友花雕  中级技神
 楼主|

发表于 2021-6-27 08:39:57

本帖最后由 驴友花雕 于 2021-6-27 08:41 编辑

项目之三:使用图形库随机绘制各种图形,三角函数以及英文字符串

实验情况动图2  【Arduino】168种传感器模块系列实验(165)---2.4寸TFT液晶触...图1

回复

使用道具 举报

驴友花雕  中级技神
 楼主|

发表于 2021-6-27 08:54:48

项目之三:使用图形库随机绘制各种图形,三角函数以及英文字符串

实验情况动图3  【Arduino】168种传感器模块系列实验(165)---2.4寸TFT液晶触...图1

回复

使用道具 举报

驴友花雕  中级技神
 楼主|

发表于 2021-6-27 09:03:36



项目之三:使用图形库随机绘制各种图形,三角函数以及英文字符串

实验情况动图4  【Arduino】168种传感器模块系列实验(165)---2.4寸TFT液晶触...图1

回复

使用道具 举报

驴友花雕  中级技神
 楼主|

发表于 2021-6-27 09:10:39

项目之三:使用图形库随机绘制各种图形,三角函数以及英文字符串

实验情况动图5  【Arduino】168种传感器模块系列实验(165)---2.4寸TFT液晶触...图1

回复

使用道具 举报

驴友花雕  中级技神
 楼主|

发表于 2021-6-27 09:16:44

项目之三:使用图形库随机绘制各种图形,三角函数以及英文字符串

实验情况动图6  【Arduino】168种传感器模块系列实验(165)---2.4寸TFT液晶触...图1

回复

使用道具 举报

驴友花雕  中级技神
 楼主|

发表于 2021-6-27 09:23:14

项目之三:使用图形库随机绘制各种图形,三角函数以及英文字符串

实验情况动图7  【Arduino】168种传感器模块系列实验(165)---2.4寸TFT液晶触...图1

回复

使用道具 举报

驴友花雕  中级技神
 楼主|

发表于 2021-6-27 09:44:19

项目之三:使用图形库随机绘制各种图形,三角函数以及英文字符串

实验情况动图8  【Arduino】168种传感器模块系列实验(165)---2.4寸TFT液晶触...图1

回复

使用道具 举报

驴友花雕  中级技神
 楼主|

发表于 2021-6-27 09:48:50

项目之三:使用图形库随机绘制各种图形,三角函数以及英文字符串

实验情况动图9  【Arduino】168种传感器模块系列实验(165)---2.4寸TFT液晶触...图1

回复

使用道具 举报

驴友花雕  中级技神
 楼主|

发表于 2021-6-27 09:54:10

项目之三:使用图形库随机绘制各种图形,三角函数以及英文字符串

实验情况动图10  【Arduino】168种传感器模块系列实验(165)---2.4寸TFT液晶触...图1

回复

使用道具 举报

驴友花雕  中级技神
 楼主|

发表于 2021-6-27 10:01:09

【Arduino】168种传感器模块系列实验(资料代码+仿真编程+图形编程)
  实验一百六十五:2.4寸TFT液晶触摸屏 彩屏模块 TFT-LCD 高清真彩显示屏
  项目之三:使用图形库随机绘制各种图形,三角函数以及英文字符串(视频60秒)


https://v.youku.com/v_show/id_XNTE3NDU2NzEwMA==.html?spm=a2hcb.playlsit.page.1



回复

使用道具 举报

帅猫  高级技师

发表于 2021-6-27 11:04:22

顶一个!
回复

使用道具 举报

驴友花雕  中级技神
 楼主|

发表于 2021-6-27 18:08:28


谢谢老师的鼓励
回复

使用道具 举报

驴友花雕  中级技神
 楼主|

发表于 2021-6-28 08:17:58

【Arduino】168种传感器模块系列实验(资料代码+仿真编程+图形编程)
  实验一百六十五:2.4寸TFT液晶触摸屏 彩屏模块 TFT-LCD 高清真彩显示屏
  项目之四:KBV图形与字符串显示的综合测试
  实验开源代码:

  1. /*
  2.   【Arduino】168种传感器模块系列实验(资料代码+仿真编程+图形编程)
  3.   实验一百六十五:2.4寸TFT液晶触摸屏 彩屏模块 TFT-LCD 高清真彩显示屏
  4.   项目之四:KBV图形与字符串显示的综合测试
  5.   模块直插,引脚用法如下:
  6.   LCD_CS LCD_CD LCD_WR LCD_RD LCD_RST SD_SS SD_DI SD_DO SD_SCK
  7.   Arduino Uno A3 A2 A1 A0 A4 10 11 12 13
  8.   LCD_D0 LCD_D1 LCD_D2 LCD_D3 LCD_D4 LCD_D5 LCD_D6 LCD_D7
  9.   Arduino Uno 8 9 2 3 4 5 6 7
  10. */
  11. #define LCD_CS A3 // 片选进入模拟A3
  12. #define LCD_CD A2 // 命令/数据进入模拟A2
  13. #define LCD_WR A1 // LCD 写入到模拟A1
  14. #define LCD_RD A0 // LCD 读取进入模拟A0
  15. #define LCD_RESET A4 //也可以只连接到 Arduino 的复位引脚
  16. #include <SPI.h>
  17. #include "Adafruit_GFX.h"// 导入特定硬件的库
  18. #include <MCUFRIEND_kbv.h>
  19. MCUFRIEND_kbv tft;
  20. //#include <Adafruit_TFTLCD.h>
  21. //Adafruit_TFTLCD tft(LCD_CS, LCD_CD, LCD_WR, LCD_RD, LCD_RESET);
  22. // 为一些常见的 16 位颜色值分配人类可读的名称
  23. #define        BLACK   0x0000
  24. #define        BLUE    0x001F
  25. #define        RED     0xF800
  26. #define        GREEN   0x07E0
  27. #define CYAN    0x07FF
  28. #define MAGENTA 0xF81F
  29. #define YELLOW  0xFFE0
  30. #define WHITE   0xFFFF
  31. #ifndef min
  32. #define min(a, b) (((a) < (b)) ? (a) : (b))
  33. #endif
  34. void setup(void);
  35. void loop(void);
  36. unsigned long testFillScreen();
  37. unsigned long testText();
  38. unsigned long testLines(uint16_t color);
  39. unsigned long testFastLines(uint16_t color1, uint16_t color2);
  40. unsigned long testRects(uint16_t color);
  41. unsigned long testFilledRects(uint16_t color1, uint16_t color2);
  42. unsigned long testFilledCircles(uint8_t radius, uint16_t color);
  43. unsigned long testCircles(uint8_t radius, uint16_t color);
  44. unsigned long testTriangles();
  45. unsigned long testFilledTriangles();
  46. unsigned long testRoundRects();
  47. unsigned long testFilledRoundRects();
  48. void progmemPrint(const char *str);
  49. void progmemPrintln(const char *str);
  50. void runtests(void);
  51. uint16_t g_identifier;
  52. extern const uint8_t hanzi[];
  53. void showhanzi(unsigned int x, unsigned int y, unsigned char index)
  54. {
  55.   uint8_t i, j, c, first = 1;
  56.   uint8_t *temp = (uint8_t*)hanzi;
  57.   uint16_t color;
  58.   tft.setAddrWindow(x, y, x + 31, y + 31); //设置区域
  59.   temp += index * 128;
  60.   for (j = 0; j < 128; j++)
  61.   {
  62.     c = pgm_read_byte(temp);
  63.     for (i = 0; i < 8; i++)
  64.     {
  65.       if ((c & (1 << i)) != 0)
  66.       {
  67.         color = RED;
  68.       }
  69.       else
  70.       {
  71.         color = BLACK;
  72.       }
  73.       tft.pushColors(&color, 1, first);
  74.       first = 0;
  75.     }
  76.     temp++;
  77.   }
  78. }
  79. void setup(void) {
  80.   Serial.begin(9600);
  81.   uint32_t when = millis();
  82.   //    while (!Serial) ;   // 挂起Leonardo,直到您连接串行
  83.   if (!Serial) delay(5000);           //给Leonardo一些时间
  84.   Serial.println("Serial took " + String((millis() - when)) + "ms to start");
  85.   //    tft.reset();                 //硬件复位
  86.   uint16_t ID = tft.readID();
  87.   Serial.print("ID = 0x");
  88.   Serial.println(ID, HEX);
  89.   Serial.print("Ready ok!");
  90.   if (ID == 0xD3D3) ID = 0x9481; //只写扩展
  91.   //    ID = 0x9329;                             // 强制标识
  92.   tft.begin(ID);
  93. }
  94. #if defined(MCUFRIEND_KBV_H_)
  95. uint16_t scrollbuf[320];    // 我最大的屏幕是 320x480
  96. #define READGRAM(x, y, buf, w, h)  tft.readGRAM(x, y, buf, w, h)
  97. #else
  98. uint16_t scrollbuf[320];    // Adafruit 只能处理 240x320
  99. // Adafruit 可以一次读取一个像素块
  100. int16_t  READGRAM(int16_t x, int16_t y, uint16_t *block, int16_t w, int16_t h)
  101. {
  102.   uint16_t *p;
  103.   for (int row = 0; row < h; row++) {
  104.     p = block + row * w;
  105.     for (int col = 0; col < w; col++) {
  106.       *p++ = tft.readPixel(x + col, y + row);
  107.     }
  108.   }
  109. }
  110. #endif
  111. void windowScroll(int16_t x, int16_t y, int16_t wid, int16_t ht, int16_t dx, int16_t dy, uint16_t *buf)
  112. {
  113.   if (dx) for (int16_t row = 0; row < ht; row++) {
  114.       READGRAM(x, y + row, buf, wid, 1);
  115.       tft.setAddrWindow(x, y + row, x + wid - 1, y + row);
  116.       tft.pushColors(buf + dx, wid - dx, 1);
  117.       tft.pushColors(buf + 0, dx, 0);
  118.     }
  119.   if (dy) for (int16_t col = 0; col < wid; col++) {
  120.       READGRAM(x + col, y, buf, 1, ht);
  121.       tft.setAddrWindow(x + col, y, x + col, y + ht - 1);
  122.       tft.pushColors(buf + dy, ht - dy, 1);
  123.       tft.pushColors(buf + 0, dy, 0);
  124.     }
  125. }
  126. void printmsg(int row, const char *msg)
  127. {
  128.   tft.setTextColor(YELLOW, BLACK);
  129.   tft.setCursor(0, row);
  130.   tft.println(msg);
  131. }
  132. void loop(void) {
  133.   uint8_t aspect;
  134.   uint16_t pixel;
  135.   const char *aspectname[] = {
  136.     "PORTRAIT", "LANDSCAPE", "PORTRAIT_REV", "LANDSCAPE_REV"
  137.   };
  138.   const char *colorname[] = { "BLUE", "GREEN", "RED", "GRAY" };
  139.   uint16_t colormask[] = { 0x001F, 0x07E0, 0xF800, 0xFFFF };
  140.   uint16_t dx, rgb, n, wid, ht, msglin;
  141.   tft.setRotation(0);
  142.   runtests();
  143.   delay(2000);
  144.   if (tft.height() > 64) {
  145.     for (uint8_t cnt = 0; cnt < 4; cnt++) {
  146.       aspect = (cnt + 0) & 3;
  147.       tft.setRotation(aspect);
  148.       wid = tft.width();
  149.       ht = tft.height();
  150.       msglin = (ht > 160) ? 200 : 112;
  151.       testText();
  152.       dx = wid / 32;
  153.       for (n = 0; n < 32; n++) {
  154.         rgb = n * 8;
  155.         rgb = tft.color565(rgb, rgb, rgb);
  156.         tft.fillRect(n * dx, 48, dx, 63, rgb & colormask[aspect]);
  157.       }
  158.       tft.drawRect(0, 48 + 63, wid, 1, WHITE);
  159.       tft.setTextSize(2);
  160.       tft.setTextColor(colormask[aspect], BLACK);
  161.       tft.setCursor(0, 72);
  162.       tft.print(colorname[aspect]);
  163.       tft.setTextColor(WHITE);
  164.       tft.println(" COLOR GRADES");
  165.       tft.setTextColor(WHITE, BLACK);
  166.       printmsg(184, aspectname[aspect]);
  167.       delay(1000);
  168.       tft.drawPixel(0, 0, YELLOW);
  169.       pixel = tft.readPixel(0, 0);
  170.       tft.setTextSize((ht > 160) ? 2 : 1); //对于消息
  171. #if defined(MCUFRIEND_KBV_H_)
  172. #if 1
  173.       extern const uint8_t penguin[];
  174.       tft.setAddrWindow(wid - 40 - 40, 20 + 0, wid - 1 - 40, 20 + 39);
  175.       tft.pushColors(penguin, 1600, 1);
  176. #elif 1
  177.       extern const uint8_t wifi_full[];
  178.       tft.setAddrWindow(wid - 40 - 40, 20 + 0, wid - 40 - 40 + 31, 20 + 31);
  179.       tft.pushColors(wifi_full, 1024, 1, true);
  180. #elif 1
  181.       extern const uint8_t icon_40x40[];
  182.       tft.setAddrWindow(wid - 40 - 40, 20 + 0, wid - 1 - 40, 20 + 39);
  183.       tft.pushColors(icon_40x40, 1600, 1);
  184. #endif
  185.       tft.setAddrWindow(0, 0, wid - 1, ht - 1);
  186.       if (aspect & 1) tft.drawRect(wid - 1, 0, 1, ht, WHITE);
  187.       else tft.drawRect(0, ht - 1, wid, 1, WHITE);
  188.       printmsg(msglin, "VERTICAL SCROLL UP");
  189.       uint16_t maxscroll;
  190.       if (tft.getRotation() & 1) maxscroll = wid;
  191.       else maxscroll = ht;
  192.       for (uint16_t i = 1; i <= maxscroll; i++) {
  193.         tft.vertScroll(0, maxscroll, i);
  194.         delay(10);
  195.       }
  196.       delay(1000);
  197.       printmsg(msglin, "VERTICAL SCROLL DN");
  198.       for (uint16_t i = 1; i <= maxscroll; i++) {
  199.         tft.vertScroll(0, maxscroll, 0 - (int16_t)i);
  200.         delay(10);
  201.       }
  202.       tft.vertScroll(0, maxscroll, 0);
  203.       printmsg(msglin, "SCROLL DISABLED   ");
  204.       delay(1000);
  205.       if ((aspect & 1) == 0) { //Portrait
  206.         tft.setTextColor(BLUE, BLACK);
  207.         printmsg(msglin, "ONLY THE COLOR BAND");
  208.         for (uint16_t i = 1; i <= 64; i++) {
  209.           tft.vertScroll(48, 64, i);
  210.           delay(20);
  211.         }
  212.         delay(1000);
  213.       }
  214. #endif
  215.       tft.setTextColor(YELLOW, BLACK);
  216.       if (pixel == YELLOW) {
  217.         printmsg(msglin, "SOFTWARE SCROLL    ");
  218. #if 0
  219.         // 块的对角线卷轴
  220.         for (int16_t i = 45, dx = 2, dy = 1; i > 0; i -= dx) {
  221.           windowScroll(24, 8, 90, 40, dx, dy, scrollbuf);
  222.         }
  223. #else
  224.         // 块的普通水平滚动
  225.         n = (wid > 320) ? 320 : wid;
  226.         for (int16_t i = n, dx = 4, dy = 0; i > 0; i -= dx) {
  227.           windowScroll(0, 200, n, 16, dx, dy, scrollbuf);
  228.         }
  229. #endif
  230.       }
  231.       else if (pixel == CYAN)
  232.         tft.println("readPixel() reads as BGR");
  233.       else if ((pixel & 0xF8F8) == 0xF8F8)
  234.         tft.println("readPixel() should be 24-bit");
  235.       else {
  236.         tft.print("readPixel() reads 0x");
  237.         tft.println(pixel, HEX);
  238.       }
  239.       delay(2000);
  240.     }
  241.   }
  242.   printmsg(msglin, "INVERT DISPLAY ");
  243.   tft.invertDisplay(true);
  244.   delay(1000);
  245.   tft.invertDisplay(false);
  246. }
  247. typedef struct {
  248.   PGM_P msg;
  249.   uint32_t ms;
  250. } TEST;
  251. TEST result[12];
  252. #define RUNTEST(n, str, test) { result[n].msg = PSTR(str); result[n].ms = test; delay(500); }
  253. void runtests(void)
  254. {
  255.   uint8_t i, len = 24, cnt;
  256.   uint32_t total;
  257.   RUNTEST(0, "FillScreen               ", testFillScreen());
  258.   RUNTEST(1, "Text                     ", testText());
  259.   RUNTEST(2, "Lines                    ", testLines(CYAN));
  260.   RUNTEST(3, "Horiz/Vert Lines         ", testFastLines(RED, BLUE));
  261.   RUNTEST(4, "Rectangles (outline)     ", testRects(GREEN));
  262.   RUNTEST(5, "Rectangles (filled)      ", testFilledRects(YELLOW, MAGENTA));
  263.   RUNTEST(6, "Circles (filled)         ", testFilledCircles(10, MAGENTA));
  264.   RUNTEST(7, "Circles (outline)        ", testCircles(10, WHITE));
  265.   RUNTEST(8, "Triangles (outline)      ", testTriangles());
  266.   RUNTEST(9, "Triangles (filled)       ", testFilledTriangles());
  267.   RUNTEST(10, "Rounded rects (outline)  ", testRoundRects());
  268.   RUNTEST(11, "Rounded rects (filled)   ", testFilledRoundRects());
  269.   tft.fillScreen(BLACK);
  270.   tft.setTextColor(GREEN);
  271.   tft.setCursor(0, 0);
  272.   uint16_t wid = tft.width();
  273.   if (wid > 176) {
  274.     tft.setTextSize(2);
  275. #if defined(MCUFRIEND_KBV_H_)
  276.     tft.print("MCUFRIEND ");
  277. #if MCUFRIEND_KBV_H_ != 0
  278.     tft.print(0.01 * MCUFRIEND_KBV_H_, 2);
  279. #else
  280.     tft.print("for");
  281. #endif
  282.     tft.println(" UNO");
  283. #else
  284.     tft.println("Adafruit-Style Tests");
  285. #endif
  286.   } else len = wid / 6 - 8;
  287.   tft.setTextSize(1);
  288.   total = 0;
  289.   for (i = 0; i < 12; i++) {
  290.     PGM_P str = result[i].msg;
  291.     char c;
  292.     if (len > 24) {
  293.       if (i < 10) tft.print(" ");
  294.       tft.print(i);
  295.       tft.print(": ");
  296.     }
  297.     uint8_t cnt = len;
  298.     while ((c = pgm_read_byte(str++)) && cnt--) tft.print(c);
  299.     tft.print(" ");
  300.     tft.println(result[i].ms);
  301.     total += result[i].ms;
  302.   }
  303.   tft.setTextSize(2);
  304.   tft.print("Total:");
  305.   tft.print(0.000001 * total);
  306.   tft.println("sec");
  307.   g_identifier = tft.readID();
  308.   tft.print("ID: 0x");
  309.   tft.println(tft.readID(), HEX);
  310.   //    tft.print("Reg(00):0x");
  311.   //    tft.println(tft.readReg(0x00), HEX);
  312.   tft.print("F_CPU:");
  313.   tft.print(0.000001 * F_CPU);
  314. #if defined(__OPTIMIZE_SIZE__)
  315.   tft.println("MHz -Os");
  316. #else
  317.   tft.println("MHz");
  318. #endif
  319.   delay(1000);
  320. }
  321. //标准 Adafruit 测试。 将调整到屏幕大小
  322. unsigned long testFillScreen() {
  323.   unsigned long start = micros();
  324.   tft.fillScreen(BLACK);
  325.   tft.fillScreen(RED);
  326.   tft.fillScreen(GREEN);
  327.   tft.fillScreen(BLUE);
  328.   tft.fillScreen(BLACK);
  329.   return micros() - start;
  330. }
  331. unsigned long testText() {
  332.   unsigned long start;
  333.   tft.fillScreen(BLACK);
  334.   start = micros();
  335.   tft.setCursor(0, 0);
  336.   tft.setTextColor(WHITE);  tft.setTextSize(1);
  337.   tft.println("Hello World!");
  338.   tft.setTextColor(YELLOW); tft.setTextSize(2);
  339.   tft.println(123.45);
  340.   tft.setTextColor(RED);    tft.setTextSize(3);
  341.   tft.println(0xDEADBEEF, HEX);
  342.   tft.println();
  343.   tft.setTextColor(GREEN);
  344.   tft.setTextSize(5);
  345.   tft.println("Groop");
  346.   tft.setTextSize(2);
  347.   tft.println("I implore thee,");
  348.   tft.setTextSize(1);
  349.   tft.println("my foonting turlingdromes.");
  350.   tft.println("And hooptiously drangle me");
  351.   tft.println("with crinkly bindlewurdles,");
  352.   tft.println("Or I will rend thee");
  353.   tft.println("in the gobberwarts");
  354.   tft.println("with my blurglecruncheon,");
  355.   tft.println("see if I don't!");
  356.   return micros() - start;
  357. }
  358. unsigned long testLines(uint16_t color) {
  359.   unsigned long start, t;
  360.   int           x1, y1, x2, y2,
  361.                 w = tft.width(),
  362.                 h = tft.height();
  363.   tft.fillScreen(BLACK);
  364.   x1 = y1 = 0;
  365.   y2    = h - 1;
  366.   start = micros();
  367.   for (x2 = 0; x2 < w; x2 += 6) tft.drawLine(x1, y1, x2, y2, color);
  368.   x2    = w - 1;
  369.   for (y2 = 0; y2 < h; y2 += 6) tft.drawLine(x1, y1, x2, y2, color);
  370.   t     = micros() - start; // fillScreen doesn't count against timing
  371.   tft.fillScreen(BLACK);
  372.   x1    = w - 1;
  373.   y1    = 0;
  374.   y2    = h - 1;
  375.   start = micros();
  376.   for (x2 = 0; x2 < w; x2 += 6) tft.drawLine(x1, y1, x2, y2, color);
  377.   x2    = 0;
  378.   for (y2 = 0; y2 < h; y2 += 6) tft.drawLine(x1, y1, x2, y2, color);
  379.   t    += micros() - start;
  380.   tft.fillScreen(BLACK);
  381.   x1    = 0;
  382.   y1    = h - 1;
  383.   y2    = 0;
  384.   start = micros();
  385.   for (x2 = 0; x2 < w; x2 += 6) tft.drawLine(x1, y1, x2, y2, color);
  386.   x2    = w - 1;
  387.   for (y2 = 0; y2 < h; y2 += 6) tft.drawLine(x1, y1, x2, y2, color);
  388.   t    += micros() - start;
  389.   tft.fillScreen(BLACK);
  390.   x1    = w - 1;
  391.   y1    = h - 1;
  392.   y2    = 0;
  393.   start = micros();
  394.   for (x2 = 0; x2 < w; x2 += 6) tft.drawLine(x1, y1, x2, y2, color);
  395.   x2    = 0;
  396.   for (y2 = 0; y2 < h; y2 += 6) tft.drawLine(x1, y1, x2, y2, color);
  397.   return micros() - start;
  398. }
  399. unsigned long testFastLines(uint16_t color1, uint16_t color2) {
  400.   unsigned long start;
  401.   int           x, y, w = tft.width(), h = tft.height();
  402.   tft.fillScreen(BLACK);
  403.   start = micros();
  404.   for (y = 0; y < h; y += 5) tft.drawFastHLine(0, y, w, color1);
  405.   for (x = 0; x < w; x += 5) tft.drawFastVLine(x, 0, h, color2);
  406.   return micros() - start;
  407. }
  408. unsigned long testRects(uint16_t color) {
  409.   unsigned long start;
  410.   int           n, i, i2,
  411.                 cx = tft.width()  / 2,
  412.                 cy = tft.height() / 2;
  413.   tft.fillScreen(BLACK);
  414.   n     = min(tft.width(), tft.height());
  415.   start = micros();
  416.   for (i = 2; i < n; i += 6) {
  417.     i2 = i / 2;
  418.     tft.drawRect(cx - i2, cy - i2, i, i, color);
  419.   }
  420.   return micros() - start;
  421. }
  422. unsigned long testFilledRects(uint16_t color1, uint16_t color2) {
  423.   unsigned long start, t = 0;
  424.   int           n, i, i2,
  425.                 cx = tft.width()  / 2 - 1,
  426.                 cy = tft.height() / 2 - 1;
  427.   tft.fillScreen(BLACK);
  428.   n = min(tft.width(), tft.height());
  429.   for (i = n; i > 0; i -= 6) {
  430.     i2    = i / 2;
  431.     start = micros();
  432.     tft.fillRect(cx - i2, cy - i2, i, i, color1);
  433.     t    += micros() - start;
  434.     // Outlines are not included in timing results
  435.     tft.drawRect(cx - i2, cy - i2, i, i, color2);
  436.   }
  437.   return t;
  438. }
  439. unsigned long testFilledCircles(uint8_t radius, uint16_t color) {
  440.   unsigned long start;
  441.   int x, y, w = tft.width(), h = tft.height(), r2 = radius * 2;
  442.   tft.fillScreen(BLACK);
  443.   start = micros();
  444.   for (x = radius; x < w; x += r2) {
  445.     for (y = radius; y < h; y += r2) {
  446.       tft.fillCircle(x, y, radius, color);
  447.     }
  448.   }
  449.   return micros() - start;
  450. }
  451. unsigned long testCircles(uint8_t radius, uint16_t color) {
  452.   unsigned long start;
  453.   int           x, y, r2 = radius * 2,
  454.                       w = tft.width()  + radius,
  455.                       h = tft.height() + radius;
  456.   // 这个屏幕没有被清除——这是
  457.   // 有意且不影响报告时间。
  458.   start = micros();
  459.   for (x = 0; x < w; x += r2) {
  460.     for (y = 0; y < h; y += r2) {
  461.       tft.drawCircle(x, y, radius, color);
  462.     }
  463.   }
  464.   return micros() - start;
  465. }
  466. unsigned long testTriangles() {
  467.   unsigned long start;
  468.   int           n, i, cx = tft.width()  / 2 - 1,
  469.                       cy = tft.height() / 2 - 1;
  470.   tft.fillScreen(BLACK);
  471.   n     = min(cx, cy);
  472.   start = micros();
  473.   for (i = 0; i < n; i += 5) {
  474.     tft.drawTriangle(
  475.       cx    , cy - i, // 峰值
  476.       cx - i, cy + i, // 左下方
  477.       cx + i, cy + i, // 右下角
  478.       tft.color565(0, 0, i));
  479.   }
  480.   return micros() - start;
  481. }
  482. unsigned long testFilledTriangles() {
  483.   unsigned long start, t = 0;
  484.   int           i, cx = tft.width()  / 2 - 1,
  485.                    cy = tft.height() / 2 - 1;
  486.   tft.fillScreen(BLACK);
  487.   start = micros();
  488.   for (i = min(cx, cy); i > 10; i -= 5) {
  489.     start = micros();
  490.     tft.fillTriangle(cx, cy - i, cx - i, cy + i, cx + i, cy + i,
  491.                      tft.color565(0, i, i));
  492.     t += micros() - start;
  493.     tft.drawTriangle(cx, cy - i, cx - i, cy + i, cx + i, cy + i,
  494.                      tft.color565(i, i, 0));
  495.   }
  496.   return t;
  497. }
  498. unsigned long testRoundRects() {
  499.   unsigned long start;
  500.   int           w, i, i2, red, step,
  501.                 cx = tft.width()  / 2 - 1,
  502.                 cy = tft.height() / 2 - 1;
  503.   tft.fillScreen(BLACK);
  504.   w     = min(tft.width(), tft.height());
  505.   start = micros();
  506.   red = 0;
  507.   step = (256 * 6) / w;
  508.   for (i = 0; i < w; i += 6) {
  509.     i2 = i / 2;
  510.     red += step;
  511.     tft.drawRoundRect(cx - i2, cy - i2, i, i, i / 8, tft.color565(red, 0, 0));
  512.   }
  513.   return micros() - start;
  514. }
  515. unsigned long testFilledRoundRects() {
  516.   unsigned long start;
  517.   int           i, i2, green, step,
  518.                 cx = tft.width()  / 2 - 1,
  519.                 cy = tft.height() / 2 - 1;
  520.   tft.fillScreen(BLACK);
  521.   start = micros();
  522.   green = 256;
  523.   step = (256 * 6) / min(tft.width(), tft.height());
  524.   for (i = min(tft.width(), tft.height()); i > 20; i -= 6) {
  525.     i2 = i / 2;
  526.     green -= step;
  527.     tft.fillRoundRect(cx - i2, cy - i2, i, i, i / 8, tft.color565(0, green, 0));
  528.   }
  529.   return micros() - start;
  530. }
复制代码


回复

使用道具 举报

驴友花雕  中级技神
 楼主|

发表于 2021-6-28 08:21:11

实验串口返回情况

【Arduino】168种传感器模块系列实验(165)---2.4寸TFT液晶触...图1
回复

使用道具 举报

驴友花雕  中级技神
 楼主|

发表于 2021-6-28 09:07:07

本帖最后由 驴友花雕 于 2021-6-28 09:15 编辑

【Arduino】168种传感器模块系列实验(资料代码+仿真编程+图形编程)
  实验一百六十五:2.4寸TFT液晶触摸屏 彩屏模块 TFT-LCD 高清真彩显示屏
  项目之四:Kbv 图形与字符串显示的综合测试(实验记录视频1分26秒)

实验动态图1  【Arduino】168种传感器模块系列实验(165)---2.4寸TFT液晶触...图1

回复

使用道具 举报

驴友花雕  中级技神
 楼主|

发表于 2021-6-28 09:16:32

【Arduino】168种传感器模块系列实验(资料代码+仿真编程+图形编程)
  实验一百六十五:2.4寸TFT液晶触摸屏 彩屏模块 TFT-LCD 高清真彩显示屏
  项目之四:Kbv 图形与字符串显示的综合测试(实验记录视频1分26秒)

实验动态图2  【Arduino】168种传感器模块系列实验(165)---2.4寸TFT液晶触...图1

回复

使用道具 举报

驴友花雕  中级技神
 楼主|

发表于 2021-6-28 09:26:20

【Arduino】168种传感器模块系列实验(资料代码+仿真编程+图形编程)
  实验一百六十五:2.4寸TFT液晶触摸屏 彩屏模块 TFT-LCD 高清真彩显示屏
  项目之四:Kbv 图形与字符串显示的综合测试(实验记录视频1分26秒)

实验动态图3【Arduino】168种传感器模块系列实验(165)---2.4寸TFT液晶触...图1

回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

为本项目制作心愿单
购买心愿单
心愿单 编辑
[[wsData.name]]

硬件清单

  • [[d.name]]
btnicon
我也要做!
点击进入购买页面
上海智位机器人股份有限公司 沪ICP备09038501号-4

© 2013-2024 Comsenz Inc. Powered by Discuz! X3.4 Licensed

mail