驴友花雕 发表于 2021-6-28 09:31:43

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

驴友花雕 发表于 2021-6-28 09:43:10


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

驴友花雕 发表于 2021-6-28 09:50:59


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

驴友花雕 发表于 2021-6-28 09:54:37


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

https://v.youku.com/v_show/id_XNTE3NTAxMDcwNA==.html

https://v.youku.com/v_show/id_XNTE3NTAxMDcwNA==.html

驴友花雕 发表于 2021-6-28 10:22:02

【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>
#if defined(_GFXFONT_H_)         
#include <Fonts/FreeSans9pt7b.h>
#define ADJ_BASELINE 11            //新字体将光标设置为字母底部
#else
#define ADJ_BASELINE 0             //遗留设置光标到字母顶部
#endif
#include <MCUFRIEND_kbv.h>
MCUFRIEND_kbv tft;

#define BLACK   0x0000
#define BLUE    0x001F
#define RED   0xF800
#define GREEN   0x07E0
#define CYAN    0x07FF
#define MAGENTA 0xF81F
#define YELLOW0xFFE0
#define WHITE   0xFFFF

#define RGB(r, g, b) (((r&0xF8)<<8)|((g&0xFC)<<3)|(b>>3))

#define GREY      RGB(127, 127, 127)
#define DARKGREYRGB(64, 64, 64)
#define TURQUOISE RGB(0, 128, 128)
#define PINK      RGB(255, 128, 192)
#define OLIVE   RGB(128, 128, 0)
#define PURPLE    RGB(128, 0, 128)
#define AZURE   RGB(0, 128, 255)
#define ORANGE    RGB(255,128,64)

#include <stdio.h>

uint16_t ID;
uint8_t hh, mm, ss; //当前时间的储存容器变量

uint8_t conv2d(const char* p){
    uint8_t v = 0;
    if ('0' <= *p && *p <= '9') v = *p - '0';
    return 10 * v + *++p - '0';
}

void setup(void){
    Serial.begin(9600);
    tft.reset();
    ID = tft.readID();
    Serial.print("TFT ID = 0x");
    Serial.println(ID, HEX);
    //    if (ID == 0xD3D3) ID = 0x9481; // 只写扩展
    if (ID == 0xD3D3) ID = 0x9486; // 只写扩展
    tft.begin(ID);
    tft.setRotation(1);
    tft.fillScreen(BLACK);
#if defined(_GFXFONT_H_)
    tft.setFont(&FreeSans9pt7b);
#endif
    hh = conv2d(__TIME__);
    mm = conv2d(__TIME__ + 3);
    ss = conv2d(__TIME__ + 6);
}

void loop(void){
    int16_t x, y, dx, dy, radius = 108, idx;
    uint16_t w, h, len, mask;
    uint16_t colors = { BLACK, WHITE, YELLOW, CYAN, GREEN, MAGENTA, RED, BLUE };
    uint16_t height, width;
    width = tft.width();
    height = tft.height();
    tft.fillRect(0, 0, 7, 3, WHITE);
    tft.fillRect(313, 0, 7, 3, WHITE);
    tft.fillRect(0, 237, 7, 3, WHITE);
    tft.fillRect(313, 237, 7, 3, WHITE);
    for (y = 0, w = 18, h = 3; y < 240; y += 13 * w + h) {
      for (x = 25; x < 320 - 18; x += 2 * w) {
            tft.fillRect(x, y, w, h, WHITE);
      }
    }
    for (x = 0, w = 7, h = 18; x < 320; x += 17 * h + w) {
      for (y = 21; y < 240 - 18; y += 2 * h) {
            tft.fillRect(x, y, w, h, WHITE);
      }
    }
    tft.fillRect(7, 3, 17 * 18, 13 * 18, GREY);
    for (x = 7, y = 0, w = 1, h = 240; x < 320; x += 18) {
      tft.fillRect(x, y, w, h, WHITE);
    }
    for (x = 0, y = 3, w = 320, h = 1; y < 240; y += 18) {
      tft.fillRect(x, y, w, h, WHITE);
    }
    tft.fillRect(26, 22, 17, 99, TURQUOISE);
    tft.fillRect(26, 120, 17, 99, PINK);
    tft.fillRect(44, 22, 17, 35, AZURE);
    tft.fillRect(44, 184, 17, 35, ORANGE);
    tft.fillRect(260, 22, 17, 35, AZURE);
    tft.fillRect(260, 184, 17, 35, ORANGE);
    tft.fillRect(278, 22, 17, 99, OLIVE);
    tft.fillRect(278, 120, 17, 99, PURPLE);

    for (dx = radius; dx > -radius; dx--) {
      w = sqrt(radius * radius - dx * dx);
      y = 120 - dx;
      dy = (y - 3) / 18;
      mask = 7;
      colors = (dy == 3) ? DARKGREY : BLACK;
      switch (dy) {
            case 0:
            case 1: idx = 1; len = 0; break;
            case 2: idx = 0; len = 0; break;
            case 3: idx = 0; len = 13; mask = 1; break;
            case 4:
            case 5: idx = 2; len = 38; break;
            case 6:
            case 7:
            case 8: idx = 0; len = 0; break;
            case 9: for (idx = 2; idx < 8; idx++) {
                  //dy = 0xFF >> (7 - idx);
                  dy = (idx - 2) * 51;
                  colors = tft.color565(dy, dy, dy);
                }
                idx = 2; len = 38; break;
            case 10: idx = 1; len = 0; break;
            case 11:
            case 12: colors = YELLOW; idx = 2; len = 0; break;
      }
      if (len == 0)
            tft.fillRect(160 - w, y, w * 2, 1, colors);

      else {
            if (mask == 1) idx = 1 + (w) / len;
            dy = w % len;
            for (x = 160 - w; x < 160 + w; idx++) {
                tft.fillRect(x, y, dy, 1, colors);
                x += dy;
                if (x + len > 160 + w) dy = w % len;
                else dy = len;
            }
      }
    }
    for (x = 72, y = 129, dx = 5, dy = 0; dx > 0; x += 2 * dx) {
      tft.fillRect(x, y, dx, 36, WHITE);
      dy += dx * 2;
      if (dy >= 36) {
            dy = 0;
            dx--;
      }
    }
    tft.fillRect(160 - 8, 5 * 18 + 3, 17, 3 * 18, BLACK);
    for (x = 3 * 18 + 7, y = 6 * 18 + 3, w = 1, h = 18; x < 160 + 108; x += 18) {
      tft.fillRect(x, y, w, h, WHITE);
    }
    tft.fillRect(160 - 108, 120, 108 * 2, 1, WHITE);
    tft.fillRect(160, 5 * 18 + 3, 1, 3 * 18, WHITE);
    tft.fillRect(108, 2 * 18 + 3, 6 * 18, 18, WHITE);
    //    tft.fillRect(108, 10 * 18 + 3, 6 * 18, 18, BLACK);
    tft.fillRect(160 - 8, 11 * 18 + 3, 17, radius - 18*9/2, RED);
    tft.setCursor(160 - 36, 24 + ADJ_BASELINE);
    tft.setTextColor(BLACK);
    tft.setTextSize(1);
    tft.print("320x240");
    tft.setCursor(109, 43 + ADJ_BASELINE);
    tft.setTextColor(BLACK);
    tft.setTextSize(1);
    tft.print("ID=0x");
    tft.print(tft.readID(), HEX);
    tft.setTextColor(WHITE, BLACK);
    //    tft.setFont(NULL);
    //    tft.setTextSize(2);
   
    while (1) {
      if (++ss > 59) {
            ss = 0;
            mm++;
            if (mm > 59) {
                mm = 0;
                hh++;
                if (hh > 23) hh = 0;
            }
      }
      char buf;
      sprintf(buf, "%02d:%02d:%02d", hh, mm, ss);
      tft.fillRect(108, 10 * 18 + 3, 6 * 18, 18, BLACK);
      tft.setCursor(128, 187 + ADJ_BASELINE);
      tft.print(buf);
      delay(1000);
    }
}

驴友花雕 发表于 2021-6-28 10:24:55

本帖最后由 驴友花雕 于 2021-7-20 05:12 编辑

实验场景图






驴友花雕 发表于 2021-6-28 11:36:30

【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> //导入核心图形库
#include <LCDWIKI_KBV.h> //导入特定硬件库

//如果 IC 模型已知或模块不可读,则可以使用此构造函数
LCDWIKI_KBV mylcd(ILI9341, A3, A2, A1, A0, A4); //模型、CS、CD、WR、RD、重置
//如果 IC 模型未知且模块可读,则可以使用此构造函数
//LCDWIKI_KBV my_lcd(240,320,A3,A2,A1,A0,A4);//屏幕宽度、高度、cs、cd、wr、rd、重置

//定义一些颜色值
#define BLACK   0x0000
#define BLUE    0x001F
#define RED   0xF800
#define GREEN   0x07E0
#define CYAN    0x07FF
#define MAGENTA 0xF81F
#define YELLOW0xFFE0
#define WHITE   0xFFFF

void setup()
{
Serial.begin(9600);
mylcd.Init_LCD();
Serial.println(mylcd.Read_ID(), HEX);
mylcd.Fill_Screen(BLACK);
}

void loop()
{
mylcd.Set_Text_Mode(0);
//显示 1 次字符串
mylcd.Fill_Screen(0x0000);
mylcd.Set_Text_colour(RED);
mylcd.Set_Text_Back_colour(BLACK);
mylcd.Set_Text_Size(1);
mylcd.Print_String("Hello World!", 0, 0);
mylcd.Print_Number_Float(01234.56789, 2, 0, 8, '.', 0, ' ');
mylcd.Print_Number_Int(0xDEADBEF, 0, 16, 0, ' ', 16);
//mylcd.Print_String("DEADBEF", 0, 16);
delay(166);

//显示 2 次字符串
mylcd.Set_Text_colour(GREEN);
mylcd.Set_Text_Size(2);
mylcd.Print_String("Hello World!", 0, 40);
mylcd.Print_Number_Float(01234.56789, 2, 0, 56, '.', 0, ' ');
mylcd.Print_Number_Int(0xDEADBEF, 0, 72, 0, ' ', 16);
//mylcd.Print_String("DEADBEEF", 0, 72);
delay(166);

//显示 3 次字符串
mylcd.Set_Text_colour(BLUE);
mylcd.Set_Text_Size(3);
mylcd.Print_String("Hello World!", 0, 104);
mylcd.Print_Number_Float(01234.56789, 2, 0, 128, '.', 0, ' ');
mylcd.Print_Number_Int(0xDEADBEF, 0, 152, 0, ' ', 16);
// mylcd.Print_String("DEADBEEF", 0, 152);
delay(166);

//显示 4 次字符串
mylcd.Set_Text_colour(WHITE);
mylcd.Set_Text_Size(4);
mylcd.Print_String("Hello!", 0, 192);
delay(166);

//显示 5 次字符串
mylcd.Set_Text_colour(YELLOW);
mylcd.Set_Text_Size(5);
mylcd.Print_String("Hello!", 0, 224);
delay(166);

//显示 6 次字符串
mylcd.Set_Text_colour(RED);
mylcd.Set_Text_Size(6);
mylcd.Print_String("Hello!", 0, 266);
delay(666);
}

驴友花雕 发表于 2021-6-28 12:09:11

实验一百六十五:2.4寸TFT液晶触摸屏 彩屏模块 TFT-LCD 高清真彩显示屏
项目之六:逐行显示不同字号的英文字符串

实验场景动图

驴友花雕 发表于 2021-6-28 12:34:10

【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
*/

void showpins(int A, int D, int value, const char *msg) {
Serial.print(msg);
Serial.print(" (A" + String(A - A0) + ", D" + String(D) + ") = ");
Serial.println(value);
}
void setup() {
int i, j, value, Apins, Dpins, Values, found = 0;

Serial.begin(9600);
Serial.println("Making all control and bus pins INPUT_PULLUP");
Serial.println("Typical 30k Analog pullup with corresponding pin");
Serial.println("would read low when digital is written LOW");
Serial.println("e.g. reads ~25 for 300R X direction");
Serial.println("e.g. reads ~30 for 500R Y direction");
Serial.println("");

for (i = A0; i < A5; i++) pinMode(i, INPUT_PULLUP);
for (i = 2; i < 10; i++) pinMode(i, INPUT_PULLUP);
for (i = A0; i < A4; i++) {
    for (j = 5; j < 10; j++) {
      pinMode(j, OUTPUT);
      digitalWrite(j, LOW);
      value = analogRead(i);   // 忽略初读
      value = analogRead(i);
      if (value < 100) {
      showpins(i, j, value, "Testing :");
      if (found < 2) {
          Apins = i;
          Dpins = j;
          Values = value;
          found++;
      }
      }
      pinMode(j, INPUT_PULLUP);
    }
}
if (found == 2) {
    Serial.println("Diagnosing as:-");
    for (i = 0; i < 2; i++) {
      showpins(Apins, Dpins, Values, (Values < Values[!i]) ? "XM,XP: " : "YP,YM: ");
    }
}
}

void loop() {
}

驴友花雕 发表于 2021-6-28 12:39:10

实验串口返回情况
      







驴友花雕 发表于 2021-6-28 12:50:26

【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>
MCUFRIEND_kbv tft;

#define BLACK   0x0000
#define BLUE    0x001F
#define RED   0xF800
#define GREEN   0x07E0
#define CYAN    0x07FF
#define MAGENTA 0xF81F
#define YELLOW0xFFE0
#define WHITE   0xFFFF

// 在行号中工作。 以 16 为单位的字体高度
int16_t ht = 16, top = 3, line, lines = 15, scroll;

void setup() {
tft.reset();
uint16_t id = tft.readID();
tft.begin(id);
tft.setRotation(0);   //肖像
tft.fillScreen(BLACK);
tft.setTextColor(WHITE, BLACK);
tft.setTextSize(2);   // 系统字体为 8 像素。 ht = 8*2=16
tft.setCursor(100, 0);
tft.print("ID = 0x");
tft.println(id, HEX);
if (id == 0x9320 || id == 0x9325 || id == 0xB509) {
    top = 0;                      // 这些控制器滚动全屏
    lines = tft.height() / ht;    // 我们处于纵向模式
}
if (id == 0x7783) {
    tft.println("can NOT scroll");
    while (1);                  // 休止
}
tft.setCursor(0, 0);
for (line = 1; line < 21; line++) tft.println(String(line) + ": ");
}

void loop()
{
tft.setCursor(0, (scroll + top) * ht);
if (++scroll >= lines) scroll = 0;
tft.vertScroll(top * ht, lines * ht, (scroll) * ht);
tft.println(String(line) + ": [" + String(scroll) + "]");
delay(100);
line++;
}

驴友花雕 发表于 2021-6-28 12:59:59

实验场景图


驴友花雕 发表于 2021-6-28 13:53:18

【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>
MCUFRIEND_kbv tft;

void setup(){
    Serial.begin(9600);
    tft.reset();
    uint16_t identifier = tft.readID();
    Serial.print("ID = 0x");
    Serial.println(identifier, HEX);
    if (identifier == 0xEFEF) identifier = 0x9486;
    tft.begin(identifier);
    // tft fill Screen (BLACK);
}

char *msg[] = { "PORTRAIT", "LANDSCAPE", "PORTRAIT_REV", "LANDSCAPE_REV" };
uint8_t aspect;

void loop(){
    uint16_t x = 50, y = 100;
    tft.setRotation(aspect);
    tft.fillScreen(0x0000);
    tft.setCursor(0, 0);
    tft.setTextSize(2);
    tft.println(msg);
    tft.setCursor(x, y);
    tft.println("");
    delay(800);
    tft.println("INVERT ON");
    tft.invertDisplay(true);
    delay(250);
    tft.invertDisplay(false);
    tft.println("INVERT OFF");
    delay(250);
    if (++aspect >= 4) aspect = 0;
}

驴友花雕 发表于 2021-6-28 13:54:34

实验场景图


驴友花雕 发表于 2021-6-28 14:49:28

【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>   // 导入特定硬件库
MCUFRIEND_kbv tft;

#include <Fonts/FreeSans9pt7b.h> //导入字体库
#include <Fonts/FreeSans12pt7b.h>
#include <Fonts/FreeSerif12pt7b.h>

#include <FreeDefaultFonts.h>

#define BLACK   0x0000
#define RED   0xF800
#define GREEN   0x07E0
#define WHITE   0xFFFF
#define GREY    0x8410

void setup(void){
    Serial.begin(9600);
    uint16_t ID = tft.readID();
    Serial.println("Example: Font_simple");
    Serial.print("found ID = 0x");
    Serial.println(ID, HEX);
    Serial.println("The display font is ready OK!");
    if (ID == 0xD3D3) ID = 0x9481; //如果只写显示,则强制 ID
    tft.begin(ID);
    tft.setRotation(0);
}

void loop(void){
    tft.fillScreen(BLACK);
    showmsgXY(20, 10, 1, NULL, "System x1");
    showmsgXY(20, 24, 2, NULL, "System x2");
    showmsgXY(20, 60, 1, &FreeSans9pt7b, "FreeSans9pt7b");
    showmsgXY(20, 80, 1, &FreeSans12pt7b, "FreeSans12pt7b");
    showmsgXY(20, 100, 1, &FreeSerif12pt7b, "FreeSerif12pt7b");
    showmsgXY(20, 120, 1, &FreeSmallFont, "FreeSmallFont");
    showmsgXY(5, 180, 1, &FreeSevenSegNumFont, "01234");
    showmsgXY(5, 190, 1, NULL, "System Font is drawn from topline");
    tft.setTextColor(RED, GREY);
    tft.setTextSize(2);
    tft.setCursor(0, 220);
    tft.print("7x5 can overwrite");
    delay(50);
    tft.setCursor(0, 220);
    tft.print("if background set");
    delay(50);
    showmsgXY(5, 260, 1, &FreeSans9pt7b, "Free Fonts from baseline");
   delay(50);
    showmsgXY(5, 285, 1, &FreeSans9pt7b, "Free Fonts transparent");
    delay(50);
    showmsgXY(5, 310, 1, &FreeSans9pt7b, "erase backgnd with fillRect()");
    delay(300);
}

void showmsgXY(int x, int y, int sz, const GFXfont *f, const char *msg)
{
    int16_t x1, y1;
    uint16_t wid, ht;
    tft.drawFastHLine(0, y, tft.width(), WHITE);
    tft.setFont(f);
    tft.setCursor(x, y);
    tft.setTextColor(GREEN);
    tft.setTextSize(sz);
    tft.print(msg);
    delay(500);
}

驴友花雕 发表于 2021-6-28 15:13:24

【Arduino】168种传感器模块系列实验(资料代码+仿真编程+图形编程)实验一百六十五:2.4寸TFT液晶触摸屏 彩屏模块 TFT-LCD 高清真彩显示屏项目之十:逐行显示不同字号的英文字符串
实验场景图

驴友花雕 发表于 2021-6-28 15:36:05

实验串口返回情况


驴友花雕 发表于 2021-6-28 16:04:51

【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
*/

#define LCD_CS A3 // Chip Select goes to Analog 3
#define LCD_CD A2 // Command/Data goes to Analog 2
#define LCD_WR A1 // LCD Write goes to Analog 1
#define LCD_RD A0 // LCD Read goes to Analog 0
#define LCD_RESET A4 // Can alternately just connect to Arduino's reset pin

#include <Adafruit_GFX.h> // Hardware-specific library
#include <MCUFRIEND_kbv.h>
MCUFRIEND_kbv tft;

//#include <Adafruit_TFTLCD.h> // Hardware-specific library
//Adafruit_TFTLCD tft(LCD_CS, LCD_CD, LCD_WR, LCD_RD, LCD_RESET);
//Adafruit_TFTLCD tft;

//为一些常见的 16 位颜色值分配可读的名称
#define        BLACK   0x0000
#define        BLUE    0x001F
#define        RED   0xF800
#define        GREEN   0x07E0
#define CYAN    0x07FF
#define MAGENTA 0xF81F
#define YELLOW0xFFE0
#define WHITE   0xFFFF

void setup(void);
void loop(void);

uint16_t g_identifier;

void setup(void) {
tft.reset();
g_identifier = tft.readID();

Serial.begin(9600);
Serial.print("readID = 0x");
Serial.println(g_identifier, HEX);
if (g_identifier == 0xFFFF) g_identifier = 0x9341;
if (g_identifier == 0) {
    Serial.println("Unknown ID");
    while (1);
}

tft.begin(g_identifier);
tft.setRotation(0);
}

uint16_t colors[] = {
BLACK, BLUE
};

void colordump(uint16_t x, uint16_t y)
{
uint16_t pixel, pixels;
char i, j, buf, dirty;
uint8_t wid = (tft.width() - 9 * 6) / (5 * 6), ht = (tft.height() / 8) - 1;
tft.setTextColor(WHITE);
tft.setTextSize(1);
for (j = 0; j < ht; j++) {
    sprintf(buf, "%3d,%3d:", x, y + j);
    tft.print(buf);
    dirty = 1;
    for (i = 0; i < wid; i++) {
#if 1 && defined(MCUFRIEND_KBV_H_)
      if (dirty) tft.readGRAM(x, y + j, pixels, wid, 1);
      dirty = 0;
      pixel = pixels;
#else
      pixel = tft.readPixel(x + i, y + j);
#endif
      tft.print(" ");
      if (pixel == WHITE) tft.setTextColor(GREEN);
      sprintf(buf, "%04X", pixel);
      tft.print(buf);
      tft.setTextColor(WHITE);
    }
    tft.println();
}
}

uint16_t bgr(uint16_t color) {
return ((color & 0xF800) >> 11) | (color & 0x7E0) | (color & 0x1F) << 11;
}

void duffcolor(uint16_t color) {
uint16_t pixel, x, y;
char done, buf;
uint16_t BGR = bgr(color);
for (done = 0, y = 0; y < 320 && !done; y++) {
    for (x = 0; x < 240; x++) {
      //pixel = readxy(x, y);
      pixel = tft.readPixel(x, y);
      if (pixel != BGR) {
      done = 1;
      sprintf(buf, "0x%04X @ %d, %d", pixel, x, y);
      tft.println(buf);
      break;
      }
    }
}
}

uint8_t aspect;
char *aspectname[] = {
"PORTRAIT", "LANDSCAPE", "PORTRAIT_REV", "LANDSCAPE_REV"
};

void loop(void) {
uint16_t iter, color;
char buf;
aspect = (aspect + 1) & 3;
tft.setRotation(aspect);
for (iter = 0; iter < sizeof(colors) / sizeof(uint16_t); iter++) {
    color = colors;
    tft.fillScreen(color);
    tft.setTextColor(WHITE);
    tft.setTextSize(1);
    tft.setCursor(0, 0);
    sprintf(buf, "ID=0x%04X Background=%04X %s",
            tft.readID(), color, aspectname);
    tft.println(buf);
    colordump(6 * 6, 0);
    //duffcolor(color);
    delay(400);
}
}

驴友花雕 发表于 2021-6-28 16:09:33

【Arduino】168种传感器模块系列实验(资料代码+仿真编程+图形编程)
实验一百六十五:2.4寸TFT液晶触摸屏 彩屏模块 TFT-LCD 高清真彩显示屏
项目之十一:四方向满屏动态字符串

实验场景图

驴友花雕 发表于 2021-6-28 16:46:06

【Arduino】168种传感器模块系列实验(资料代码+仿真编程+图形编程)
实验一百六十五:2.4寸TFT液晶触摸屏 彩屏模块 TFT-LCD 高清真彩显示屏
项目之十二:读取MCUFRIEND UNO shield上的寄存器16位或8位值序列
实验开源代码:

/*
【Arduino】168种传感器模块系列实验(资料代码+仿真编程+图形编程)
实验一百六十五:2.4寸TFT液晶触摸屏 彩屏模块 TFT-LCD 高清真彩显示屏
项目之十二:读取MCUFRIEND UNO shield上的寄存器16位或8位值序列
模块直插,引脚用法如下:
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
*/

//Arduino UNO或Mega 2560作为扩展
#define LCD_RST A4
#define LCD_CS A3
#define LCD_RS A2
#define LCD_WR A1
#define LCD_RD A0

#define LCD_D0 8
#define LCD_D1 9
#define LCD_D2 2
#define LCD_D3 3
#define LCD_D4 4
#define LCD_D5 5
#define LCD_D6 6
#define LCD_D7 7

void setup(){
    Serial.begin(9600);
    while (!Serial) ;
    Serial.println("Read Registers on MCUFRIEND UNO shield");
    Serial.println("controllers either read as single 16-bit");
    Serial.println("e.g. the ID is at readReg(0)");
    Serial.println("or as a sequence of 8-bit values");
    Serial.println("in special locations (first is dummy)");
    Serial.println("");
    lcdInit();
    lcdReset();      //ensures that controller is in default state
//    for (uint16_t i = 0; i < 256; i++) readReg(i, 7, "f.k");
    readReg(0x00, 2, "ID: ILI9320, ILI9325, ILI9335, ...");
    readReg(0x04, 4, "Manufacturer ID");
    readReg(0x09, 5, "Status Register");
    readReg(0x0A, 2, "Get Power Mode");
    readReg(0x0C, 2, "Get Pixel Format");
    readReg(0x61, 2, "RDID1 HX8347-G");
    readReg(0x62, 2, "RDID2 HX8347-G");
    readReg(0x63, 2, "RDID3 HX8347-G");
    readReg(0x64, 2, "RDID1 HX8347-A");
    readReg(0x65, 2, "RDID2 HX8347-A");
    readReg(0x66, 2, "RDID3 HX8347-A");
    readReg(0x67, 2, "RDID Himax HX8347-A");
    readReg(0x70, 2, "Panel Himax HX8347-A");
    readReg(0xA1, 5, "RD_DDB SSD1963");
    readReg(0xB0, 2, "RGB Interface Signal Control");
    readReg(0xB4, 2, "Inversion Control");
    readReg(0xB6, 5, "Display Control");
    readReg(0xB7, 2, "Entry Mode Set");
    readReg(0xBF, 6, "ILI9481, HX8357-B");
    readReg(0xC0, 9, "Panel Control");
    readReg(0xC8, 13, "GAMMA");
    readReg(0xCC, 2, "Panel Control");
    readReg(0xD0, 3, "Power Control");
    readReg(0xD2, 5, "NVM Read");
    readReg(0xD3, 4, "ILI9341, ILI9488");
    readReg(0xD4, 4, "Novatek ID");
    readReg(0xDA, 2, "RDID1");
    readReg(0xDB, 2, "RDID2");
    readReg(0xDC, 2, "RDID3");
    readReg(0xE0, 16, "GAMMA-P");
    readReg(0xE1, 16, "GAMMA-N");
    readReg(0xEF, 6, "ILI9327");
    readReg(0xF2, 12, "Adjust Control 2");
    readReg(0xF6, 4, "Interface Control");
}

void loop() {
}

void printhex(uint8_t val){
    if (val < 0x10) Serial.print("0");
    Serial.print(val, HEX);
}

void readReg(uint16_t reg, uint8_t n, const char *msg){
    uint8_t val8;
    lcdReset();
    lcdSetWriteDir();
    lcdWriteCommand(0xB0);   //Command Access Protect
    lcdWriteData(0x00);      //looks wrong
/*
    lcdWriteCommand(0xF6);
    lcdWriteData(0x01);
    lcdWriteData(0x01);
    lcdWriteData(0x03);
*/
    lcdWriteCommand(reg);
    Serial.print("reg(0x");
    printhex(reg >> 8);
    printhex(reg);
    Serial.print(")");
    lcdSetReadDir();
    while (n--) {
      val8 = lcdReadData8();
      Serial.print(" ");
      printhex(val8);
    }
    lcdSetWriteDir();
    Serial.print("\t");
    Serial.println(msg);
}

void lcdInit(){
    pinMode(LCD_CS, OUTPUT);
    digitalWrite(LCD_CS, HIGH);
    pinMode(LCD_RS, OUTPUT);
    digitalWrite(LCD_RS, HIGH);
    pinMode(LCD_WR, OUTPUT);
    digitalWrite(LCD_WR, HIGH);
    pinMode(LCD_RD, OUTPUT);
    digitalWrite(LCD_RD, HIGH);
    pinMode(LCD_RST, OUTPUT);
    digitalWrite(LCD_RST, HIGH);
}

void lcdReset(){
    digitalWrite(LCD_RST, LOW);
    delay(2);
    digitalWrite(LCD_RST, HIGH);
    delay(10);             //允许控制器重新启动
}

void lcdWrite8(uint16_t data){
    digitalWrite(LCD_D0, data & 1);
    digitalWrite(LCD_D1, (data & 2) >> 1);
    digitalWrite(LCD_D2, (data & 4) >> 2);
    digitalWrite(LCD_D3, (data & 8) >> 3);
    digitalWrite(LCD_D4, (data & 16) >> 4);
    digitalWrite(LCD_D5, (data & 32) >> 5);
    digitalWrite(LCD_D6, (data & 64) >> 6);
    digitalWrite(LCD_D7, (data & 128) >> 7);
}

uint16_t lcdRead8(){
    uint16_t result = digitalRead(LCD_D7);
    result <<= 1;
    result |= digitalRead(LCD_D6);
    result <<= 1;
    result |= digitalRead(LCD_D5);
    result <<= 1;
    result |= digitalRead(LCD_D4);
    result <<= 1;
    result |= digitalRead(LCD_D3);
    result <<= 1;
    result |= digitalRead(LCD_D2);
    result <<= 1;
    result |= digitalRead(LCD_D1);
    result <<= 1;
    result |= digitalRead(LCD_D0);
    return result;
}

void lcdSetWriteDir(){
    pinMode(LCD_D0, OUTPUT);
    pinMode(LCD_D1, OUTPUT);
    pinMode(LCD_D2, OUTPUT);
    pinMode(LCD_D3, OUTPUT);
    pinMode(LCD_D4, OUTPUT);
    pinMode(LCD_D5, OUTPUT);
    pinMode(LCD_D6, OUTPUT);
    pinMode(LCD_D7, OUTPUT);
}


void lcdSetReadDir(){
    pinMode(LCD_D0, INPUT);
    pinMode(LCD_D1, INPUT);
    pinMode(LCD_D2, INPUT);
    pinMode(LCD_D3, INPUT);
    pinMode(LCD_D4, INPUT);
    pinMode(LCD_D5, INPUT);
    pinMode(LCD_D6, INPUT);
    pinMode(LCD_D7, INPUT);
}

void lcdWriteData(uint16_t data){
    lcdSetWriteDir();
    digitalWrite(LCD_CS, LOW);
    digitalWrite(LCD_RS, HIGH);
    digitalWrite(LCD_RD, HIGH);
    digitalWrite(LCD_WR, HIGH);
    lcdWrite8(data >> 8);
    digitalWrite(LCD_WR, LOW);
    delayMicroseconds(10);
    digitalWrite(LCD_WR, HIGH);
    lcdWrite8(data);
    digitalWrite(LCD_WR, LOW);
    delayMicroseconds(10);
    digitalWrite(LCD_WR, HIGH);
    digitalWrite(LCD_CS, HIGH);
}

void lcdWriteCommand(uint16_t command){
    lcdSetWriteDir();
    digitalWrite(LCD_CS, LOW);
    digitalWrite(LCD_RS, LOW);
    digitalWrite(LCD_RD, HIGH);
    digitalWrite(LCD_WR, HIGH);
    lcdWrite8(command >> 8);
    digitalWrite(LCD_WR, LOW);
    delayMicroseconds(10);
    digitalWrite(LCD_WR, HIGH);
    lcdWrite8(command);
    digitalWrite(LCD_WR, LOW);
    delayMicroseconds(10);
    digitalWrite(LCD_WR, HIGH);
    digitalWrite(LCD_CS, HIGH);
}

uint8_t lcdReadData8(){
    uint8_t result;
    lcdSetReadDir();
    digitalWrite(LCD_CS, LOW);
    digitalWrite(LCD_RS, HIGH);
    digitalWrite(LCD_RD, HIGH);
    digitalWrite(LCD_WR, HIGH);
    digitalWrite(LCD_RD, LOW);
    delayMicroseconds(10);
    result = lcdRead8();
    digitalWrite(LCD_RD, HIGH);
    delayMicroseconds(10);
    return result;
}

uint16_t lcdReadData16(){
    uint16_t result;
    result = lcdReadData8() << 8;
    result |= lcdReadData8();
    return result;
}

void lcdWriteRegister(uint16_t addr, uint16_t data){
    lcdWriteCommand(addr);
    lcdWriteData(data);
}


驴友花雕 发表于 2021-6-28 16:49:44

实验串口返回情况


页: 1 2 [3] 4 5 6 7
查看完整版本: 【Arduino】168种传感器模块系列实验(165)---2.4寸TFT液晶触...