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 showmsgXYint 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.setFontf);
    25. tft.setCursorx y);
    26. tft.setTextColorWHITE);
    27. tft.setTextSizesz);
    28. tft.printmsg);
    29. delay1000);
    30. }
    31. void setup()
    32. {
    33. Serial.begin9600);
    34. uint16_t ID = tft.readID();
    35. tft.beginID);
    36. tft.invertDisplaytrue);
    37. tft.setRotation1);
    38. }
    39. void loopvoid
    40. {
    41. tft.invertDisplaytrue);
    42. tft.fillScreenBLACK);
    43. tft.drawRGBBitmap0 0 test 480 320);
    44. tft.drawBitmap20 20 Line1 45 45 0xffff);//battery
    45. tft.drawBitmap65 20 Line2 45 45 0xffff);//wifi
    46. tft.drawBitmap125 25 Line3 45 45 0xffff);//mail
    47. tft.drawBitmap185 25 Line4 45 45 0xffff);//instagram
    48. tft.drawBitmap245 25 Line6 45 45 0xffff);//power
    49. tft.drawBitmap20 260 Line5 45 45 0xffff);//twitter
    50. tft.drawBitmap410 140 Line7 45 45 0xffff);//rain
    51. tft.setTextSize6);
    52. tft.setTextColor0xffff);
    53. tft.setCursor280 210);
    54. tft.print(“20:45”);
    55. tft.setTextSize2);
    56. tft.setTextColor0xffff);
    57. showmsgXY330 280 1 &FreeSans12pt7b Saturday”);
    58. showmsgXY300 305 1 &FreeSans12pt7b 6 October 2018”);
    59. while 1);
    60. }