{"id":120,"date":"2022-07-13T22:20:45","date_gmt":"2022-07-13T14:20:45","guid":{"rendered":"http:\/\/www.zhangxiaohei.cn\/?p=120"},"modified":"2022-07-13T22:20:45","modified_gmt":"2022-07-13T14:20:45","slug":"nodemcu-%e4%b9%8b-u8g2-%e5%ba%93%e4%bd%bf%e7%94%a8%e8%af%a6%e8%a7%a32","status":"publish","type":"post","link":"http:\/\/www.zhangxiaohei.cn\/?p=120","title":{"rendered":"NodeMCU \u4e4b U8G2 \u5e93\u4f7f\u7528\u8be6\u89e3"},"content":{"rendered":"\n<p><\/p>\n\n\n\n<p><\/p>\n\n\n\n<p><a href=\"https:\/\/github.com\/olikraus\/u8g2\/wiki\/fntlist12\">https:\/\/github.com\/olikraus\/u8g2\/wiki\/fntlist12<\/a><\/p>\n\n\n\n<p>\u7801\u4e91 U8G2\u5b57\u4f53\u67e5\u627e\u5730\u5740\uff1a<a href=\"https:\/\/gitee.com\/penjun71\/u8g2\/wikis\/fntlistallplain\" data-type=\"URL\" data-id=\"https:\/\/gitee.com\/penjun71\/u8g2\/wikis\/fntlistallplain\">https:\/\/gitee.com\/penjun71\/u8g2\/wikis\/fntlistallplain<\/a>  <\/p>\n\n\n\n<h3 class=\"wp-block-heading\">1.\u6307\u4ee4<\/h3>\n\n\n\n<pre class=\"wp-block-preformatted\">1 u8g2.clearDisplay();    \/\/ \u6e05\u9664\u663e\u793a\u6570\u636e\u53ca\u5c4f\u5e55\n2 u8g2.clearBuffer();    \/\/ \u6e05Buffer\u7f13\u51b2\u533a\u7684\u6570\u636e\n3 u8g2.sendBuffer();    \/\/ \u5c06Buffer\u5e27\u7f13\u51b2\u533a\u7684\u5185\u5bb9\u53d1\u9001\u5230\u663e\u793a\u5668,\u53d1\u9001\u5237\u65b0\u6d88\u606f\n4 u8g2.sendF(\"c\", 0x0a7);    \/\/ \u5411\u663e\u793a\u63a7\u5236\u5668\u53d1\u9001\u7279\u6b8a\u547d\u4ee4\n5 u8g2.setPowerSave(0)    \/\/ \u5f00\u5173\u7701\u7535\u6a21\u5f0f<\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">2.\u8bbe\u7f6e<\/h3>\n\n\n\n<pre class=\"wp-block-preformatted\">1 u8g2.enableUTF8Print();    \/\/\u8bbe\u7f6e\u542f\u7528UTF-8\u652f\u6301\n2 u8g2.disableUTF8Print();    \/\/\u8bbe\u7f6e\u505c\u7528UTF-8\u652f\u6301\n3 u8g2.setContrast();    \/\/\u8bbe\u7f6e\u663e\u793a\u5c4f\u4eae\u5ea6\/\u5bf9\u6bd4\u5ea6(0-255)\n4 u8g2.setBusClock();    \/\/\u8bbe\u7f6e\u8fde\u63a5\u901f\u5ea6(IIC:200000-400000\/SPI:1000000-8000000),\u5728begin()\u4e4b\u524d\u8c03\u7528<\/pre>\n\n\n\n<p><strong>2.1\u8bbe\u7f6e\u5b57\u4f53:<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">1 u8g2.setFontMode(0);    \/\/\u5b9a\u4e49\u5b57\u4f53\u80cc\u666f\u6a21\u5f0f,\u4ec5u8g2_xxx_tX\u5b57\u4f53\u652f\u6301,\u9ed8\u8ba40,\u7981\u7528\u900f\u660e\n2 u8g2.setFontDirection(0); \/\/\u65cb\u8f6c\u5f53\u524d\u663e\u793a \u53c2\u6570:0123\n3 u8g2.setFont(u8g2_font_unifont_t_chinese1);    \/\/\u8bbe\u7f6e\u5b57\u4f53\n4 u8g2.setFontPosCenter();    \/\/\u8bbe\u7f6e\u5b57\u4f53\u57fa\u7ebfCenter\/Baseline\/Bottom\/Top<\/pre>\n\n\n\n<p><strong>2.2\u8bbe\u7f6e\u989c\u8272:<\/strong><br>&nbsp;1&nbsp;u8g2.setDrawColor(1);&nbsp;\/\/\u8bbe\u7f6e\u989c\u8272,0\u900f\u663e,1\u5b9e\u663e,2XOR (drawCircle,drawDisc,drawEllipse\u548cdrawFilledEllipse\u4e0d\u652f\u6301XOR\u6a21\u5f0f)&nbsp;<\/p>\n\n\n\n<h4 class=\"wp-block-heading\">2.3\u8bbe\u7f6e\u5149\u6807\u4f4d\u7f6e:<\/h4>\n\n\n\n<pre class=\"wp-block-preformatted\">1 u8g2.home();    \/\/\u8bbe\u7f6e\u5149\u6807\u56de\u521d\u59cb\u4f4d\u7f6e\n2 u8g2.setCursor(x, y); \/\/\u8bbe\u7f6e\u6253\u5370\u529f\u80fd\u7684\u5149\u6807\u4f4d\u7f6e\n3 u8g2.setBitmapMode(0);    \/\/\u8bbe\u7f6e\u662f\u5426\u5f00\u542f\u4f4d\u56fe\u51fd\u6570\u80cc\u666f\u8272<\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">3.\u7b80\u5355\u7ed8\u5236<\/h3>\n\n\n\n<pre class=\"wp-block-preformatted\">1 u8g2.drawStr(x, y, \"\u6587\u672c\"); \/\/ \u7ed8\u5236\u6587\u672c\u5b57\u7b26,\u4e0d\u80fd\u7ed8\u5236\u7f16\u7801\u5927\u4e8e\u6216\u7b49\u4e8e256,\u7ed8\u5236\u6587\u672c\u524d\u9700\u5b9a\u4e49\u5b57\u4f53.y\u8f74\u5411\u4e0a\u7ed8\u5236\n2 u8g2.drawUTF8(x, y,\"\u5b57\u7b26\");    \/\/ \u7ed8\u5236\u4e00\u4e2a\u7f16\u7801\u4e3aUTF-8\u7684\u5b57\u7b26\u4e32.\u6ce8\u610f1.\u7f16\u8bd1\u5668\u652f\u63012.\u4ee3\u7801\u7f16\u8f91\u5668\u652f\u6301\n3 u8g2.drawGlyph(x, y, HEX);    \/\/ \u7ed8\u5236\u7279\u6b8a\u6587\u672c\u56fe\u6807(\u9700\u8054\u5408\u7279\u6b8a\u5b57\u4f53)\n4 u8g2.print();    \/\/ \u6253\u5370\u6587\u672c\u5b57\u7b26(\u9700\u8981\u8054\u5408\u5149\u6807\u4f4d\u7f6esetCursor,setFont)\u652f\u6301\u53d8\u91cf\u548cF()<\/pre>\n\n\n\n<p>4.\u9ad8\u7ea7\u7ed8\u5236<\/p>\n\n\n\n<h4 class=\"wp-block-heading\">4.0.\u7ed8\u5236\u70b9<\/h4>\n\n\n\n<p>&nbsp;1&nbsp;u8g2.drawPixel(x, y);&nbsp;\/\/&nbsp;\u5728xy\u4f4d\u7f6e\u7ed8\u5236\u4e00\u4e2a\u50cf\u7d20.&nbsp;<\/p>\n\n\n\n<p><br><strong>4.1.\u7ed8\u5236\u7ebf\u6761<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">1 u8g2.drawHLine(x, y, w); \/\/ \u7ed8\u5236\u6c34\u5e73\u7ebf w\u957f\u5ea6\n2 u8g2.drawVLine(x, y, h);    \/\/ \u7ed8\u5236\u5782\u76f4\u7ebf h\u9ad8\u5ea6\n3 u8g2.drawLine(x1, y1, x2, y2);    \/\/ \u753b\u81ea\u7531\u7ebf x1y1\u70b91 x2y2\u70b92<\/pre>\n\n\n\n<h4 class=\"wp-block-heading\">4.2.\u7ed8\u5236\u77e9\u5f62<\/h4>\n\n\n\n<p>&nbsp;1&nbsp;u8g2.drawBox(x, y, w, h);&nbsp;\/\/&nbsp;\u753b\u586b\u5145\u77e9\u5f62w,h,\u5bbd\u5ea6,\u9ad8\u5ea6&nbsp;2&nbsp;u8g2.drawFrame(x, y, w, h);&nbsp;\/\/&nbsp;\u753b\u7a7a\u5fc3\u77e9\u5f62w,h,\u5bbd\u5ea6,\u9ad8\u5ea6&nbsp;<br>4.2.1.\u7ed8\u5236\u5706\u89d2\u77e9\u5f62&nbsp;<\/p>\n\n\n\n<p>1&nbsp;u8g2.drawRFrame(x,y,w,h,r);&nbsp;\/\/\u8981\u6c42w &gt;= 2*(r+1);h &gt;= 2*(r+1);\u5426\u5219\u672a\u5b9a\u4e492*(r+1)&nbsp;<br><strong>4.3. \u7ed8\u5236\u5706\u5f62<\/strong><\/p>\n\n\n\n<h4 class=\"wp-block-heading\">4.3.1.\u753b\u6b63\/\u692d\u5706<\/h4>\n\n\n\n<pre class=\"wp-block-preformatted\">1 u8g2.drawCircle(\u5706\u5fc3x, \u5706\u5fc3y, \u534a\u5f84rad, \u90e8\u5206\u4f4d\u7f6eU8G2_DRAW_ALL);    \/\/ \u753b\u7a7a\u5fc3\u5706 rad\u534a\u5f84 \u76f4\u5f84\u4e3a 2rad+1\n2 u8g2.drawEllipse(\u5706\u5fc3x, \u5706\u5fc3y, \u692d\u5706\u957f\u5ea6x, \u692d\u5706\u5bbd\u5ea6y, \u90e8\u5206\u4f4d\u7f6eU8G2_DRAW_ALL)    \/\/\u753b\u7a7a\u5fc3\u692d\u5706 \u957f\u5ea6\u548c\u5bbd\u5ea6\u5747\u4e3a\u6574\u4e2a\u5706\u76841\/2\n3 U8G2_DRAW_ALL    \/*\u66ff\u6362\u53c2\u6570: \n4 U8G2_DRAW_ALL \u5168\u90e8\n5 U8G2_DRAW_UPPER_RIGHT \u4e0a\u53f3\n6 U8G2_DRAW_UPPER_LEFT \u4e0a\u5de6\n7 U8G2_DRAW_LOWER_RIGHT \u4e0b\u53f3\n8 U8G2_DRAW_LOWER_LEFT \u4e0b\u5de6*\/<\/pre>\n\n\n\n<p><strong>4.4.\u7ed8\u5236\u591a\u8fb9\u5f62<\/strong><br>&nbsp;1&nbsp;u8g2.drawTriangle(x1,y1,x2,y2,x3,y3);&nbsp;\/\/\u4e09\u4e2a\u70b9\u7684\u5750\u6807,\u5b9e\u5fc3&nbsp;<br><strong>4.5.\u7ed8\u5236\u4f4d\u56fe\u56fe\u50cf<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">1 u8g2.drawXBM( x, y, w, h, bits);    \/\/bits\u662f\u4f4d\u56fe\u8d44\u6e90\u8868,setBitmapMode(1)\u5207\u6362\u4e3a\u65e7\u6a21\u5f0f<\/pre>\n\n\n\n<p><strong>5.\u7ed8\u5236\u5904\u7406<\/strong><br><strong>5.1.\u6307\u5b9a\u533a\u57df\u7ed8\u5236<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">1 u8g2.setClipWindow(x1, y1, x2, y2);    \/\/\u4ece1\u52302\u5f62\u6210\u53ef\u89c6\u77e9\u5f62,\u77e9\u5f62\u5185\u90e8\u53ef\u89c6,\u5916\u90e8\u906e\u76d6\n2 u8g2.updateDisplay();    \/\/\u5237\u65b0\u5168\u90e8\u663e\u793a\u533a\u57df\n3 u8g2.updateDisplayArea(x, y, w, h);    \/\/\u5237\u65b0\u6307\u5b9a\u533a\u57df\u663e\u793a \u63a8\u8350sendBuffer<\/pre>\n\n\n\n<p><strong>6.\u6309\u952e\u529f\u80fd\u5904\u7406<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">1 u8g2.userInterfaceInputValue(\"\u6807\u9898\",\"\u63d0\u793a\u6587\u672c\",\u503c,\u6700\u4f4e\u503c,\u6700\u9ad8\u503c,\u503c\u7684\u4f4d\u6570,\"\u6587\u672c\")    \/\/\u6309\u952e\u6d88\u606f\u83dc\u5355\n2 u8g2.userInterfaceMessage(\"Title1\", \"Title2\", \"Title3\", \" Ok \\n Cancel \");    \/\/\u6309\u952e\u786e\u8ba4\u83dc\u5355\n3 u8g2.userInterfaceSelectionList(\"Title\", \u9ed8\u8ba4\u9009\u62e9\u9879, \"Select1\\Select2\\Select3\");    \/\/\u6309\u952e\u9009\u62e9\u83dc\u5355<\/pre>\n\n\n\n<p><strong>7.\u9ad8\u7ea7API\u64cd\u4f5c<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">u8g2.getBufferSize    \/\/\u8fd4\u56de\u9875\u9762\u7f13\u51b2\u533a\u7684\u5927\u5c0f,\u7b49\u4e8e8*u8g2.getBufferTileHeight*u8g2.getBufferTileWidth\nu8g2.setBufferPtr(buf);    \/\/\u6307\u5411\u5185\u90e8\u9875\u9762\u7f13\u51b2\u533a\u5f00\u59cb\u4f4d\u7684\u6307\u9488<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>https:\/\/github.com\/olikraus\/u8g2\/wiki\/fntlist12 \u7801\u4e91 U8G2<\/p><\/div>\n<div class=\"blog-btn\"><a href=\"http:\/\/www.zhangxiaohei.cn\/?p=120\" class=\"home-blog-btn\">\u9605\u8bfb\u66f4\u591a<\/a><\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[6],"tags":[],"class_list":["post-120","post","type-post","status-publish","format-standard","hentry","category-arduino"],"_links":{"self":[{"href":"http:\/\/www.zhangxiaohei.cn\/index.php?rest_route=\/wp\/v2\/posts\/120","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/www.zhangxiaohei.cn\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/www.zhangxiaohei.cn\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/www.zhangxiaohei.cn\/index.php?rest_route=\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"http:\/\/www.zhangxiaohei.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=120"}],"version-history":[{"count":0,"href":"http:\/\/www.zhangxiaohei.cn\/index.php?rest_route=\/wp\/v2\/posts\/120\/revisions"}],"wp:attachment":[{"href":"http:\/\/www.zhangxiaohei.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=120"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/www.zhangxiaohei.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=120"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/www.zhangxiaohei.cn\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=120"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}