{"id":7543,"date":"2025-03-29T17:42:49","date_gmt":"2025-03-29T08:42:49","guid":{"rendered":"https:\/\/robot.e-nat.org\/?p=7543"},"modified":"2025-03-29T17:44:01","modified_gmt":"2025-03-29T08:44:01","slug":"python%e5%85%a5%e9%96%80%e7%ac%ac2%e5%9b%9e%e3%80%8c%e9%bb%92%e3%81%84%e7%b7%9a%e3%82%92%e8%a6%8b%e3%81%a4%e3%81%91%e3%82%8b%e3%81%be%e3%81%a7%e9%80%b2%e3%82%80%e3%80%8d","status":"publish","type":"post","link":"https:\/\/robot.e-nat.org\/?p=7543","title":{"rendered":"Python\u5165\u9580\u7b2c2\u56de\u300c\u9ed2\u3044\u7dda\u3092\u898b\u3064\u3051\u308b\u307e\u3067\u9032\u3080\u300d"},"content":{"rendered":"\n<p>\u3000\u91d1\u5b8f\u548c\u5be6\u3067\u3059\u3002Python\u5165\u9580\u306e\u7b2c2\u56de\u3067\u3059\u3002\u4eca\u56de\u306e\u4e3b\u65e8\u306f\u3001runloop\u3068await\u3092\u4e00\u7dd2\u306b\u4f7f\u3046\u3068\u3001\u25cb\u25cb\u307e\u3067\u5f85\u3064\u3068\u3044\u3046\u3088\u3046\u306a\u72b6\u614b\u304c\u5909\u5316\u3059\u308b\u307e\u3067\u540c\u3058\u52d5\u4f5c\u3092\u3059\u308b\u30d7\u30ed\u30b0\u30e9\u30e0\u306e\u4f5c\u6210\u304c\u7c21\u5358\u3060\u3044\u3046\u3053\u3068\u3067\u3059\u3002\u3044\u308f\u3086\u308b\u9ed2\u3044\u7dda\u3092\u898b\u3064\u3051\u308b\u307e\u3067\u9032\u3080\u3068\u3044\u3046\u30d7\u30ed\u30b0\u30e9\u30e0\u3092\u4f5c\u308a\u307e\u3059\u3002<br>\u3000\u30e2\u30fc\u30bf\u30fc\u306fC\u30dd\u30fc\u30c8\u3068D\u30dd\u30fc\u30c8\u306b\u63a5\u7d9a\u3055\u308c\u3066\u304a\u308a\u3001motor.pair.pair()\u95a2\u6570\u3067\u30da\u30a2\u306b\u3057\u3066\u30ed\u30dc\u30c3\u30c8\u306e\u99c6\u52d5\u306b\u4f7f\u3044\u307e\u3059\u3002B\u30dd\u30fc\u30c8\u306b\u63a5\u7d9a\u3057\u305f\u30ab\u30e9\u30fc\u30bb\u30f3\u30b5\u30fc\u306e\u53cd\u5c04\u5149\u304c40\u672a\u6e80\u306b\u306a\u308b\u307e\u3067\u3001<br>await runloop.until(intensity_found)\u3067\u5f85\u3061\u307e\u3059\u3002<br>\u3000\u305d\u3057\u3066intensity_found()\u95a2\u6570\u304creflection\uff08\u53cd\u5c04\u5149\uff09\u304c40\u672a\u6e80\u3060\u3068\u691c\u77e5\u3057\u3066True\u3092\u8fd4\u3057\u305f\u3089\u3001\u30e2\u30fc\u30bf\u30fc\u3092\u505c\u6b62\u3057\u3066\u30d7\u30ed\u30b0\u30e9\u30e0\u3092\u629c\u3051\u307e\u3059\u3002<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>from hub import port\nimport runloop, motor_pair, sys, color_sensor\n\ndef intensity_found():\n    return color_sensor.reflection(port.B) &lt; 40\n\nasync def main():\n    # \u30e2\u30fc\u30bf\u30fc\u30da\u30a2\u3092\u30bb\u30c3\u30c8\u3057\u3066\u79fb\u52d5\u958b\u59cb\n    motor_pair.pair(motor_pair.PAIR_1, port.C, port.D)\n    motor_pair.move(motor_pair.PAIR_1, 0)\n    # \u6697\u3044\u3068\u3053\u308d\u306b\u79fb\u52d5\u3059\u308b\u306e\u3092\u5f85\u3064\n    await runloop.until(intensity_found)\n    # \u79fb\u52d5\u3092\u7d42\u4e86\u3057\u3066\u3001\u30d7\u30ed\u30b0\u30e9\u30e0\u3092\u629c\u3051\u308b\n    motor_pair.stop(motor_pair.PAIR_1)\n    sys.exit()\n\n\nrunloop.run(main())\n<\/code><\/pre>\n\n\n\n<p>\u72b6\u614b\u306e\u5909\u5316\u3092\u5f85\u3064\u306e\u306bwhile\u6587\u3084for\u6587\u3092\u4f7f\u3063\u3066\u30eb\u30fc\u30d7\u69cb\u9020\u3092\u4f5c\u308b\u5fc5\u8981\u304c\u306a\u3044\u306e\u3067\u3001\u30d7\u30ed\u30b0\u30e9\u30e0\u304c\u30b7\u30f3\u30d7\u30eb\u306b\u306a\u308a\u307e\u3059\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u3000\u91d1\u5b8f\u548c\u5be6\u3067\u3059\u3002Python\u5165\u9580\u306e\u7b2c2\u56de\u3067\u3059\u3002\u4eca\u56de\u306e\u4e3b\u65e8\u306f\u3001runloop\u3068await\u3092\u4e00\u7dd2\u306b\u4f7f\u3046\u3068\u3001\u25cb\u25cb\u307e\u3067 &hellip; <\/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":[41],"tags":[43,15,14],"class_list":["post-7543","post","type-post","status-publish","format-standard","hentry","category-python","tag-python-2","tag-15","tag-14","latest_post"],"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/robot.e-nat.org\/index.php?rest_route=\/wp\/v2\/posts\/7543","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/robot.e-nat.org\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/robot.e-nat.org\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/robot.e-nat.org\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/robot.e-nat.org\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=7543"}],"version-history":[{"count":4,"href":"https:\/\/robot.e-nat.org\/index.php?rest_route=\/wp\/v2\/posts\/7543\/revisions"}],"predecessor-version":[{"id":7547,"href":"https:\/\/robot.e-nat.org\/index.php?rest_route=\/wp\/v2\/posts\/7543\/revisions\/7547"}],"wp:attachment":[{"href":"https:\/\/robot.e-nat.org\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=7543"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/robot.e-nat.org\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=7543"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/robot.e-nat.org\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=7543"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}