1. 在这个模板中,我们只是通过 RGBbitmap 和位图功能显示一些图像。只需为触摸屏制作代码并使用此模板即可。下载. h 文件并将其添加到 Arduino 草图的文件夹中。
    2. #include “Adafruit_GFX.h” // Core graphics library
    3. #include “MCUFRIEND_kbv.h” // Hardware-specific library
    4. MCUFRIEND_kbv tft;
    5. #define BLACK 0x0000
    6. #define RED 0xF800
    7. #define GREEN 0x07E0
    8. #define WHITE 0xFFFF
    9. #define GREY 0x8410
    10. #include “images.h”
    11. #include “Fonts/FreeSans9pt7b.h”
    12. #include “Fonts/FreeSans12pt7b.h”
    13. #include “Fonts/FreeSerif12pt7b.h”
    14. #include “FreeDefaultFonts.h”
    15. int a = 3000;
    16. int b = 4000;
    17. int j, j2;
    18. int i, i2;
    19. void showmsgXY(int x, int y, int sz, const GFXfont f, const char msg)
    20. {
    21. int16_t x1, y1;
    22. uint16_t wid, ht;
    23. // tft.drawFastHLine(0, y, tft.width(), 0xffff);
    24. tft.setFont(f);
    25. tft.setCursor(x, y);
    26. tft.setTextColor(WHITE);
    27. tft.setTextSize(sz);
    28. tft.print(msg);
    29. delay(1000);
    30. }
    31. void setup()
    32. {
    33. Serial.begin(9600);
    34. uint16_t ID = tft.readID();
    35. tft.begin(ID);
    36. tft.invertDisplay(true);
    37. tft.setRotation(1);
    38. }
    39. void loop(void)
    40. {
    41. tft.invertDisplay(true);
    42. tft.fillScreen(BLACK);
    43. tft.drawRGBBitmap(0, 0, test, 480, 320);
    44. tft.drawBitmap(20, 20, Line1, 45, 45, 0xffff);//battery
    45. tft.drawBitmap(65, 20, Line2, 45, 45, 0xffff);//wifi
    46. tft.drawBitmap(125, 25, Line3, 45, 45, 0xffff);//mail
    47. tft.drawBitmap(185, 25, Line4, 45, 45, 0xffff);//instagram
    48. tft.drawBitmap(245, 25, Line6, 45, 45, 0xffff);//power
    49. tft.drawBitmap(20, 260, Line5, 45, 45, 0xffff);//twitter
    50. tft.drawBitmap(410, 140, Line7, 45, 45, 0xffff);//rain
    51. tft.setTextSize(6);
    52. tft.setTextColor(0xffff);
    53. tft.setCursor(280, 210);
    54. tft.print(“20:45”);
    55. tft.setTextSize(2);
    56. tft.setTextColor(0xffff);
    57. showmsgXY(330, 280, 1, &FreeSans12pt7b, “Saturday”);
    58. showmsgXY(300, 305, 1, &FreeSans12pt7b, “6 October 2018”);
    59. while (1);
    60. }