查看: 3507|回复: 0

Tiny ML微型机器学习开发板 + 显示字符例程

[复制链接]
  • TA的每日心情
    开心
    2024-10-25 14:50
  • 签到天数: 1071 天

    连续签到: 1 天

    [LV.10]以坛为家III

    发表于 2021-7-15 11:00:38 | 显示全部楼层 |阅读模式
    分享到:


        通过开发板的例程,来了解显示屏。
        通过上篇 开发环境的搭建https://www.cirmall.com/bbs/thread-207473-1-1.html,开发工具包含开发板一些例程,下面通过一些例程来学习。


        一、打开例程


        1.1、打开示例,选择开发板下LCD的例程,选择字体的例程。
        001.png
       
        1.2、项目文件
        002.png


        1.3、程序源码
       
    1. /*
    2.     Example for TFT_eSPI library

    3.     Created by Bodmer 31/12/16

    4.     This example draws all fonts (as used by the Adafruit_GFX library) onto the
    5.     screen. These fonts are called the GFX Free Fonts (GFXFF) in this library.

    6.     The fonts are referenced by a short name, see the Free_Fonts.h file
    7.     attached to this sketch.

    8.     Other True Type fonts could be converted using the utility within the
    9.     "fontconvert" folder inside the library. This converted has also been
    10.     copied from the Adafruit_GFX library.

    11.     Since these fonts are a recent addition Adafruit do not have a tutorial
    12.     available yet on how to use the fontconvert utility.   Linux users will
    13.     no doubt figure it out!  In the meantime there are 48 font files to use
    14.     in sizes from 9 point to 24 point, and in normal, bold, and italic or
    15.     oblique styles.

    16.     This example sketch uses both the print class and drawString() functions
    17.     to plot text to the screen.

    18.     Make sure LOAD_GFXFF is defined in the User_Setup.h file within the
    19.     library folder.

    20.     --------------------------- NOTE ----------------------------------------
    21.     The free font encoding format does not lend itself easily to plotting
    22.     the background without flicker. For values that changes on screen it is
    23.     better to use Fonts 1- 8 which are encoded specifically for rapid
    24.     drawing with background.
    25.     -------------------------------------------------------------------------

    26.     #########################################################################
    27.     ###### DON'T FORGET TO UPDATE THE User_Setup.h FILE IN THE LIBRARY ######
    28.     ######       TO SELECT YOUR DISPLAY TYPE AND ENABLE FONTS          ######
    29.     #########################################################################
    30. */

    31. #define TEXT "aA MWyz~12" // Text that will be printed on screen in any font

    32. #include "Free_Fonts.h" // Include the header file attached to this sketch

    33. #include "SPI.h"
    34. #include "TFT_eSPI.h"

    35. // Use hardware SPI
    36. TFT_eSPI tft = TFT_eSPI();

    37. unsigned long drawTime = 0;

    38. void setup(void) {

    39.     tft.begin();

    40.     tft.setRotation(1);

    41. }

    42. void loop() {

    43.     // >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
    44.     // Show all 48 fonts in centre of screen ( x,y coordinate 160,120)
    45.     // >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>

    46.     // Where font sizes increase the screen is not cleared as the larger fonts overwrite
    47.     // the smaller one with the background colour.

    48.     // Set text datum to middle centre
    49.     tft.setTextDatum(MC_DATUM);

    50.     // Set text colour to orange with black background
    51.     tft.setTextColor(TFT_WHITE, TFT_BLACK);

    52.     tft.fillScreen(TFT_BLACK);            // Clear screen
    53.     tft.setFreeFont(FF18);                 // Select the font
    54.     tft.drawString(sFF1, 160, 60, GFXFF);// Print the string name of the font
    55.     tft.setFreeFont(FF1);                 // Select the font
    56.     tft.drawString(TEXT, 160, 120, GFXFF);// Print the string name of the font
    57.     delay(1000);
    58.     //tft.fillScreen(TFT_BLACK);
    59.     tft.setFreeFont(FF18);                 // Select the font
    60.     tft.drawString(sFF2, 160, 60, GFXFF);// Print the string name of the font
    61.     tft.setFreeFont(FF2);
    62.     tft.drawString(TEXT, 160, 120, GFXFF);
    63.     delay(1000);
    64.     //tft.fillScreen(TFT_BLACK);
    65.     tft.setFreeFont(FF18);                 // Select the font
    66.     tft.drawString(sFF3, 160, 60, GFXFF);// Print the string name of the font
    67.     tft.setFreeFont(FF3);
    68.     tft.drawString(TEXT, 160, 120, GFXFF);
    69.     delay(1000);
    70.     //tft.fillScreen(TFT_BLACK);
    71.     tft.setFreeFont(FF18);                 // Select the font
    72.     tft.drawString(sFF4, 160, 60, GFXFF);// Print the string name of the font
    73.     tft.setFreeFont(FF4);
    74.     tft.drawString(TEXT, 160, 120, GFXFF);
    75.     delay(1000);

    76.     tft.fillScreen(TFT_BLACK);
    77.     tft.setFreeFont(FF18);                 // Select the font
    78.     tft.drawString(sFF5, 160, 60, GFXFF);// Print the string name of the font
    79.     tft.setFreeFont(FF5);
    80.     tft.drawString(TEXT, 160, 120, GFXFF);
    81.     delay(1000);
    82.     //tft.fillScreen(TFT_BLACK);
    83.     tft.setFreeFont(FF18);                 // Select the font
    84.     tft.drawString(sFF6, 160, 60, GFXFF);// Print the string name of the font
    85.     tft.setFreeFont(FF6);
    86.     tft.drawString(TEXT, 160, 120, GFXFF);
    87.     delay(1000);
    88.     //tft.fillScreen(TFT_BLACK);
    89.     tft.setFreeFont(FF18);                 // Select the font
    90.     tft.drawString(sFF7, 160, 60, GFXFF);// Print the string name of the font
    91.     tft.setFreeFont(FF7);
    92.     tft.drawString(TEXT, 160, 120, GFXFF);
    93.     delay(1000);
    94.     //tft.fillScreen(TFT_BLACK);
    95.     tft.setFreeFont(FF18);                 // Select the font
    96.     tft.drawString(sFF8, 160, 60, GFXFF);// Print the string name of the font
    97.     tft.setFreeFont(FF8);
    98.     tft.drawString(TEXT, 160, 120, GFXFF);
    99.     delay(1000);

    100.     tft.fillScreen(TFT_BLACK);
    101.     tft.setFreeFont(FF18);                 // Select the font
    102.     tft.drawString(sFF9, 160, 60, GFXFF);// Print the string name of the font
    103.     tft.setFreeFont(FF9);
    104.     tft.drawString(TEXT, 160, 120, GFXFF);
    105.     delay(1000);
    106.     //tft.fillScreen(TFT_BLACK);
    107.     tft.setFreeFont(FF18);                 // Select the font
    108.     tft.drawString(sFF10, 160, 60, GFXFF);// Print the string name of the font
    109.     tft.setFreeFont(FF10);
    110.     tft.drawString(TEXT, 160, 120, GFXFF);
    111.     delay(1000);
    112.     //tft.fillScreen(TFT_BLACK);
    113.     tft.setFreeFont(FF18);                 // Select the font
    114.     tft.drawString(sFF11, 160, 60, GFXFF);// Print the string name of the font
    115.     tft.setFreeFont(FF11);
    116.     tft.drawString(TEXT, 160, 120, GFXFF);
    117.     delay(1000);
    118.     //tft.fillScreen(TFT_BLACK);
    119.     tft.setFreeFont(FF18);                 // Select the font
    120.     tft.drawString(sFF12, 160, 60, GFXFF);// Print the string name of the font
    121.     tft.setFreeFont(FF12);
    122.     tft.drawString(TEXT, 160, 120, GFXFF);
    123.     delay(1000);

    124.     tft.fillScreen(TFT_BLACK);
    125.     tft.setFreeFont(FF18);                 // Select the font
    126.     tft.drawString(sFF13, 160, 60, GFXFF);// Print the string name of the font
    127.     tft.setFreeFont(FF13);
    128.     tft.drawString(TEXT, 160, 120, GFXFF);
    129.     delay(1000);
    130.     //tft.fillScreen(TFT_BLACK);
    131.     tft.setFreeFont(FF18);                 // Select the font
    132.     tft.drawString(sFF14, 160, 60, GFXFF);// Print the string name of the font
    133.     tft.setFreeFont(FF14);
    134.     tft.drawString(TEXT, 160, 120, GFXFF);
    135.     delay(1000);
    136.     //tft.fillScreen(TFT_BLACK);
    137.     tft.setFreeFont(FF18);                 // Select the font
    138.     tft.drawString(sFF15, 160, 60, GFXFF);// Print the string name of the font
    139.     tft.setFreeFont(FF15);
    140.     tft.drawString(TEXT, 160, 120, GFXFF);
    141.     delay(1000);
    142.     //tft.fillScreen(TFT_BLACK);
    143.     tft.setFreeFont(FF18);                 // Select the font
    144.     tft.drawString(sFF16, 160, 60, GFXFF);// Print the string name of the font
    145.     tft.setFreeFont(FF16);
    146.     tft.drawString(TEXT, 160, 120, GFXFF);
    147.     delay(1000);

    148.     tft.fillScreen(TFT_BLACK);
    149.     tft.setFreeFont(FF18);                 // Select the font
    150.     tft.drawString(sFF17, 160, 60, GFXFF);// Print the string name of the font
    151.     tft.setFreeFont(FF17);
    152.     tft.drawString(TEXT, 160, 120, GFXFF);
    153.     delay(1000);
    154.     //tft.fillScreen(TFT_BLACK);
    155.     tft.setFreeFont(FF18);                 // Select the font
    156.     tft.drawString(sFF18, 160, 60, GFXFF);// Print the string name of the font
    157.     tft.setFreeFont(FF18);
    158.     tft.drawString(TEXT, 160, 120, GFXFF);
    159.     delay(1000);
    160.     //tft.fillScreen(TFT_BLACK);
    161.     tft.setFreeFont(FF18);                 // Select the font
    162.     tft.drawString(sFF19, 160, 60, GFXFF);// Print the string name of the font
    163.     tft.setFreeFont(FF19);
    164.     tft.drawString(TEXT, 160, 120, GFXFF);
    165.     delay(1000);
    166.     //tft.fillScreen(TFT_BLACK);
    167.     tft.setFreeFont(FF18);                 // Select the font
    168.     tft.drawString(sFF20, 160, 60, GFXFF);// Print the string name of the font
    169.     tft.setFreeFont(FF20);
    170.     tft.drawString(TEXT, 160, 120, GFXFF);
    171.     delay(1000);

    172.     tft.fillScreen(TFT_BLACK);
    173.     tft.setFreeFont(FF18);                 // Select the font
    174.     tft.drawString(sFF21, 160, 60, GFXFF);// Print the string name of the font
    175.     tft.setFreeFont(FF21);
    176.     tft.drawString(TEXT, 160, 120, GFXFF);
    177.     delay(1000);
    178.     //tft.fillScreen(TFT_BLACK);
    179.     tft.setFreeFont(FF18);                 // Select the font
    180.     tft.drawString(sFF22, 160, 60, GFXFF);// Print the string name of the font
    181.     tft.setFreeFont(FF22);
    182.     tft.drawString(TEXT, 160, 120, GFXFF);
    183.     delay(1000);
    184.     //tft.fillScreen(TFT_BLACK);
    185.     tft.setFreeFont(FF18);                 // Select the font
    186.     tft.drawString(sFF23, 160, 60, GFXFF);// Print the string name of the font
    187.     tft.setFreeFont(FF23);
    188.     tft.drawString(TEXT, 160, 120, GFXFF);
    189.     delay(1000);
    190.     //tft.fillScreen(TFT_BLACK);
    191.     tft.setFreeFont(FF18);                 // Select the font
    192.     tft.drawString(sFF24, 160, 60, GFXFF);// Print the string name of the font
    193.     tft.setFreeFont(FF24);
    194.     tft.drawString(TEXT, 160, 120, GFXFF);
    195.     delay(1000);

    196.     tft.fillScreen(TFT_BLACK);
    197.     tft.setFreeFont(FF18);                 // Select the font
    198.     tft.drawString(sFF25, 160, 60, GFXFF);// Print the string name of the font
    199.     tft.setFreeFont(FF25);
    200.     tft.drawString(TEXT, 160, 120, GFXFF);
    201.     delay(1000);
    202.     //tft.fillScreen(TFT_BLACK);
    203.     tft.setFreeFont(FF18);                 // Select the font
    204.     tft.drawString(sFF26, 160, 60, GFXFF);// Print the string name of the font
    205.     tft.setFreeFont(FF26);
    206.     tft.drawString(TEXT, 160, 120, GFXFF);
    207.     delay(1000);
    208.     //tft.fillScreen(TFT_BLACK);
    209.     tft.setFreeFont(FF18);                 // Select the font
    210.     tft.drawString(sFF27, 160, 60, GFXFF);// Print the string name of the font
    211.     tft.setFreeFont(FF27);
    212.     tft.drawString(TEXT, 160, 120, GFXFF);
    213.     delay(1000);
    214.     //tft.fillScreen(TFT_BLACK);
    215.     tft.setFreeFont(FF18);                 // Select the font
    216.     tft.drawString(sFF28, 160, 60, GFXFF);// Print the string name of the font
    217.     tft.setFreeFont(FF28);
    218.     tft.drawString(TEXT, 160, 120, GFXFF);
    219.     delay(1000);

    220.     tft.fillScreen(TFT_BLACK);
    221.     tft.setFreeFont(FF18);                 // Select the font
    222.     tft.drawString(sFF29, 160, 60, GFXFF);// Print the string name of the font
    223.     tft.setFreeFont(FF29);
    224.     tft.drawString(TEXT, 160, 120, GFXFF);
    225.     delay(1000);
    226.     //tft.fillScreen(TFT_BLACK);
    227.     tft.setFreeFont(FF18);                 // Select the font
    228.     tft.drawString(sFF30, 160, 60, GFXFF);// Print the string name of the font
    229.     tft.setFreeFont(FF30);
    230.     tft.drawString(TEXT, 160, 120, GFXFF);
    231.     delay(1000);
    232.     //tft.fillScreen(TFT_BLACK);
    233.     tft.setFreeFont(FF18);                 // Select the font
    234.     tft.drawString(sFF31, 160, 60, GFXFF);// Print the string name of the font
    235.     tft.setFreeFont(FF31);
    236.     tft.drawString(TEXT, 160, 120, GFXFF);
    237.     delay(1000);
    238.     //tft.fillScreen(TFT_BLACK);
    239.     tft.setFreeFont(FF18);                 // Select the font
    240.     tft.drawString(sFF32, 160, 60, GFXFF);// Print the string name of the font
    241.     tft.setFreeFont(FF32);
    242.     tft.drawString(TEXT, 160, 120, GFXFF);
    243.     delay(1000);

    244.     tft.fillScreen(TFT_BLACK);
    245.     tft.setFreeFont(FF18);                 // Select the font
    246.     tft.drawString(sFF33, 160, 60, GFXFF);// Print the string name of the font
    247.     tft.setFreeFont(FF33);
    248.     tft.drawString(TEXT, 160, 120, GFXFF);
    249.     delay(1000);
    250.     //tft.fillScreen(TFT_BLACK);
    251.     tft.setFreeFont(FF18);                 // Select the font
    252.     tft.drawString(sFF34, 160, 60, GFXFF);// Print the string name of the font
    253.     tft.setFreeFont(FF34);
    254.     tft.drawString(TEXT, 160, 120, GFXFF);
    255.     delay(1000);
    256.     //tft.fillScreen(TFT_BLACK);
    257.     tft.setFreeFont(FF18);                 // Select the font
    258.     tft.drawString(sFF35, 160, 60, GFXFF);// Print the string name of the font
    259.     tft.setFreeFont(FF35);
    260.     tft.drawString(TEXT, 160, 120, GFXFF);
    261.     delay(1000);
    262.     //tft.fillScreen(TFT_BLACK);
    263.     tft.setFreeFont(FF18);                 // Select the font
    264.     tft.drawString(sFF36, 160, 60, GFXFF);// Print the string name of the font
    265.     tft.setFreeFont(FF36);
    266.     tft.drawString(TEXT, 160, 120, GFXFF);
    267.     delay(1000);

    268.     tft.fillScreen(TFT_BLACK);
    269.     tft.setFreeFont(FF18);                 // Select the font
    270.     tft.drawString(sFF37, 160, 60, GFXFF);// Print the string name of the font
    271.     tft.setFreeFont(FF37);
    272.     tft.drawString(TEXT, 160, 120, GFXFF);
    273.     delay(1000);
    274.     //tft.fillScreen(TFT_BLACK);
    275.     tft.setFreeFont(FF18);                 // Select the font
    276.     tft.drawString(sFF38, 160, 60, GFXFF);// Print the string name of the font
    277.     tft.setFreeFont(FF38);
    278.     tft.drawString(TEXT, 160, 120, GFXFF);
    279.     delay(1000);
    280.     //tft.fillScreen(TFT_BLACK);
    281.     tft.setFreeFont(FF18);                 // Select the font
    282.     tft.drawString(sFF39, 160, 60, GFXFF);// Print the string name of the font
    283.     tft.setFreeFont(FF39);
    284.     tft.drawString(TEXT, 160, 120, GFXFF);
    285.     delay(1000);
    286.     //tft.fillScreen(TFT_BLACK);
    287.     tft.setFreeFont(FF18);                 // Select the font
    288.     tft.drawString(sFF40, 160, 60, GFXFF);// Print the string name of the font
    289.     tft.setFreeFont(FF40);
    290.     tft.drawString(TEXT, 160, 120, GFXFF);
    291.     delay(1000);

    292.     tft.fillScreen(TFT_BLACK);
    293.     tft.setFreeFont(FF18);                 // Select the font
    294.     tft.drawString(sFF41, 160, 60, GFXFF);// Print the string name of the font
    295.     tft.setFreeFont(FF41);
    296.     tft.drawString(TEXT, 160, 120, GFXFF);
    297.     delay(1000);
    298.     //tft.fillScreen(TFT_BLACK);
    299.     tft.setFreeFont(FF18);                 // Select the font
    300.     tft.drawString(sFF42, 160, 60, GFXFF);// Print the string name of the font
    301.     tft.setFreeFont(FF42);
    302.     tft.drawString(TEXT, 160, 120, GFXFF);
    303.     delay(1000);
    304.     //tft.fillScreen(TFT_BLACK);
    305.     tft.setFreeFont(FF18);                 // Select the font
    306.     tft.drawString(sFF43, 160, 60, GFXFF);// Print the string name of the font
    307.     tft.setFreeFont(FF43);
    308.     tft.drawString(TEXT, 160, 120, GFXFF);
    309.     delay(1000);
    310.     //tft.fillScreen(TFT_BLACK);
    311.     tft.setFreeFont(FF18);                 // Select the font
    312.     tft.drawString(sFF44, 160, 60, GFXFF);// Print the string name of the font
    313.     tft.setFreeFont(FF44);
    314.     tft.drawString(TEXT, 160, 120, GFXFF);
    315.     delay(1000);

    316.     tft.fillScreen(TFT_BLACK);
    317.     tft.setFreeFont(FF18);                 // Select the font
    318.     tft.drawString(sFF45, 160, 60, GFXFF);// Print the string name of the font
    319.     tft.setFreeFont(FF45);
    320.     tft.drawString(TEXT, 160, 120, GFXFF);
    321.     delay(1000);
    322.     //tft.fillScreen(TFT_BLACK);
    323.     tft.setFreeFont(FF18);                 // Select the font
    324.     tft.drawString(sFF46, 160, 60, GFXFF);// Print the string name of the font
    325.     tft.setFreeFont(FF46);
    326.     tft.drawString(TEXT, 160, 120, GFXFF);
    327.     delay(1000);
    328.     //tft.fillScreen(TFT_BLACK);
    329.     tft.setFreeFont(FF18);                 // Select the font
    330.     tft.drawString(sFF47, 160, 60, GFXFF);// Print the string name of the font
    331.     tft.setFreeFont(FF47);
    332.     tft.drawString(TEXT, 160, 120, GFXFF);
    333.     delay(1000);
    334.     //tft.fillScreen(TFT_BLACK);
    335.     tft.setFreeFont(FF18);                 // Select the font
    336.     tft.drawString(sFF48, 160, 60, GFXFF);// Print the string name of the font
    337.     tft.setFreeFont(FF48);
    338.     tft.drawString(TEXT, 160, 120, GFXFF);
    339.     delay(1000);

    340. }

    341. // There follows a crude way of flagging that this example sketch needs fonts which
    342. // have not been enbabled in the User_Setup.h file inside the TFT_HX8357 library.
    343. //
    344. // These lines produce errors during compile time if settings in User_Setup are not correct
    345. //
    346. // The error will be "does not name a type" but ignore this and read the text between ''
    347. // it will indicate which font or feature needs to be enabled
    348. //
    349. // Either delete all the following lines if you do not want warnings, or change the lines
    350. // to suit your sketch modifications.

    351. #ifndef LOAD_GLCD
    352.     //ERROR_Please_enable_LOAD_GLCD_in_User_Setup
    353. #endif

    354. #ifndef LOAD_GFXFF
    355.     ERROR_Please_enable_LOAD_GFXFF_in_User_Setup!
    356. #endif
    复制代码

        二、编译上传程序

        003.png


        三、运行结果


        1001.gif

    回复

    使用道具 举报

    您需要登录后才可以回帖 注册/登录

    本版积分规则

    关闭

    站长推荐上一条 /4 下一条

    手机版|小黑屋|与非网

    GMT+8, 2024-11-19 12:30 , Processed in 0.125669 second(s), 16 queries , MemCache On.

    ICP经营许可证 苏B2-20140176  苏ICP备14012660号-2   苏州灵动帧格网络科技有限公司 版权所有.

    苏公网安备 32059002001037号

    Powered by Discuz! X3.4

    Copyright © 2001-2024, Tencent Cloud.