{"id":1253,"date":"2022-03-29T16:17:25","date_gmt":"2022-03-29T08:17:25","guid":{"rendered":"https:\/\/104.es\/?p=1253"},"modified":"2022-03-29T16:17:25","modified_gmt":"2022-03-29T08:17:25","slug":"cyperpi-python-counter","status":"publish","type":"post","link":"https:\/\/104.es\/index.php\/2022\/03\/29\/cyperpi-python-counter\/","title":{"rendered":"CyperPi Python\u7a0b\u5f0f\u8a2d\u8a08\u5165\u9580"},"content":{"rendered":"\n<p>Python\u5728\u8a31\u591a\u958b\u767c\u677f\u4e0a\u5df2\u7d93\u6210\u70ba\u4e86\u975e\u5e38\u53d7\u6b61\u8fce\u7684\u7a0b\u5f0f\u8a9e\u8a00\uff0c\u8209\u51e1microbit\u3001NodeMCU\u3001HaloCode\u4ee5\u53ca\u672c\u7bc7\u6587\u7ae0\u8981\u4ecb\u7d39\u7684CyperPi\uff0c\u90fd\u53ef\u4ee5\u4f7f\u7528\u3002\u7136\u800c\u7531\u65bc\u958b\u767c\u677f\u672c\u8eab\u8a08\u7b97\u80fd\u529b\u7684\u9650\u5236\uff0c\u5728\u9019\u4e9b\u677f\u5b50\u4e0a\u6240\u4f7f\u7528\u7684Python\u7248\u672c\u53e6\u7d71\u7a31\u70baMicroPython\uff0c\u7b97\u662fPython\u8a9e\u8a00\u7684\u4e00\u500b\u5b50\u96c6\u5408\uff0c\u4e0d\u540c\u7684\u958b\u767c\u677f\u80fd\u652f\u63f4\u7684\u51fd\u5f0f\u5eab\u4e5f\u4e0d\u5118\u76f8\u540c\uff0c\u6240\u4ee5\u5728\u958b\u59cb\u64b0\u5beb\u7a0b\u5f0f\u4e4b\u524d\uff0c\u9084\u662f\u8981\u5148\u67e5\u8a62\u76ee\u6a19\u958b\u767c\u677f\u6240\u63d0\u4f9b\u7684API\u6587\u4ef6\u70ba\u4e3b\u3002<\/p>\n\n\n\n<p>CyperPi\u7684MicroPython\u958b\u767c\u8aaa\u660e\u6587\u4ef6\u7db2\u5740\u5982\u4e0b\uff1a<\/p>\n\n\n\n<p>https:\/\/education.makeblock.com\/help\/mblock-python-editor-python-api-documentation-for-cyberpi\/<\/p>\n\n\n\n<p>\u9664\u4e86\u76f4\u63a5\u53c3\u8003\u4e0a\u8ff0\u7684\u6587\u4ef6\u5167\u5bb9\u4e4b\u5916\uff0c\u56e0\u70ba\u5b83\u5011\u7684\u7a4d\u6728\u74b0\u5883\u4e5f\u6709\u63d0\u4f9b\u7a4d\u6728\u8f49\u63dbPython\u7684\u529f\u80fd\uff0c\u56e0\u6b64\u6709\u4e9b\u6642\u5019\u4e5f\u53ef\u4ee5\u5148\u53bb\u62c9\u500b\u7a4d\u6728\uff0c\u8f49\u63db\u6210Python\u51fd\u5f0f\u7a0b\u5f0f\u78bc\u4e4b\u5f8c\u518d\u62ff\u4f86\u4f7f\u7528\u4e5f\u662f\u5f88\u65b9\u4fbf\u7684\u958b\u767c\u65b9\u5f0f\u3002\u5728\u958b\u59cb\u7de8\u5beb\u7a0b\u5f0f\u524d\u8acb\u5148\u53bb<a href=\"https:\/\/mblock.makeblock.com\/zh-cn\/download\/\">\u4e0b\u8f09<\/a>\u514d\u8cbb\u7684\u6167\u7de8\u7a0b\u684c\u9762\u7aef\uff0c\u5982\u4e0b\u6240\u793a\uff1a<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1225\" height=\"1025\" src=\"http:\/\/104es.nkust.org\/wp-content\/uploads\/2022\/03\/image-29.png?w=1024\" alt=\"\" class=\"wp-image-1258\" srcset=\"https:\/\/104.es\/wp-content\/uploads\/2022\/03\/image-29.png 1225w, https:\/\/104.es\/wp-content\/uploads\/2022\/03\/image-29-300x251.png 300w, https:\/\/104.es\/wp-content\/uploads\/2022\/03\/image-29-1024x857.png 1024w, https:\/\/104.es\/wp-content\/uploads\/2022\/03\/image-29-768x643.png 768w\" sizes=\"auto, (max-width: 1225px) 100vw, 1225px\" \/><\/figure>\n\n\n\n<p>\u5b89\u88dd\u5b8c\u6210\u4e4b\u5f8c\uff0c\u57f7\u884c\u8a72\u7a0b\u5f0f\u4e00\u958b\u59cb\u51fa\u73fe\u7684\u662f\u7a4d\u6728\u7684\u958b\u767c\u74b0\u5883\uff0c\u8acb\u9078\u64c7\u53f3\u4e0a\u89d2\u7684\u300cPython\u7de8\u8f2f\u5668\u300d\u524d\u5f80Python\u958b\u767c\u74b0\u5883\uff0c\u5982\u4e0b\u6240\u793a\uff1a<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1505\" height=\"900\" src=\"http:\/\/104es.nkust.org\/wp-content\/uploads\/2022\/03\/image-30.png?w=1024\" alt=\"\" class=\"wp-image-1260\" srcset=\"https:\/\/104.es\/wp-content\/uploads\/2022\/03\/image-30.png 1505w, https:\/\/104.es\/wp-content\/uploads\/2022\/03\/image-30-300x179.png 300w, https:\/\/104.es\/wp-content\/uploads\/2022\/03\/image-30-1024x612.png 1024w, https:\/\/104.es\/wp-content\/uploads\/2022\/03\/image-30-768x459.png 768w\" sizes=\"auto, (max-width: 1505px) 100vw, 1505px\" \/><\/figure>\n\n\n\n<p>\u9032\u5165Python\u958b\u767c\u74b0\u5883\u4e4b\u5f8c\uff0c\u8981\u4f9d\u7167\u4f60\u7684\u9700\u6c42\u6c7a\u5b9a\u8981\u4f7f\u7528Live\u9084\u662fUpload\u6a21\u5f0f\uff0c\u4f7f\u7528Upload\u6a21\u5f0f\u53ef\u4ee5\u8b93CyberPi\u5e36\u8457\u8d70\uff0c\u57f7\u884c\u7a0b\u5f0f\u6642\u4e0d\u9700\u8981\u96fb\u8166\uff0c\u4f46\u662f\u8a31\u591a\u7b2c3\u65b9\u7684\u5957\u4ef6\u90fd\u6c92\u8fa6\u6cd5\u4f7f\u7528\uff0c\u53ea\u80fd\u4f7f\u7528CyberPi\u6240\u63d0\u4f9b\u7684\u4e00\u4e9b\u51fd\u5f0f\u3002CyberPi\u7684\u958b\u767c\u74b0\u5883\u5982\u4e0b\uff1a<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1549\" height=\"992\" src=\"http:\/\/104es.nkust.org\/wp-content\/uploads\/2022\/03\/image-31.png?w=1024\" alt=\"\" class=\"wp-image-1262\" srcset=\"https:\/\/104.es\/wp-content\/uploads\/2022\/03\/image-31.png 1549w, https:\/\/104.es\/wp-content\/uploads\/2022\/03\/image-31-300x192.png 300w, https:\/\/104.es\/wp-content\/uploads\/2022\/03\/image-31-1024x656.png 1024w, https:\/\/104.es\/wp-content\/uploads\/2022\/03\/image-31-768x492.png 768w, https:\/\/104.es\/wp-content\/uploads\/2022\/03\/image-31-1536x984.png 1536w\" sizes=\"auto, (max-width: 1549px) 100vw, 1549px\" \/><\/figure>\n\n\n\n<p>\u5728CyberPi\u7684Python\u7de8\u8f2f\u74b0\u5883\u4e2d\u4ecd\u7136\u53ef\u4ee5\u96a8\u6642\u5229\u7528\u53f3\u4e0a\u89d2\u7684\u300c\u5716\u5f62\u5316\u7a0b\u5f0f\u300d\u6309\u9215\uff0c\u56de\u5230\u7a4d\u6728\u74b0\u5883\u9032\u884c\u53c3\u8003\u3002\u5728\u672c\u7bc7\u6587\u7ae0\u4e2d\uff0c\u8acb\u5148\u6309\u4e0b\u300c\u9023\u63a5\u300d\u6309\u9215\uff0c\u7136\u5f8c\u9078\u64c7\u300c\u4e0a\u50b3\u6a21\u5f0f\u300d\uff0c\u63a5\u8457\u5de6\u65b9\u9078\u64c7\u65b0\u589e\u6a94\u6848\uff0c\u628a\u6a94\u6848\u547d\u540d\u70bamain1.py\uff0c\u518d\u8f38\u5165\u4ee5\u4e0b\u7684\u7a0b\u5f0f\u78bc\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>import cyberpi as cp\nimport time\n\nfor i in range(1, 101):\n    cp.display.show_label(i, 32, \"center\", \"center\")\n    time.sleep(0.5)<\/code><\/pre>\n\n\n\n<p>\u8f38\u5165\u5b8c\u7562\u4e4b\u5f8c\u518d\u9ede\u9078\u4e0a\u50b3\uff0c\u5c31\u6703\u770b\u5230CyberPi\u958b\u59cb\u9032\u884c\u8a08\u6578\u7684\u52d5\u4f5c\uff0c\u5f9e1\u958b\u59cb\u6578\u5230100\u3002\u5982\u679c\u60f3\u8981\u518d\u91cd\u65b0\u958b\u59cb\u7684\u8a71\uff0c\u8acb\u6309\u4e0b\u91cd\u7f6e\u6309\u9215\uff0c\u6216\u662f\u518d\u4e0a\u50b3\u4e00\u6b21\u5c31\u53ef\u4ee5\u4e86\u3002<\/p>\n\n\n\n<p>\u5982\u679c\u6211\u5011\u5e0c\u671b\u7684\u662f\u53ef\u4ee5\u6bcf\u6b21\u6309\u9215\u4e4b\u5f8c\u624d\u6703\u958b\u59cb\u8a08\u6578\uff0c\u90a3\u9ebc\u53ef\u4ee5\u628a\u7a0b\u5f0f\u4fee\u6539\u5982\u4e0b\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>import cyberpi as cp\nimport time, event\n\n@event.start\ndef on_start():\n    cp.display.show_label(\"Welcome\", 16, \"center\", \"center\")\n\n@event.is_press(\"a\")\ndef on_a_pressed():\n    cp.display.clear()\n    cp.led.on(255,0,0)\n    for i in range(1, 11):\n        cp.display.show_label(i, 32, \"center\", \"center\")\n        time.sleep(0.5)\n    cp.led.on(0,255,0)<\/code><\/pre>\n\n\n\n<p>\u4e0a\u9762\u9019\u500b\u7a0b\u5f0f\u5229\u7528\u4e86\u4e8b\u4ef6\u8655\u7406\u4fee\u98fe\u5b50\uff0c\u8b93\u4e8b\u4ef6\u7684\u8655\u7406\u66f4\u52a0\u5730\u5bb9\u6613\u3002\u4e00\u958b\u59cb\u87a2\u5e55\u4e0a\u6703\u5148\u986f\u793aWelcome\u5b57\u6a23\uff0c\u5728\u4f7f\u7528\u8005\u6309\u4e0b\u6309\u9215A\u4e4b\u5f8c\u624d\u958b\u59cb\u8a08\u6578\uff0c\u8a08\u6578\u6642\u71c8\u865f\u8a2d\u5b9a\u70ba\u7d05\u71c8\uff0c\u7b49\u5230\u8a08\u6578\u523010\u6642\u5c31\u505c\u6b62\u8a08\u6578\uff0c\u540c\u6642\u4e5f\u628aLED\u71c8\u6539\u70ba\u7da0\u71c8\u3002\u8acb\u53c3\u8003\u4ee5\u4e0b\u7684\u57f7\u884c\u793a\u7bc4\u5f71\u7247\uff1a<\/p>\n\n\n\n<figure class=\"wp-block-embed is-type-video is-provider-youtube wp-block-embed-youtube wp-embed-aspect-16-9 wp-has-aspect-ratio\"><div class=\"wp-block-embed__wrapper\">\n<iframe loading=\"lazy\" title=\"Cyber Pi \u8a08\u6578\u5668\u793a\u7bc4\u5f71\u7247\" width=\"640\" height=\"360\" src=\"https:\/\/www.youtube.com\/embed\/39KFlKp-Jck?feature=oembed\" frameborder=\"0\" allow=\"accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share\" referrerpolicy=\"strict-origin-when-cross-origin\" allowfullscreen><\/iframe>\n<\/div><\/figure>\n","protected":false},"excerpt":{"rendered":"<p>Python\u5728\u8a31\u591a\u958b\u767c\u677f\u4e0a\u5df2\u7d93\u6210\u70ba\u4e86\u975e\u5e38\u53d7\u6b61\u8fce\u7684\u7a0b\u5f0f\u8a9e\u8a00\uff0c\u8209\u51e1microbit\u3001NodeMCU\u3001HaloCode\u4ee5\u53ca\u672c\u7bc7\u6587\u7ae0\u8981\u4ecb\u7d39\u7684CyperPi\uff0c\u90fd\u53ef\u4ee5\u4f7f\u7528\u3002\u7136\u800c\u7531\u65bc\u958b\u767c\u677f\u672c\u8eab\u8a08\u7b97\u80fd\u529b\u7684\u9650\u5236\uff0c\u5728\u9019\u4e9b\u677f\u5b50\u4e0a\u6240\u4f7f\u7528\u7684Python\u7248\u672c\u53e6\u7d71\u7a31\u70baMicroPython\uff0c\u7b97\u662fPython\u8a9e\u8a00\u7684\u4e00\u500b\u5b50\u96c6\u5408\uff0c\u4e0d\u540c\u7684\u958b\u767c\u677f\u80fd\u652f\u63f4\u7684\u51fd\u5f0f\u5eab\u4e5f\u4e0d\u5118\u76f8\u540c\uff0c\u6240\u4ee5\u5728\u958b\u59cb\u64b0\u5beb\u7a0b\u5f0f\u4e4b\u524d\uff0c\u9084\u662f\u8981\u5148\u67e5\u8a62\u76ee\u6a19\u958b\u767c\u677f\u6240\u63d0\u4f9b\u7684API\u6587\u4ef6\u70ba\u4e3b\u3002<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[5],"tags":[],"class_list":["post-1253","post","type-post","status-publish","format-standard","hentry","category-cyber-pi"],"jetpack_featured_media_url":"","jetpack-related-posts":[],"jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/104.es\/index.php\/wp-json\/wp\/v2\/posts\/1253","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=1253"}],"version-history":[{"count":0,"href":"https:\/\/104.es\/index.php\/wp-json\/wp\/v2\/posts\/1253\/revisions"}],"wp:attachment":[{"href":"https:\/\/104.es\/index.php\/wp-json\/wp\/v2\/media?parent=1253"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/104.es\/index.php\/wp-json\/wp\/v2\/categories?post=1253"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/104.es\/index.php\/wp-json\/wp\/v2\/tags?post=1253"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}