{"id":2526,"date":"2023-08-05T11:57:11","date_gmt":"2023-08-05T03:57:11","guid":{"rendered":"https:\/\/104.es\/?p=2526"},"modified":"2023-08-05T11:57:11","modified_gmt":"2023-08-05T03:57:11","slug":"microbitmicropython-servo","status":"publish","type":"post","link":"https:\/\/104.es\/index.php\/2023\/08\/05\/microbitmicropython-servo\/","title":{"rendered":"\u3010micro:bit\u3011MicroPython\u4f3a\u670d\u99ac\u9054\u64cd\u4f5c"},"content":{"rendered":"\n<p>\u4f3a\u670d\u99ac\u9054\u53ef\u4ee5\u900f\u904e\u89d2\u5ea6\u7684\u65b9\u5f0f\u8b93\u99ac\u9054\u6307\u5b9a\u5230\u56fa\u5b9a\u7684\u4f4d\u7f6e\uff0c\u5c0d\u65bc\u63a7\u5236\u4e00\u4e9b\u6a5f\u69cb\u7684\u60c5\u6cc1\u975e\u5e38\u65b9\u4fbf\u3002\u7b2c\u4e00\u500b\u7df4\u7fd2\u4f7f\u7528\u7684\u662f\u4e0b\u9762\u9019\u9846\u4f3a\u670d\u99ac\u9054\uff1a<\/p>\n\n\n\n<p><a href=\"https:\/\/www.taiwaniot.com.tw\/product\/%E8%BC%9D%E7%9B%9B-sg90-tower-pro-1-8kg-%E8%88%B5%E6%A9%9F-9%E5%85%8B%E4%BC%BA%E6%9C%8D%E6%A9%9F\/\">https:\/\/www.taiwaniot.com.tw\/product\/%E8%BC%9D%E7%9B%9B-sg90-tower-pro-1-8kg-%E8%88%B5%E6%A9%9F-9%E5%85%8B%E4%BC%BA%E6%9C%8D%E6%A9%9F\/<\/a><\/p>\n\n\n\n<p>\u5927\u90e8\u4efd\u7684\u4f3a\u670d\u99ac\u9054\u90fd\u6709\u4e09\u689d\u7dda\uff0c\u5206\u5225\u662f\u96fb\u6e90\u7dda\u7684\u6b63\u8ca0\u6975\uff08\u56e0\u70ba\u4f3a\u670d\u99ac\u9054\u9700\u8981\u8f03\u5927\u96fb\u6d41\uff0c\u6240\u4ee5\u4e5f\u662f\u8981\u984d\u5916\u4f9b\u96fb\u5594\uff09\uff0c\u4ee5\u53ca\u4e00\u689d\u6c7a\u5b9a\u8981\u8f49\u5e7e\u5ea6\u7684\u8a0a\u865f\u7dda\uff0c\u800c\u5c0d\u65bc\u8981\u63a7\u5236\u5b83\u7684\u89d2\u5ea6\u7684micro:bit\u4f86\u8aaa\uff0c\u9023\u63a5\u63a7\u5236\u7528\u7684\u8173\u4f4d\u9700\u8981\u6709PWM\u80fd\u529b\uff0c\u4e5f\u5c31\u662f\u4ee5\u6578\u4f4d\u4fe1\u865f\u6a21\u64ec\u985e\u6bd4\u4fe1\u865f\u7684\u6280\u8853\u3002micro:bit\u53ea\u6709pin3, pin4, \u4ee5\u53capin10\u9019\u4e09\u652f\u63a5\u8173\u5177\u5099\u6b64\u80fd\u529b\uff0c\u9084\u8a18\u5f97micro:bit\u7684\u63a5\u8173\u5716\u55ce\uff1f\u8acb\u53c3\u8003\u4ee5\u4e0b\u7684\u8aaa\u660e\uff1a<\/p>\n\n\n\n<p><a href=\"https:\/\/microbit-micropython.readthedocs.io\/en\/latest\/pin.html?highlight=PWM\">https:\/\/microbit-micropython.readthedocs.io\/en\/latest\/pin.html?highlight=PWM<\/a><\/p>\n\n\n\n<p>\u4f46\u662f\u90193\u652f\u63a5\u8173\u90fd\u548cLED\u662f\u5171\u7528\u7684\uff0c\u6240\u4ee5\u70ba\u4e86\u4f7f\u7528\u9019\u5e7e\u652f\u63a5\u8173\uff0c\u8981\u5148\u628aLED\u95dc\u9589\u624d\u80fd\u3002\u4ee5\u4e0b\u662f\u6e2c\u8a66\u7684\u7a0b\u5f0f\uff08\u5047\u8a2d\u628a\u4f3a\u670d\u99ac\u9054\u7684\u4fe1\u865f\u865f\u9023\u63a5\u5230pin3\uff09\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>from microbit import *\r\n\r\ndisplay.off()\r\nwhile True:\r\n    pin3.write_analog(60)\r\n    sleep(500)\r\n    pin3.write_analog(120)\r\n    sleep(500)<\/code><\/pre>\n\n\n\n<p>\u57f7\u884c\u4e0a\u9762\u9019\u500b\u7a0b\u5f0f\uff0c\u4f60\u6709\u5c31\u53ef\u4ee5\u770b\u5230\u4f3a\u670d\u99ac\u9054\u4ee50.5\u79d2\u70ba\u9593\u9694\uff0c\u5f88\u5feb\u5730\u5728\u5169\u500b\u4e0d\u540c\u7684\u89d2\u5ea6\u9593\u8f49\u52d5\u3002<\/p>\n\n\n\n<p>\u9084\u8a18\u5f97\u524d\u4e00\u500b\u4f7f\u7528\u5149\u611f\u6e2c\u5668\u7684\u55ae\u5143\u55ce\uff1f\u7d50\u5408\u5149\u611f\u6e2c\u5668\uff0c\u6211\u5011\u5c31\u53ef\u4ee5\u5229\u7528\u4e0d\u540c\u7684\u4eae\u5ea6\u4f86\u6c7a\u5b9a\u4f3a\u670d\u99ac\u9054\u7684\u8f49\u52d5\u89d2\u5ea6\uff0c\u9019\u500b\u65b9\u5f0f\u5c31\u53ef\u4ee5\u7528\u4f86\u88fd\u4f5c\u96f7\u5c04\u5149\u6253\u9776\u904a\u6232\u5594\u3002<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>from ssd1306 import initialize, clear_oled\r\nfrom ssd1306_text import add_text\r\nfrom microbit import *\r\n\r\ndisplay.off()\r\ninitialize()\r\nclear_oled()\r\nadd_text(0, 0, 'NKUST')\r\nadd_text(0, 1, 'Richard Ho')\r\n\r\npin3.write_analog(120)\r\nwhile True:\r\n    light = pin1.read_analog()\r\n    add_text(0, 3, 'Light:{:>4d}'.format(light))\r\n    if light &lt; 300:\r\n        pin3.write_analog(60)\r\n        sleep(5000)\r\n    else:\r\n        pin3.write_analog(120)<\/code><\/pre>\n\n\n\n<p>\u4e0a\u9762\u9019\u500b\u7a0b\u5f0f\u6703\u628a\u4f3a\u670d\u99ac\u9054\u56fa\u5b9a\u5728\u67d0\u4e00\u500b\u9ede\u4e0a\uff0c\u7576\u5075\u6e2c\u5230\u4eae\u5ea6\u5c0f\u65bc300\u7684\u6642\u5019\uff0c\u5c31\u6703\u8b93\u4f3a\u670d\u99ac\u9054\u8f49\u52d5\u5230\u53e6\u5916\u4e00\u500b\u89d2\u5ea6\u4e26\u505c\u75595\u79d2\u624d\u518d\u5075\u6e2c\u662f\u5426\u9700\u8981\u56de\u5fa9\u5230\u539f\u6709\u7684\u89d2\u5ea6\u3002\u6b64\u5916\uff0c\u70ba\u4e86\u8b93\u6211\u5011\u53ef\u4ee5\u96a8\u6642\u77ad\u89e3\u4eae\u5ea6\u7684\u6578\u503c\u4ee5\u65b9\u4fbf\u8abf\u6574\u7a0b\u5f0f\uff0c\u5728\u7a0b\u5f0f\u4e2d\u532f\u5165\u4e86ssd1306\uff0c\u9a45\u52d5OLED\u986f\u793a\u5668\u986f\u793a\u51fa\u6578\u503c\u5167\u5bb9\u3002<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"576\" src=\"https:\/\/104.es\/wp-content\/uploads\/2023\/08\/image-10-1024x576.png\" alt=\"\" class=\"wp-image-2529\" srcset=\"https:\/\/104.es\/wp-content\/uploads\/2023\/08\/image-10-1024x576.png 1024w, https:\/\/104.es\/wp-content\/uploads\/2023\/08\/image-10-300x169.png 300w, https:\/\/104.es\/wp-content\/uploads\/2023\/08\/image-10-768x432.png 768w, https:\/\/104.es\/wp-content\/uploads\/2023\/08\/image-10-1536x864.png 1536w, https:\/\/104.es\/wp-content\/uploads\/2023\/08\/image-10-2048x1152.png 2048w, https:\/\/104.es\/wp-content\/uploads\/2023\/08\/image-10-600x338.png 600w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n","protected":false},"excerpt":{"rendered":"<p>\u8981\u628a\u96fb\u529b\u8f49\u63db\u6210\u53ef\u63a7\u5236\u7684\u6a5f\u68b0\u529b\uff0c\u4f3a\u670d\u99ac\u9054\u7121\u7591\u662f\u6700\u4f73\u7684\u88dd\u7f6e\u4e4b\u4e00\u3002\u5728micro:bit\u4e2d\u4e0d\u9700\u8981\u532f\u5165\u4efb\u4f55\u5916\u5728\u7684\u6a21\u7d44\uff0c\u53ea\u8981\u96fb\u8def\u9023\u63a5\u59a5\u7576\uff0c\u5229\u7528MicroPython\u5167\u5efa\u7684\u6307\u4ee4\u5373\u53ef\u5b8c\u6210\u5c0d\u65bc\u4f3a\u670d\u99ac\u9054\u7684\u63a7\u5236\uff0c\u975e\u5e38\u65b9\u4fbf\u3002<\/p>\n","protected":false},"author":1,"featured_media":2529,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[11,15],"tags":[],"class_list":["post-2526","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-microbit","category-python"],"jetpack_featured_media_url":"https:\/\/104.es\/wp-content\/uploads\/2023\/08\/image-10.png","jetpack-related-posts":[],"jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/104.es\/index.php\/wp-json\/wp\/v2\/posts\/2526","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/104.es\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/104.es\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/104.es\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/104.es\/index.php\/wp-json\/wp\/v2\/comments?post=2526"}],"version-history":[{"count":2,"href":"https:\/\/104.es\/index.php\/wp-json\/wp\/v2\/posts\/2526\/revisions"}],"predecessor-version":[{"id":2530,"href":"https:\/\/104.es\/index.php\/wp-json\/wp\/v2\/posts\/2526\/revisions\/2530"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/104.es\/index.php\/wp-json\/wp\/v2\/media\/2529"}],"wp:attachment":[{"href":"https:\/\/104.es\/index.php\/wp-json\/wp\/v2\/media?parent=2526"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/104.es\/index.php\/wp-json\/wp\/v2\/categories?post=2526"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/104.es\/index.php\/wp-json\/wp\/v2\/tags?post=2526"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}