{"id":121,"date":"2019-09-01T11:35:43","date_gmt":"2019-09-01T03:35:43","guid":{"rendered":"http:\/\/blog.coolcoding.cn\/?p=121"},"modified":"2020-09-28T21:53:59","modified_gmt":"2020-09-28T13:53:59","slug":"arduino-%e8%88%b5%e6%9c%ba%e5%ae%9e%e9%aa%8c","status":"publish","type":"post","link":"https:\/\/blog.coolcoding.cn\/?p=121","title":{"rendered":"Arduino-\u8235\u673a\u5b9e\u9a8c"},"content":{"rendered":"\n<pre class=\"wp-block-code\"><code>#include &lt;Servo.h>\n\nServo myservo;\nbool dir = false;\n\nvoid setup() {\n  myservo.attach(9); \/\/ \u63a59\u53f7\n}\n\nvoid loop(){\n  int angle = myservo.read();\n  if (dir)\n  {\n    if (++angle >= 180)\n    {\n      angle = 180;\n      dir = !dir;\n    }\n  }\n  else\n  {\n    if (--angle &lt;= 0)\n    {\n      angle = 0;\n      dir = !dir; \n    }\n  }\n  myservo.write(angle);\n  delay(10);\n}<\/code><\/pre>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"http:\/\/blog.coolcoding.cn\/wp-content\/uploads\/2020\/09\/110931c818ex01zt00z0yt.png\" alt=\"\u00e5\u009b\u00be\u00e7\u0089\u00873.png\"\/><\/figure>\n\n\n\n<figure class=\"wp-block-image\"><img loading=\"lazy\" decoding=\"async\" width=\"945\" height=\"389\" src=\"http:\/\/blog.coolcoding.cn\/wp-content\/uploads\/2019\/09\/1.png\" alt=\"\" class=\"wp-image-122\" srcset=\"https:\/\/blog.coolcoding.cn\/wp-content\/uploads\/2019\/09\/1.png 945w, https:\/\/blog.coolcoding.cn\/wp-content\/uploads\/2019\/09\/1-300x123.png 300w, https:\/\/blog.coolcoding.cn\/wp-content\/uploads\/2019\/09\/1-768x316.png 768w\" sizes=\"(max-width: 945px) 100vw, 945px\" \/><\/figure>\n\n\n\n<figure class=\"wp-block-image\"><img loading=\"lazy\" decoding=\"async\" width=\"463\" height=\"567\" src=\"http:\/\/blog.coolcoding.cn\/wp-content\/uploads\/2019\/09\/2.png\" alt=\"\" class=\"wp-image-123\" srcset=\"https:\/\/blog.coolcoding.cn\/wp-content\/uploads\/2019\/09\/2.png 463w, https:\/\/blog.coolcoding.cn\/wp-content\/uploads\/2019\/09\/2-245x300.png 245w\" sizes=\"(max-width: 463px) 100vw, 463px\" \/><\/figure>\n\n\n\n<p>\u8235\u673a\u68d5\u8272\u7ebf\u63a5\u5730\uff0c\u7ea2\u8272\u7ebf\u63a5\u7535\u6e90\uff0c\u6a59\u8272\u7ebf\u4e3a\u4fe1\u53f7\u7ebf\u63a5PIN9<\/p>\n\n\n\n<p><\/p>\n\n\n\n<p>\u7528Arduino \u63a7\u5236\u8235\u673a\u7684\u65b9\u6cd5\u6709\u4e24\u79cd\uff0c\u4e00\u79cd\u662f\u901a\u8fc7Arduino \u7684\u666e\u901a\u6570\u5b57\u4f20\u611f\u5668\u63a5\u53e3\u4ea7\u751f\u5360\u7a7a\u6bd4\u4e0d\u540c\u7684\u65b9\u6ce2\uff0c\u6a21\u62df\u4ea7\u751fPWM \u4fe1\u53f7\u8fdb\u884c\u8235\u673a\u5b9a\u4f4d\uff0c\u7b2c\u4e8c\u79cd\u662f\u76f4\u63a5\u5229\u7528Arduino \u81ea\u5e26\u7684Servo \u51fd\u6570\u8fdb\u884c\u8235\u673a\u7684\u63a7\u5236\uff0c\u8fd9\u79cd\u63a7\u5236\u65b9\u6cd5\u7684\u4f18\u70b9\u5728\u4e8e\u7a0b\u5e8f\u7f16\u5199\uff0c\u7f3a\u70b9\u662f\u53ea\u80fd\u63a7\u52362 \u8def\u8235\u673a\uff0c\u56e0\u4e3aArduino \u81ea\u5e26\u51fd\u6570\u53ea\u80fd\u5229\u7528\u6570\u5b579\u300110 \u63a5\u53e3\u3002Arduino \u7684\u9a71\u52a8\u80fd\u529b\u6709\u9650\uff0c\u6240\u4ee5\u5f53\u9700\u8981\u63a7\u52361 \u4e2a\u4ee5\u4e0a\u7684\u8235\u673a\u65f6\u9700\u8981\u5916\u63a5\u7535\u6e90\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u8235\u673a\u68d5\u8272\u7ebf\u63a5\u5730\uff0c\u7ea2\u8272\u7ebf\u63a5\u7535\u6e90\uff0c\u6a59\u8272\u7ebf\u4e3a\u4fe1\u53f7\u7ebf\u63a5PIN9 \u7528Arduino \u63a7\u5236\u8235\u673a\u7684\u65b9\u6cd5\u6709\u4e24\u79cd\uff0c\u4e00\u79cd\u662f\u901a\u8fc7Ar [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[11],"tags":[],"_links":{"self":[{"href":"https:\/\/blog.coolcoding.cn\/index.php?rest_route=\/wp\/v2\/posts\/121"}],"collection":[{"href":"https:\/\/blog.coolcoding.cn\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog.coolcoding.cn\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog.coolcoding.cn\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.coolcoding.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=121"}],"version-history":[{"count":4,"href":"https:\/\/blog.coolcoding.cn\/index.php?rest_route=\/wp\/v2\/posts\/121\/revisions"}],"predecessor-version":[{"id":2703,"href":"https:\/\/blog.coolcoding.cn\/index.php?rest_route=\/wp\/v2\/posts\/121\/revisions\/2703"}],"wp:attachment":[{"href":"https:\/\/blog.coolcoding.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=121"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.coolcoding.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=121"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.coolcoding.cn\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=121"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}