{"id":1347,"date":"2022-04-21T11:31:38","date_gmt":"2022-04-21T03:31:38","guid":{"rendered":"https:\/\/104.es\/?p=1347"},"modified":"2022-04-21T11:31:38","modified_gmt":"2022-04-21T03:31:38","slug":"cyberpi-fit-assistor","status":"publish","type":"post","link":"https:\/\/104.es\/index.php\/2022\/04\/21\/cyberpi-fit-assistor\/","title":{"rendered":"CyberPi \u5065\u8eab\u8f14\u52a9\u795e\u5668"},"content":{"rendered":"\n<p>\u73fe\u4ee3\u6108\u4f86\u6108\u591a\u7684\u4eba\u6709\u4e0a\u5065\u8eab\u623f\u7684\u7fd2\u6163\u3002\u5728\u4f7f\u7528\u5065\u8eab\u5668\u6750\u6642\uff0c\u540c\u4e00\u500b\u5668\u6750\u6559\u7df4\u90fd\u6703\u8981\u6c42\u8981\u505a3\u52305\u7d44\uff0c\u6bcf\u7d44\u52d5\u4f5c12~15\u6b21\uff0c\u7d44\u548c\u7d44\u4e4b\u9593\u8981\u4f11\u606f1\u52301.5\u5206\u9418\u3002\u5728\u5065\u8eab\u7684\u904e\u7a0b\u4e2d\uff0c\u8981\u8a08\u7b97\u540c\u4e00\u500b\u52d5\u4f5c\u505a\u4e86\u5e7e\u6b21\u6c92\u6709\u554f\u984c\uff0c\u4f46\u662f\uff0c\u6bcf\u4e00\u7d44\u52d5\u4f5c\u4e4b\u9593\u8981\u4f11\u606f\u7684\u6642\u9593\u4e26\u4e0d\u662f\u6bcf\u4e00\u500b\u5668\u6750\u90fd\u6709\u652f\u63f4\u9019\u500b\u529f\u80fd\u3002\u5728\u9019\u7bc7\u6587\u7ae0\u4e2d\uff0c\u6211\u5011\u5c31\u7528CyberPi\u4f86\u88fd\u4f5c\u4e00\u500b\u8f14\u52a9\u795e\u5668\uff0c\u8b93\u5b83\u53ef\u4ee5\u63d0\u9192\u6211\u5011\uff0c\u8a72\u505a\u4e0b\u4e00\u7d44\u52d5\u4f5c\u4e86\u3002<\/p>\n\n\n\n<p>\u56e0\u70baCyberPi\u672c\u8eab\u5177\u6709\u52d5\u4f5c\u611f\u6e2c\u5668\uff0c\u56e0\u6b64\u6211\u5011\u53ef\u4ee5\u7528\u5b83\u4f86\u6aa2\u67e5\u76ee\u524dCyberPi\u662f\u5426\u6709\u5728\u6643\u52d5\uff0c\u6211\u5011\u7684\u8a2d\u8a08\u65b9\u6cd5\u662f\uff0c\u7576CyberPi\u958b\u6a5f\u4e4b\u5f8c\uff0c\u5b83\u5c31\u6703\u4e0d\u505c\u5730\u8a08\u6578\uff0c\u5982\u679c\u7d2f\u8a08\u7684\u8a08\u6578\u5230\u9054\u6211\u5011\u8a2d\u5b9a\u7684\u6642\u9593\u9ede\u6642\uff0c\u5c31\u8981\u767c\u51fa\u8072\u97f3\u8b93\u6211\u5011\u77e5\u9053\uff0c\u4f11\u606f\u5920\u4e86\uff0c\u8a72\u9032\u884c\u4e0b\u4e00\u7d44\u4e86\u3002\u7576\u6211\u5011\u53c8\u958b\u59cb\u904b\u52d5\u6642\uff0c\u8a08\u6578\u7684\u503c\u5c31\u8981\u6b78\u96f6\u91cd\u65b0\u8a08\u7b97\u3002<\/p>\n\n\n\n<p>\u7b2c\u4e00\u7248\u7684\u7a0b\u5f0f\u5982\u4e0b\u6240\u793a\uff0c\u5b83\u53ea\u8981\u4e00\u958b\u6a5f\u5c31\u958b\u59cb\u8a08\u6578\uff0c\u6643\u52d5\u5c31\u628a\u6642\u9593\u6b78\u96f6\u91cd\u7b97\uff0c\u5982\u679c\u8a08\u6578\u8d85\u904e90\u79d2\uff08\u4e00\u5206\u534a\uff09\u5c31\u6703\u767c\u51fa\u8072\u97f3\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>import cyberpi as cp\nimport event, time\n\ncounter = 0\n\n@event.start\ndef on_start():\n    while True:\n        global counter \n        cp.display.show_label(counter, 32, \"center\")\n        time.sleep(1)\n        counter += 1\n        if counter &gt; 20:\n            cp.audio.play_until('sprint')\n\n@event.is_shake\ndef on_shake():\n    global counter\n    counter = 0<\/code><\/pre>\n\n\n\n<p>\u9019\u500b\u7a0b\u5f0f\u4f7f\u7528\u4e86\u4e00\u500bcounter\u8b8a\u6578\u7528\u4f86\u8a08\u7b97\u505c\u6b62\u52d5\u4f5c\u5230\u76ee\u524d\u70ba\u6b62\u7d2f\u8a08\u7684\u6642\u9593\uff0c\u75282\u500b\u4e8b\u4ef6\u4f86\u9032\u884c\u64cd\u4f5c\uff0cstart\u4e8b\u4ef6\u5728CyberPi\u4e00\u901a\u4e0a\u96fb\u6e90\u6642\u5c31\u958b\u59cb\u57f7\u884c\u986f\u793a\u8a08\u6578\u5668\u4ee5\u53ca\u7d2f\u8a08\u8a08\u6578\u5668\u7684\u5de5\u4f5c\uff0c\u540c\u6642\u5b83\u6703\u6aa2\u67e5\u5982\u679c\u8d85\u904e\u8a2d\u5b9a\u7684\u6642\u9593\uff08\u5728\u6b64\u7bc4\u4f8b\u4ee520\u79d2\u70ba\u4f8b\uff0c\u540c\u5b78\u5011\u53ef\u4ee5\u81ea\u884c\u66f4\u6539\uff09\uff0c\u5c31\u6703\u767c\u51fa&#8217;sprint&#8217;\u9019\u500b\u8072\u97f3\uff0c\u7576\u7136\u8072\u97f3\u4e5f\u53ef\u4ee5\u81ea\u884c\u66f4\u63db\u3002<\/p>\n\n\n\n<p>is_shake\u662f\u5075\u6e2cCyberPi\u662f\u5426\u6643\u52d5\u7684\u4e8b\u4ef6\uff0c\u5982\u679c\u767c\u751f\u6643\u52d5\u4e86\uff0c\u5c31\u628acounter\u8a2d\u5b9a\u70ba0\u3002\u56e0\u70bacounter\u9019\u500b\u8b8a\u6578\u662f\u5169\u500b\u4e8b\u4ef6\u51fd\u5f0f\u90fd\u8981\u64cd\u4f5c\u7684\uff0c\u6240\u4ee5\u8981\u628a\u5b83\u5b9a\u7fa9\u5728\u5916\u90e8\uff0c\u5728\u51fd\u5f0f\u4e2d\u8981\u64cd\u4f5c\u6642\u8981\u5148\u7528global counter\u5ba3\u544a\u624d\u884c\u3002<\/p>\n\n\n\n<p>\u4e0a\u8ff0\u7684\u7a0b\u5f0f\u53ef\u4ee5\u6b63\u5e38\u5730\u904b\u4f5c\uff0c\u4e0d\u904e\u5b83\u7684\u7f3a\u9ede\u662f\u5728\u7a0b\u5f0f\u4e2d\u56fa\u5b9a\u4e86\u8a08\u6578\u7684\u6642\u9593\uff0c\u6b64\u7a2e\u65b9\u5f0f\u6703\u8b93\u5b83\u7684\u5be6\u7528\u6027\u5927\u6253\u6298\u6263\uff0c\u7562\u7adf\u4e26\u4e0d\u662f\u6bcf\u4e00\u500b\u4eba\u6216\u662f\u6bcf\u4e00\u500b\u52d5\u4f5c\u6240\u9700\u8981\u7684\u4f11\u606f\u6642\u9593\u90fd\u662f\u76f8\u540c\u7684\u3002\u4e0b\u4e00\u500b\u7a0b\u5f0f\u6211\u5011\u5f15\u5165\u4e86\u53e6\u5916\u4e00\u500b\u8b8a\u6578limit\uff0c\u4ee5\u53ca\u6416\u687f\u4e0a\u4e0b\u7684\u4e8b\u4ef6\uff0c\u8b93\u4f7f\u7528\u8005\u53ef\u4ee5\u81ea\u7531\u5730\u8abf\u6574\u8981\u767c\u51fa\u8072\u97ff\u7684\u6642\u9593\uff0c\u7a0b\u5f0f\u5982\u4e0b\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>import cyberpi as cp\nimport mbuild, event, time\n\ncounter = 0\nlimit = 60\n\n@event.start\ndef on_start():\n    while True:\n        global counter, limit \n        cp.display.show_label(\"{}\/{}\".format(counter,limit), 32, \"center\")\n        time.sleep(1)\n        counter += 1\n        if counter &gt; limit:\n            cp.audio.play_until('sprint')\n\n@event.is_shake\ndef on_shake():\n    global counter\n    counter = 0\n\n@event.is_press('down')\ndef on_up():\n    global limit\n    limit = limit - 10\n    if limit &lt; 10:\n        limit = 10\n        \n@event.is_press('up')\ndef on_down():\n    global limit\n    limit = limit + 10\n    if limit &gt; 120:\n        limit = 120<\/code><\/pre>\n\n\n\n<p>\u4e0a\u9762\u9019\u500b\u7a0b\u5f0f\u5df2\u7d93\u53ef\u4ee5\u8b93\u6211\u5011\u81ea\u7531\u5730\u8abf\u6574\u4f11\u606f\u7684\u6642\u9593\u4e86\u3002\u4f46\u6709\u6642\u5019\u5982\u679c\u6211\u5011\u60f3\u8981\u8b93\u5b83\u66ab\u505c\u4e00\u4e0b\uff0c\u90a3\u53c8\u8a72\u5982\u4f55\u8a2d\u8a08\u5462\uff1f\u8acb\u53c3\u8003\u4ee5\u4e0b\u7684\u7a0b\u5f0f\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>import cyberpi as cp\nimport mbuild, event, time\n\ncounter = 0\nlimit = 60\npause = False\n\n@event.start\ndef on_start():\n    while True:\n        global counter, limit, pause\n        if not pause:\n            cp.display.show_label(\"{}\/{}\".format(counter,limit), 32, \"center\")\n            time.sleep(1)\n            counter += 1\n        else:\n            cp.display.show_label(\"Paused\", 32, \"center\")\n        if counter &gt; limit:\n            cp.audio.play_until('sprint')\n\n@event.is_shake\ndef on_shake():\n    global counter\n    counter = 0\n\n@event.is_press('down')\ndef on_up():\n    global limit\n    limit = limit - 10\n    if limit &lt; 10:\n        limit = 10\n        \n@event.is_press('up')\ndef on_down():\n    global limit\n    limit = limit + 10\n    if limit &gt; 120:\n        limit = 120\n\n@event.is_press('a')\ndef on_a():\n    global pause\n    pause = True\n\n@event.is_press('b')\ndef on_b():\n    global pause\n    pause = False    <\/code><\/pre>\n\n\n\n<p>\u5728\u6700\u7d42\u7248\u7684\u7a0b\u5f0f\u4e2d\u6211\u5011\u52a0\u5165\u4e86\u53e6\u5916\u5169\u500b\u6309\u9215\uff0ca\u6309\u9215\u8868\u793a\u8981\u66ab\u505c\uff0cb\u6309\u9215\u8868\u793a\u8981\u7e7c\u7e8c\u3002\u540c\u6642\u70ba\u4e86\u8b93CyberPi\u53ef\u4ee5\u771f\u6b63\u57f7\u884c\u66ab\u505c\u7684\u4f5c\u696d\uff0c\u518d\u52a0\u5165\u4e00\u500b\u5168\u57df\u8b8a\u6578pause\uff0c\u5982\u679c\u5b83\u4e0d\u662fTrue\u7684\u6642\u5019\u624d\u8981\u57f7\u884ccounter = counter + 1\u4ee5\u53ca\u986f\u793a\u8a08\u6578\u73fe\u6cc1\u7684\u64cd\u4f5c\uff0c\u5982\u679c\u662fpause\u662fTrue\u7684\u8a71\uff0c\u5247\u4e0d\u8981\u8a08\u6578\uff0c\u540c\u6642\u986f\u793a&#8221;Paused&#8221;\u9019\u6bb5\u6587\u5b57\u3002<\/p>\n\n\n\n<p>\u4ee5\u4e0b\u5c31\u662f\u6b64\u5065\u8eab\u8f14\u52a9\u795e\u5668\u7684\u64cd\u4f5c\u5c55\u793a\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=\"CyberPi \u5065\u623f\u8f14\u52a9\u795e\u5668\" width=\"640\" height=\"360\" src=\"https:\/\/www.youtube.com\/embed\/ZeJcawf8cqQ?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>\u73fe\u4ee3\u6108\u4f86\u6108\u591a\u7684\u4eba\u6709\u4e0a\u5065\u8eab\u623f\u7684\u7fd2\u6163\u3002\u5728\u4f7f\u7528\u5065\u8eab\u5668\u6750\u6642\uff0c\u540c\u4e00\u500b\u5668\u6750\u6559\u7df4\u90fd\u6703\u8981\u6c42\u8981\u505a3\u52305\u7d44\uff0c\u6bcf\u7d44\u52d5\u4f5c12~15\u6b21\uff0c\u7d44\u548c\u7d44\u4e4b\u9593\u8981\u4f11\u606f1\u52301.5\u5206\u9418\u3002\u5728\u5065\u8eab\u7684\u904e\u7a0b\u4e2d\uff0c\u8981\u8a08\u7b97\u540c\u4e00\u500b\u52d5\u4f5c\u505a\u4e86\u5e7e\u6b21\u6c92\u6709\u554f\u984c\uff0c\u4f46\u662f\uff0c\u6bcf\u4e00\u7d44\u52d5\u4f5c\u4e4b\u9593\u8981\u4f11\u606f\u7684\u6642\u9593\u4e26\u4e0d\u662f\u6bcf\u4e00\u500b\u5668\u6750\u90fd\u6709\u652f\u63f4\u9019\u500b\u529f\u80fd\u3002\u5728\u9019\u7bc7\u6587\u7ae0\u4e2d\uff0c\u6211\u5011\u5c31\u7528CyberPi\u4f86\u88fd\u4f5c\u4e00\u500b\u8f14\u52a9\u795e\u5668\uff0c\u8b93\u5b83\u53ef\u4ee5\u63d0\u9192\u6211\u5011\uff0c\u8a72\u505a\u4e0b\u4e00\u7d44\u52d5\u4f5c\u4e86\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-1347","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\/1347","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=1347"}],"version-history":[{"count":0,"href":"https:\/\/104.es\/index.php\/wp-json\/wp\/v2\/posts\/1347\/revisions"}],"wp:attachment":[{"href":"https:\/\/104.es\/index.php\/wp-json\/wp\/v2\/media?parent=1347"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/104.es\/index.php\/wp-json\/wp\/v2\/categories?post=1347"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/104.es\/index.php\/wp-json\/wp\/v2\/tags?post=1347"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}