{"id":12284,"date":"2023-12-14T21:29:09","date_gmt":"2023-12-14T13:29:09","guid":{"rendered":"https:\/\/blog.iyatt.com\/?p=12284"},"modified":"2024-05-05T12:31:04","modified_gmt":"2024-05-05T04:31:04","slug":"arduino-%e4%bd%bf%e7%94%a8-tft-%e5%bd%a9%e5%b1%8f%ef%bc%88%e5%be%85%e5%86%99%ef%bc%89","status":"publish","type":"post","link":"https:\/\/blog.iyatt.com\/?p=12284","title":{"rendered":"Arduino \u4f7f\u7528 TFT \u5f69\u5c4f\uff08\u7f16\u8f91\u4e2d\uff09"},"content":{"rendered":"<div id=\"ez-toc-container\" class=\"ez-toc-v2_0_82_2 ez-toc-wrap-center counter-hierarchy ez-toc-counter ez-toc-light-blue ez-toc-container-direction\">\n<div class=\"ez-toc-title-container\">\n<p class=\"ez-toc-title ez-toc-toggle\" style=\"cursor:pointer\">\u76ee\u5f55<\/p>\n<span class=\"ez-toc-title-toggle\"><a href=\"#\" class=\"ez-toc-pull-right ez-toc-btn ez-toc-btn-xs ez-toc-btn-default ez-toc-toggle\" aria-label=\"Toggle Table of Content\"><span class=\"ez-toc-js-icon-con\"><span class=\"\"><span class=\"eztoc-hide\" style=\"display:none;\">Toggle<\/span><span class=\"ez-toc-icon-toggle-span\"><svg style=\"fill: #999;color:#999\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" class=\"list-377408\" width=\"20px\" height=\"20px\" viewBox=\"0 0 24 24\" fill=\"none\"><path d=\"M6 6H4v2h2V6zm14 0H8v2h12V6zM4 11h2v2H4v-2zm16 0H8v2h12v-2zM4 16h2v2H4v-2zm16 0H8v2h12v-2z\" fill=\"currentColor\"><\/path><\/svg><svg style=\"fill: #999;color:#999\" class=\"arrow-unsorted-368013\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"10px\" height=\"10px\" viewBox=\"0 0 24 24\" version=\"1.2\" baseProfile=\"tiny\"><path d=\"M18.2 9.3l-6.2-6.3-6.2 6.3c-.2.2-.3.4-.3.7s.1.5.3.7c.2.2.4.3.7.3h11c.3 0 .5-.1.7-.3.2-.2.3-.5.3-.7s-.1-.5-.3-.7zM5.8 14.7l6.2 6.3 6.2-6.3c.2-.2.3-.5.3-.7s-.1-.5-.3-.7c-.2-.2-.4-.3-.7-.3h-11c-.3 0-.5.1-.7.3-.2.2-.3.5-.3.7s.1.5.3.7z\"\/><\/svg><\/span><\/span><\/span><\/a><\/span><\/div>\n<nav><ul class='ez-toc-list ez-toc-list-level-1 ' ><li class='ez-toc-page-1 ez-toc-heading-level-1'><a class=\"ez-toc-link ez-toc-heading-1\" href=\"https:\/\/blog.iyatt.com\/?p=12284\/#1%E7%8E%AF%E5%A2%83\" >1\u73af\u5883<\/a><ul class='ez-toc-list-level-2' ><li class='ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-2\" href=\"https:\/\/blog.iyatt.com\/?p=12284\/#11_%E7%A1%AC%E4%BB%B6\" >1.1 \u786c\u4ef6<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-3\" href=\"https:\/\/blog.iyatt.com\/?p=12284\/#12_%E8%BD%AF%E4%BB%B6\" >1.2 \u8f6f\u4ef6<\/a><\/li><\/ul><\/li><li class='ez-toc-page-1 ez-toc-heading-level-1'><a class=\"ez-toc-link ez-toc-heading-4\" href=\"https:\/\/blog.iyatt.com\/?p=12284\/#2_%E5%9F%BA%E6%9C%AC%E6%98%BE%E7%A4%BA\" >2 \u57fa\u672c\u663e\u793a<\/a><ul class='ez-toc-list-level-2' ><li class='ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-5\" href=\"https:\/\/blog.iyatt.com\/?p=12284\/#21_%E7%BA%AF%E8%89%B2%E5%A1%AB%E5%85%85%E5%B1%8F%E5%B9%95\" >2.1 \u7eaf\u8272\u586b\u5145\u5c4f\u5e55<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-6\" href=\"https:\/\/blog.iyatt.com\/?p=12284\/#22_%E5%AD%97%E7%AC%A6%E4%B8%B2%E6%98%BE%E7%A4%BA\" >2.2 \u5b57\u7b26\u4e32\u663e\u793a<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-7\" href=\"https:\/\/blog.iyatt.com\/?p=12284\/#23_%E7%BB%98%E5%88%B6%E7%9B%B4%E7%BA%BF\" >2.3 \u7ed8\u5236\u76f4\u7ebf<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-8\" href=\"https:\/\/blog.iyatt.com\/?p=12284\/#24_%E7%BB%98%E5%88%B6%E5%87%A0%E4%BD%95%E5%9B%BE%E5%BD%A2\" >2.4 \u7ed8\u5236\u51e0\u4f55\u56fe\u5f62<\/a><ul class='ez-toc-list-level-3' ><li class='ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-9\" href=\"https:\/\/blog.iyatt.com\/?p=12284\/#241_%E7%BB%98%E5%88%B6%E7%9F%A9%E5%BD%A2\" >2.4.1 \u7ed8\u5236\u77e9\u5f62<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-10\" href=\"https:\/\/blog.iyatt.com\/?p=12284\/#242_%E7%BB%98%E5%88%B6%E5%9C%86%E5%BD%A2\" >2.4.2 \u7ed8\u5236\u5706\u5f62<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-11\" href=\"https:\/\/blog.iyatt.com\/?p=12284\/#243_%E7%BB%98%E5%88%B6%E4%B8%89%E8%A7%92%E5%BD%A2\" >2.4.3 \u7ed8\u5236\u4e09\u89d2\u5f62<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-12\" href=\"https:\/\/blog.iyatt.com\/?p=12284\/#244_%E7%BB%98%E5%88%B6%E5%9C%86%E8%A7%92%E7%9F%A9%E5%BD%A2\" >2.4.4 \u7ed8\u5236\u5706\u89d2\u77e9\u5f62<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-13\" href=\"https:\/\/blog.iyatt.com\/?p=12284\/#245_%E7%BB%98%E5%88%B6%E7%BB%84%E5%90%88%E5%9B%BE%E6%A1%88\" >2.4.5 \u7ed8\u5236\u7ec4\u5408\u56fe\u6848<\/a><\/li><\/ul><\/li><\/ul><\/li><\/ul><\/nav><\/div>\n<h1><span class=\"ez-toc-section\" id=\"1%E7%8E%AF%E5%A2%83\"><\/span>1\u73af\u5883<span class=\"ez-toc-section-end\"><\/span><\/h1>\n<h2><span class=\"ez-toc-section\" id=\"11_%E7%A1%AC%E4%BB%B6\"><\/span>1.1 \u786c\u4ef6<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p>Arduino UNO<br \/>\n1.8 \u5bf8 128&#215;160 RGB TFT\uff08ST7735\uff09<br \/>\n<img decoding=\"async\" data-src=\"https:\/\/blog.iyatt.com\/wp-content\/uploads\/2023\/12\/image-1702560223448.png\" alt=\"file\" src=\"data:image\/svg+xml;base64,PHN2ZyB3aWR0aD0iMSIgaGVpZ2h0PSIxIiB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciPjwvc3ZnPg==\" class=\"lazyload\" style=\"--smush-placeholder-width: 383px; --smush-placeholder-aspect-ratio: 383\/483;\" \/><\/p>\n<h2><span class=\"ez-toc-section\" id=\"12_%E8%BD%AF%E4%BB%B6\"><\/span>1.2 \u8f6f\u4ef6<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p>Arduino IDE 2.2.1<br \/>\nAdafruit ST7735 and ST7789 Library 1.10.3<\/p>\n<p>\u63a5\u7ebf\uff1a<\/p>\n<pre><code class=\"language-katex\">\\begin{array}{|l|l|}\n\\hline\nTFT &amp; Arduino \\\\\n\\hline\nSCL &amp; 13 \uff08\u786c\u4ef6 SPI - SCLK\uff09\\\\\nSDA &amp; 11 \uff08\u786c\u4ef6 SPI - MOSI\uff09\\\\\nRST &amp; 9 \\\\\nDC &amp; 8 \\\\\nCS &amp; 10 \\\\\nGND &amp; GND \\\\\nVCC &amp; 5V\uff083.3V \u4e0d\u80fd\u6b63\u5e38\u5de5\u4f5c\uff09\\\\\n\\hline\n\\end{array}<\/code><\/pre>\n<h1><span class=\"ez-toc-section\" id=\"2_%E5%9F%BA%E6%9C%AC%E6%98%BE%E7%A4%BA\"><\/span>2 \u57fa\u672c\u663e\u793a<span class=\"ez-toc-section-end\"><\/span><\/h1>\n<p>\u5173\u4e8e\u989c\u8272\u8f6c\u6362\u53c2\u8003\uff1a<a href=\"https:\/\/blog.iyatt.com\/?p=12867\">https:\/\/blog.iyatt.com\/?p=12867<\/a><br \/>\n2.1 \u662f\u5b8c\u5168\u4ee3\u7801\uff0c\u540e\u9762\u5f00\u59cb\u975e setup \u548c loop \u90e8\u5206\u90fd\u548c 2.1 \u4e00\u6837\uff0c\u76f4\u63a5\u7701\u7565\u3002<\/p>\n<h2><span class=\"ez-toc-section\" id=\"21_%E7%BA%AF%E8%89%B2%E5%A1%AB%E5%85%85%E5%B1%8F%E5%B9%95\"><\/span>2.1 \u7eaf\u8272\u586b\u5145\u5c4f\u5e55<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<pre><code class=\"language-cpp\">#include &lt;Adafruit_ST7735.h&gt;\n#include &lt;SPI.h&gt;\n\n#define CS      10\n#define RST     9\n#define DC      8\n\nAdafruit_ST7735 tft = Adafruit_ST7735(CS, DC, RST);\n\nuint16_t rgb888_to_565 (uint32_t rgb888, bool reverse = false)\n{\n    uint8_t r = (rgb888 &amp; 0xFF0000) &gt;&gt; 16;\n    uint8_t g = (rgb888 &amp; 0x00FF00) &gt;&gt; 8;\n    uint8_t b = (rgb888 &amp; 0x0000FF);\n\n    if (reverse)\n    {\n        return ((b &gt;&gt; 3) &lt;&lt; 11) |\n                ((g &gt;&gt; 2) &lt;&lt; 5) |\n                (r &gt;&gt; 3);\n    }\n\n    return ((r &gt;&gt; 3) &lt;&lt; 11) |\n            ((g &gt;&gt; 2) &lt;&lt; 5) |\n            (b &gt;&gt; 3);\n}\n\nuint16_t rgb888_to_565(uint8_t r, uint8_t g, uint8_t b, bool reverse = false)\n{\n    if (reverse)\n    {\n        return ((b &gt;&gt; 3) &lt;&lt; 11) |\n                ((g &gt;&gt; 2) &lt;&lt; 5) |\n                (r &gt;&gt; 3);\n    }\n\n    return ((r &gt;&gt; 3) &lt;&lt; 11) |\n            ((g &gt;&gt; 2) &lt;&lt; 5) |\n            (b &gt;&gt; 3);\n}\n\nvoid setup()\n{\n    tft.initR(INITR_GREENTAB); \/\/ \u521d\u59cb\u5316\n}\n\nvoid loop()\n{\n    \/\/ \u81ea\u5b9a\u4e49\u989c\u8272\n    tft.fillScreen(rgb888_to_565(255, 0, 255, true)); \/\/ \u7d2b\u8272\n    delay(500);\n    tft.fillScreen(rgb888_to_565(0xFFC0CB, true)); \/\/ \u7c89\u8272\n    delay(500);\n    tft.fillScreen(rgb888_to_565(255, 0, 0, true)); \/\/ \u7ea2\u8272\n    delay(500);\n}<\/code><\/pre>\n<p>\u53ef\u4ee5\u770b\u5230\u5404\u79cd\u989c\u8272\u8f6e\u756a\u95ea\u70c1<br \/>\n<img decoding=\"async\" data-src=\"https:\/\/blog.iyatt.com\/wp-content\/uploads\/2023\/12\/image-1704974977365.png\" alt=\"file\" src=\"data:image\/svg+xml;base64,PHN2ZyB3aWR0aD0iMSIgaGVpZ2h0PSIxIiB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciPjwvc3ZnPg==\" class=\"lazyload\" style=\"--smush-placeholder-width: 254px; --smush-placeholder-aspect-ratio: 254\/300;\" \/><br \/>\n<img decoding=\"async\" data-src=\"https:\/\/blog.iyatt.com\/wp-content\/uploads\/2023\/12\/image-1704974988835.png\" alt=\"file\" src=\"data:image\/svg+xml;base64,PHN2ZyB3aWR0aD0iMSIgaGVpZ2h0PSIxIiB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciPjwvc3ZnPg==\" class=\"lazyload\" style=\"--smush-placeholder-width: 259px; --smush-placeholder-aspect-ratio: 259\/352;\" \/><\/p>\n<h2><span class=\"ez-toc-section\" id=\"22_%E5%AD%97%E7%AC%A6%E4%B8%B2%E6%98%BE%E7%A4%BA\"><\/span>2.2 \u5b57\u7b26\u4e32\u663e\u793a<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<pre><code class=\"language-cpp\">void setup()\n{\n    tft.initR(INITR_GREENTAB); \/\/ \u521d\u59cb\u5316\n    tft.fillScreen(ST77XX_BLACK); \/\/ \u586b\u5145\u9ed1\u5c4f\n    delay(1000);\n\n    tft.setCursor(0, 0); \/\/ \u8bbe\u7f6e\u8d77\u59cb\u5149\u6807\u4f4d\u7f6e\n    tft.setTextColor(rgb888_to_565(0xFF0000, true)); \/\/ \u8bbe\u7f6e\u989c\u8272\n    tft.setTextWrap(true); \/\/ \u8bbe\u7f6e\u81ea\u52a8\u6362\u884c\n    tft.print(&quot;Lorem ipsum dolor sit amet, consectetur adipiscing elit. Curabitur adipiscing ante sed nibh tincidunt feugiat. Maecenas enim massa, fringilla sed malesuada et, malesuada sit amet turpis. Sed porttitor neque ut ante pretium vitae malesuada nunc bibendum. Nullam aliquet ultrices massa eu hendrerit. Ut sed nisi lorem. In vestibulum purus a tortor imperdiet posuere. &quot;);\n    \/\/ delay(2000);\n    tft.setTextWrap(false);\n}\n\nvoid loop()\n{\n    tft.fillScreen(ST77XX_BLACK);\n\n    tft.setCursor(0, 30);\n    tft.setTextSize(1);\n    tft.setTextColor(rgb888_to_565(0xE3CF57, true));\n    tft.println(&quot;hello world!&quot;);\n    delay(500);\n\n    tft.setTextColor(rgb888_to_565(0xFF00FF, true));\n    tft.setTextSize(2);\n    tft.println(&quot;hello world!&quot;);\n    delay(500);\n\n    tft.setTextColor(rgb888_to_565(0xFF8000, true));\n    tft.setTextSize(3);\n    tft.println(&quot;hello world!&quot;);\n    delay(500);\n}<\/code><\/pre>\n<p><img decoding=\"async\" data-src=\"https:\/\/blog.iyatt.com\/wp-content\/uploads\/2023\/12\/image-1704971055988.png\" alt=\"file\" src=\"data:image\/svg+xml;base64,PHN2ZyB3aWR0aD0iMSIgaGVpZ2h0PSIxIiB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciPjwvc3ZnPg==\" class=\"lazyload\" style=\"--smush-placeholder-width: 563px; --smush-placeholder-aspect-ratio: 563\/640;\" \/><br \/>\n<img decoding=\"async\" data-src=\"https:\/\/blog.iyatt.com\/wp-content\/uploads\/2023\/12\/image-1704978951005.png\" alt=\"file\" src=\"data:image\/svg+xml;base64,PHN2ZyB3aWR0aD0iMSIgaGVpZ2h0PSIxIiB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciPjwvc3ZnPg==\" class=\"lazyload\" style=\"--smush-placeholder-width: 355px; --smush-placeholder-aspect-ratio: 355\/428;\" \/><\/p>\n<h2><span class=\"ez-toc-section\" id=\"23_%E7%BB%98%E5%88%B6%E7%9B%B4%E7%BA%BF\"><\/span>2.3 \u7ed8\u5236\u76f4\u7ebf<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<pre><code class=\"language-cpp\">void setup()\n{\n    tft.initR(INITR_GREENTAB); \/\/ \u521d\u59cb\u5316\n    delay(1000);\n}\n\nvoid loop()\n{\n    uint16_t color = rgb888_to_565(255, 0, 0, true); \/\/ \u7ea2\u8272\n    tft.fillScreen(ST77XX_BLACK);\n    for (int16_t x=0; x &lt; tft.width(); x+=6)\n    {\n        tft.drawLine(0, 0, x, tft.height()-1, color);\n        delay(10);\n    }\n    for (int16_t y=0; y &lt; tft.height(); y+=6)\n    {\n        tft.drawLine(0, 0, tft.width()-1, y, color);\n        delay(10);\n    }\n\n    color = rgb888_to_565(0, 255, 0, true); \/\/ \u7eff\u8272\n    tft.fillScreen(ST77XX_BLACK);\n    for (int16_t x=0; x &lt; tft.width(); x+=6)\n    {\n        tft.drawLine(tft.width()-1, 0, x, tft.height()-1, color);\n        delay(10);\n    }\n    for (int16_t y=0; y &lt; tft.height(); y+=6)\n    {\n        tft.drawLine(tft.width()-1, 0, 0, y, color);\n        delay(10);\n    }\n\n    color = rgb888_to_565(0, 0, 255, true); \/\/ \u84dd\u8272\n    tft.fillScreen(ST77XX_BLACK);\n    for (int16_t x=0; x &lt; tft.width(); x+=6)\n    {\n        tft.drawLine(0, tft.height()-1, x, 0, color);\n        delay(10);\n    }\n    for (int16_t y=0; y &lt; tft.height(); y+=6)\n    {\n        tft.drawLine(0, tft.height()-1, tft.width()-1, y, color);\n        delay(10);\n    }\n\n    color = rgb888_to_565(255, 0, 255, true); \/\/ \u7d2b\u8272\n    tft.fillScreen(ST77XX_BLACK);\n    for (int16_t x=0; x &lt; tft.width(); x+=6)\n    {\n        tft.drawLine(tft.width()-1, tft.height()-1, x, 0, color);\n        delay(10);\n    }\n    for (int16_t y=0; y &lt; tft.height(); y+=6)\n    {\n        tft.drawLine(tft.width()-1, tft.height()-1, 0, y, color);\n        delay(10);\n    }\n}<\/code><\/pre>\n<p><img decoding=\"async\" data-src=\"https:\/\/blog.iyatt.com\/wp-content\/uploads\/2023\/12\/image-1704979535482.png\" alt=\"file\" src=\"data:image\/svg+xml;base64,PHN2ZyB3aWR0aD0iMSIgaGVpZ2h0PSIxIiB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciPjwvc3ZnPg==\" class=\"lazyload\" style=\"--smush-placeholder-width: 338px; --smush-placeholder-aspect-ratio: 338\/437;\" \/><br \/>\n<img decoding=\"async\" data-src=\"https:\/\/blog.iyatt.com\/wp-content\/uploads\/2023\/12\/image-1704979544641.png\" alt=\"file\" src=\"data:image\/svg+xml;base64,PHN2ZyB3aWR0aD0iMSIgaGVpZ2h0PSIxIiB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciPjwvc3ZnPg==\" class=\"lazyload\" style=\"--smush-placeholder-width: 360px; --smush-placeholder-aspect-ratio: 360\/457;\" \/><br \/>\n<img decoding=\"async\" data-src=\"https:\/\/blog.iyatt.com\/wp-content\/uploads\/2023\/12\/image-1704979553241.png\" alt=\"file\" src=\"data:image\/svg+xml;base64,PHN2ZyB3aWR0aD0iMSIgaGVpZ2h0PSIxIiB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciPjwvc3ZnPg==\" class=\"lazyload\" style=\"--smush-placeholder-width: 314px; --smush-placeholder-aspect-ratio: 314\/430;\" \/><\/p>\n<p>\u6c34\u5e73\u7ebf\u548c\u5782\u76f4\u7ebf<\/p>\n<pre><code class=\"language-cpp\">void setup()\n{\n    tft.initR(INITR_GREENTAB); \/\/ \u521d\u59cb\u5316\n    delay(1000);\n}\n\nvoid loop()\n{\n    static uint16_t color1 = rgb888_to_565(255, 0, 0, true);\n    static uint16_t color2 = rgb888_to_565(0, 0, 255);\n    tft.fillScreen(ST77XX_BLACK);\n    for (int16_t y=0; y &lt; tft.height(); y+=5)\n    {\n        tft.drawFastHLine(0, y, tft.width(), color1);\n        delay(30);\n    }\n    for (int16_t x=0; x &lt; tft.width(); x+=5)\n    {\n        tft.drawFastVLine(x, 0, tft.height(), color2);\n        delay(30);\n    }\n}<\/code><\/pre>\n<p><img decoding=\"async\" data-src=\"https:\/\/blog.iyatt.com\/wp-content\/uploads\/2023\/12\/image-1704979847916.png\" alt=\"file\" src=\"data:image\/svg+xml;base64,PHN2ZyB3aWR0aD0iMSIgaGVpZ2h0PSIxIiB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciPjwvc3ZnPg==\" class=\"lazyload\" style=\"--smush-placeholder-width: 338px; --smush-placeholder-aspect-ratio: 338\/443;\" \/><br \/>\n<img decoding=\"async\" data-src=\"https:\/\/blog.iyatt.com\/wp-content\/uploads\/2023\/12\/image-1704979856953.png\" alt=\"file\" src=\"data:image\/svg+xml;base64,PHN2ZyB3aWR0aD0iMSIgaGVpZ2h0PSIxIiB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciPjwvc3ZnPg==\" class=\"lazyload\" style=\"--smush-placeholder-width: 380px; --smush-placeholder-aspect-ratio: 380\/515;\" \/><\/p>\n<h2><span class=\"ez-toc-section\" id=\"24_%E7%BB%98%E5%88%B6%E5%87%A0%E4%BD%95%E5%9B%BE%E5%BD%A2\"><\/span>2.4 \u7ed8\u5236\u51e0\u4f55\u56fe\u5f62<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<h3><span class=\"ez-toc-section\" id=\"241_%E7%BB%98%E5%88%B6%E7%9F%A9%E5%BD%A2\"><\/span>2.4.1 \u7ed8\u5236\u77e9\u5f62<span class=\"ez-toc-section-end\"><\/span><\/h3>\n<pre><code class=\"language-cpp\">void setup()\n{\n    tft.initR(INITR_GREENTAB); \/\/ \u521d\u59cb\u5316\n    delay(1000);\n}\n\nvoid loop()\n{\n    static uint16_t color1 = rgb888_to_565(255, 0, 0, true);\n    static uint16_t color2 = rgb888_to_565(0, 0, 255, true);\n    tft.fillScreen(ST77XX_BLACK);\n    for (int16_t x=tft.width()-1; x &gt; 6; x-=6)\n    {\n        tft.fillRect(tft.width()\/2 -x\/2, tft.height()\/2 -x\/2 , x, x, color1); \/\/ \u5b9e\u5fc3\n        tft.drawRect(tft.width()\/2 -x\/2, tft.height()\/2 -x\/2 , x, x, color2); \/\/ \u8fb9\u6846\n        delay(50);\n    }\n}<\/code><\/pre>\n<p><img decoding=\"async\" data-src=\"https:\/\/blog.iyatt.com\/wp-content\/uploads\/2023\/12\/image-1704980368956.png\" alt=\"file\" src=\"data:image\/svg+xml;base64,PHN2ZyB3aWR0aD0iMSIgaGVpZ2h0PSIxIiB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciPjwvc3ZnPg==\" class=\"lazyload\" style=\"--smush-placeholder-width: 292px; --smush-placeholder-aspect-ratio: 292\/345;\" \/><br \/>\n<img decoding=\"async\" data-src=\"https:\/\/blog.iyatt.com\/wp-content\/uploads\/2023\/12\/image-1704980381834.png\" alt=\"file\" src=\"data:image\/svg+xml;base64,PHN2ZyB3aWR0aD0iMSIgaGVpZ2h0PSIxIiB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciPjwvc3ZnPg==\" class=\"lazyload\" style=\"--smush-placeholder-width: 321px; --smush-placeholder-aspect-ratio: 321\/371;\" \/><\/p>\n<h3><span class=\"ez-toc-section\" id=\"242_%E7%BB%98%E5%88%B6%E5%9C%86%E5%BD%A2\"><\/span>2.4.2 \u7ed8\u5236\u5706\u5f62<span class=\"ez-toc-section-end\"><\/span><\/h3>\n<pre><code class=\"language-cpp\">void setup()\n{\n    tft.initR(INITR_GREENTAB); \/\/ \u521d\u59cb\u5316\n    delay(1000);\n}\n\nvoid loop()\n{\n    static uint16_t color1 = rgb888_to_565(255, 0, 0, true);\n    static uint16_t color2 = rgb888_to_565(0, 0, 255, true);\n    static uint8_t radius = 30;\n    tft.fillScreen(ST77XX_BLACK);\n    for (int16_t x=0; x &lt; tft.width()+radius; x+=radius*2)\n    {\n        for (int16_t y=0; y &lt; tft.height()+radius; y+=radius*2)\n        {\n            tft.fillCircle(x, y, radius, color1);\n            tft.drawCircle(x, y, radius, color2);\n            delay(50);\n        }\n    }\n}<\/code><\/pre>\n<p><img decoding=\"async\" data-src=\"https:\/\/blog.iyatt.com\/wp-content\/uploads\/2023\/12\/image-1704980751503.png\" alt=\"file\" src=\"data:image\/svg+xml;base64,PHN2ZyB3aWR0aD0iMSIgaGVpZ2h0PSIxIiB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciPjwvc3ZnPg==\" class=\"lazyload\" style=\"--smush-placeholder-width: 307px; --smush-placeholder-aspect-ratio: 307\/410;\" \/><br \/>\n<img decoding=\"async\" data-src=\"https:\/\/blog.iyatt.com\/wp-content\/uploads\/2023\/12\/image-1704980759632.png\" alt=\"file\" src=\"data:image\/svg+xml;base64,PHN2ZyB3aWR0aD0iMSIgaGVpZ2h0PSIxIiB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciPjwvc3ZnPg==\" class=\"lazyload\" style=\"--smush-placeholder-width: 367px; --smush-placeholder-aspect-ratio: 367\/465;\" \/><\/p>\n<h3><span class=\"ez-toc-section\" id=\"243_%E7%BB%98%E5%88%B6%E4%B8%89%E8%A7%92%E5%BD%A2\"><\/span>2.4.3 \u7ed8\u5236\u4e09\u89d2\u5f62<span class=\"ez-toc-section-end\"><\/span><\/h3>\n<pre><code class=\"language-cpp\">void setup()\n{\n    tft.initR(INITR_GREENTAB); \/\/ \u521d\u59cb\u5316\n    delay(1000);\n}\n\nvoid loop()\n{\n    uint16_t color = rgb888_to_565(0, 0, 0, true);\n    tft.fillScreen(ST77XX_BLACK);\n    int w = tft.width() \/ 2;\n    int x = tft.height() - 1;\n    int y = 0;\n    int z = tft.width();\n    for(int t = 0 ; t &lt;= 15; t++)\n    {\n        tft.drawTriangle(w, y, y, x, z, x, color);\n        x-=4;\n        y+=4;\n        z-=4;\n        color+=100;\n        delay(100);\n    }\n}<\/code><\/pre>\n<p><img decoding=\"async\" data-src=\"https:\/\/blog.iyatt.com\/wp-content\/uploads\/2023\/12\/image-1704981234269.png\" alt=\"file\" src=\"data:image\/svg+xml;base64,PHN2ZyB3aWR0aD0iMSIgaGVpZ2h0PSIxIiB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciPjwvc3ZnPg==\" class=\"lazyload\" style=\"--smush-placeholder-width: 256px; --smush-placeholder-aspect-ratio: 256\/317;\" \/><br \/>\n<img decoding=\"async\" data-src=\"https:\/\/blog.iyatt.com\/wp-content\/uploads\/2023\/12\/image-1704981242740.png\" alt=\"file\" src=\"data:image\/svg+xml;base64,PHN2ZyB3aWR0aD0iMSIgaGVpZ2h0PSIxIiB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciPjwvc3ZnPg==\" class=\"lazyload\" style=\"--smush-placeholder-width: 323px; --smush-placeholder-aspect-ratio: 323\/417;\" \/><\/p>\n<h3><span class=\"ez-toc-section\" id=\"244_%E7%BB%98%E5%88%B6%E5%9C%86%E8%A7%92%E7%9F%A9%E5%BD%A2\"><\/span>2.4.4 \u7ed8\u5236\u5706\u89d2\u77e9\u5f62<span class=\"ez-toc-section-end\"><\/span><\/h3>\n<pre><code class=\"language-cpp\">void setup()\n{\n    tft.initR(INITR_GREENTAB); \/\/ \u521d\u59cb\u5316\n    delay(1000);\n}\n\nvoid loop()\n{\n    uint16_t color = rgb888_to_565(0, 0, 0, true);\n    tft.fillScreen(ST77XX_BLACK);\n    for(int t = 0 ; t &lt;= 4; t+=1)\n    {\n        int x = 0;\n        int y = 0;\n        int w = tft.width()-2;\n        int h = tft.height()-2;\n        for(int i = 0 ; i &lt;= 16; i+=1)\n        {\n            tft.drawRoundRect(x, y, w, h, 5, color);\n            x+=2;\n            y+=3;\n            w-=4;\n            h-=6;\n            color+=1100;\n            delay(50);\n        }\n        color += 100;\n    }\n}<\/code><\/pre>\n<p><img decoding=\"async\" data-src=\"https:\/\/blog.iyatt.com\/wp-content\/uploads\/2023\/12\/image-1704981312492.png\" alt=\"file\" src=\"data:image\/svg+xml;base64,PHN2ZyB3aWR0aD0iMSIgaGVpZ2h0PSIxIiB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciPjwvc3ZnPg==\" class=\"lazyload\" style=\"--smush-placeholder-width: 310px; --smush-placeholder-aspect-ratio: 310\/407;\" \/><br \/>\n<img decoding=\"async\" data-src=\"https:\/\/blog.iyatt.com\/wp-content\/uploads\/2023\/12\/image-1704981320248.png\" alt=\"file\" src=\"data:image\/svg+xml;base64,PHN2ZyB3aWR0aD0iMSIgaGVpZ2h0PSIxIiB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciPjwvc3ZnPg==\" class=\"lazyload\" style=\"--smush-placeholder-width: 295px; --smush-placeholder-aspect-ratio: 295\/386;\" \/><\/p>\n<h3><span class=\"ez-toc-section\" id=\"245_%E7%BB%98%E5%88%B6%E7%BB%84%E5%90%88%E5%9B%BE%E6%A1%88\"><\/span>2.4.5 \u7ed8\u5236\u7ec4\u5408\u56fe\u6848<span class=\"ez-toc-section-end\"><\/span><\/h3>\n<pre><code class=\"language-cpp\">void setup()\n{\n    tft.initR(INITR_GREENTAB); \/\/ \u521d\u59cb\u5316\n    delay(1000);\n}\n\nvoid loop()\n{\n    tft.fillScreen(ST77XX_BLACK);\n    tft.fillRoundRect(25, 10, 78, 60, 8, ST77XX_WHITE);\n    tft.fillTriangle(42, 20, 42, 60, 90, 40, rgb888_to_565(0xFF0000, true));\n    delay(500);\n\n    tft.fillRoundRect(25, 90, 78, 60, 8, ST77XX_WHITE);\n    tft.fillRoundRect(39, 98, 20, 45, 5, rgb888_to_565(0x00FF00, true));\n    tft.fillRoundRect(69, 98, 20, 45, 5, rgb888_to_565(0x00FF00, true));\n    delay(500);\n\n    tft.fillTriangle(42, 20, 42, 60, 90, 40, rgb888_to_565(0x0000FF, true));\n    delay(50);\n\n    tft.fillRoundRect(39, 98, 20, 45, 5, rgb888_to_565(0xFF0000, true));\n    tft.fillRoundRect(69, 98, 20, 45, 5, rgb888_to_565(0xFF0000, true));\n\n    tft.fillTriangle(42, 20, 42, 60, 90, 40, rgb888_to_565(0x00FF00, true));\n}<\/code><\/pre>\n<p><img decoding=\"async\" data-src=\"https:\/\/blog.iyatt.com\/wp-content\/uploads\/2023\/12\/image-1704981683845.png\" alt=\"file\" src=\"data:image\/svg+xml;base64,PHN2ZyB3aWR0aD0iMSIgaGVpZ2h0PSIxIiB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciPjwvc3ZnPg==\" class=\"lazyload\" style=\"--smush-placeholder-width: 328px; --smush-placeholder-aspect-ratio: 328\/414;\" \/><\/p>\n","protected":false},"excerpt":{"rendered":"<p>1\u73af\u5883 1.1 \u786c\u4ef6 Arduino UNO 1.8 \u5bf8 128&#215;160 RGB TFT\uff08ST773 [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"zakra_page_container_layout":"customizer","zakra_page_sidebar_layout":"customizer","zakra_remove_content_margin":false,"zakra_sidebar":"customizer","zakra_transparent_header":"customizer","zakra_logo":0,"zakra_main_header_style":"default","zakra_menu_item_color":"","zakra_menu_item_hover_color":"","zakra_menu_item_active_color":"","zakra_menu_active_style":"","zakra_page_header":true,"_lmt_disableupdate":"no","_lmt_disable":"no","footnotes":""},"categories":[1],"tags":[],"class_list":["post-12284","post","type-post","status-publish","format-standard","hentry","category-all"],"modified_by":"IYATT-yx","_links":{"self":[{"href":"https:\/\/blog.iyatt.com\/index.php?rest_route=\/wp\/v2\/posts\/12284","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/blog.iyatt.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog.iyatt.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog.iyatt.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.iyatt.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=12284"}],"version-history":[{"count":0,"href":"https:\/\/blog.iyatt.com\/index.php?rest_route=\/wp\/v2\/posts\/12284\/revisions"}],"wp:attachment":[{"href":"https:\/\/blog.iyatt.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=12284"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.iyatt.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=12284"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.iyatt.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=12284"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}