{"id":2799,"date":"2018-05-20T22:59:24","date_gmt":"2018-05-20T14:59:24","guid":{"rendered":"https:\/\/drho.club\/?p=2163"},"modified":"2018-05-20T22:59:24","modified_gmt":"2018-05-20T14:59:24","slug":"arduino-joy-stick","status":"publish","type":"post","link":"https:\/\/104.es\/index.php\/2018\/05\/20\/arduino-joy-stick\/","title":{"rendered":"\u3010Arduino\u3011\u6416\u687f\u6a21\u7d44\u5be6\u7fd2"},"content":{"rendered":"<p>Arduino\u5728\u9032\u884c\u63a7\u5236\u7684\u6642\u5019\uff0c\u6709\u6642\u5019\u9700\u8981\u900f\u904e\u6309\u9215\uff0c\u6709\u6642\u5019\u5247\u662f\u9700\u8981\u6578\u5b57\u9375\u76e4\uff0c\u82e5\u662f\u540c\u6642\u9700\u8981\u63a7\u5236\u4e8c\u500b\u8ef8\u4ee5\u4e0a\u7684\u8f38\u51fa\u6642\uff0c\u4f7f\u7528\u6416\u687f\u6703\u662f\u975e\u5e38\u65b9\u4fbf\u7684\u9078\u64c7\u3002\u9019\u500b\u5be6\u7fd2\u4e2d\uff0c\u6211\u5011\u8981\u7df4\u7fd2\u7684\u662f\u4e0b\u9762\u9019\u500b\u6416\u687f\u6a21\u7d44\uff1a<\/p>\n<p style=\"text-align: center;\"><a href=\"https:\/\/104.es\/wp-content\/uploads\/2018\/05\/2018-05-20-22.29.00.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-2164\" src=\"https:\/\/104.es\/wp-content\/uploads\/2018\/05\/2018-05-20-22.29.00.jpg\" alt=\"\" width=\"400\" height=\"311\" \/><\/a><\/p>\n<p>\u9019\u500b\u6a21\u7d44\u662f\u5c08\u9580\u8a2d\u8a08\u7d66Arduino\u4f7f\u7528\u7684\uff0c\u6240\u4ee5\u5728\u4f7f\u7528\u4e0a\u975e\u5e38\u5730\u7c21\u4fbf\u3002\u5b83\u67095\u652f\u63a5\u8173\uff0c\u5176\u4e2d+5V\u548cGND\u4e00\u5982\u5f80\u4f8b\uff0c\u76f4\u63a5\u63a5\u5230 Arduino\u4e0a\u7684\u96fb\u6e90\u8f38\u51fa\u5c31\u53ef\u4ee5\u4e86\uff0c\u800c\u5176\u5b83\u76843\u652f\u8f38\u51fa\uff0c\u5206\u5225\u662fVRx\u3001VRy\u3001\u4ee5\u53caSW\uff0c\u5206\u5225\u7528\u4f86\u5075\u5074\u5de6\u53f3\u3001\u4e0a\u4e0b\u3001\u4ee5\u53ca\u662f\u5426\u6309\u4e0b\u53bb\u7684\u958b\u95dc\u3002\u5b83\u5011\u8f38\u51fa\u7684\u662f\u985e\u6bd4\u8a0a\u865f\uff0c\u6700\u5c0f\u503c\u662f0\uff0c\u3ae4\u5927\u503c\u662f1023\u3002\u9023\u63a5\u5716\u5982\u4e0b\u6240\u793a\uff1a<\/p>\n<p><a href=\"https:\/\/104.es\/wp-content\/uploads\/2018\/05\/2018-05-20-22.31.06.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-2165 aligncenter\" src=\"https:\/\/104.es\/wp-content\/uploads\/2018\/05\/2018-05-20-22.31.06.jpg\" alt=\"\" width=\"534\" height=\"600\" \/><\/a><\/p>\n<p>\u5728\u9019\u500b\u4f8b\u5b50\u4e2d\uff0c\u6211\u5011\u5206\u5225\u628aVRx\u3001VRy\u3001\u4ee5\u53caSW\u9023\u63a5\u5230A1, A2,\u00a0\u4ee5\u53caA3\u90193\u500b\u985e\u5225\u8f38\u5165\u57e0\u3002\u9023\u63a5\u5b8c\u6210\u4e4b\u5f8c\uff0c\u53ea\u8981\u76f4\u63a5\u4f7f\u7528analogRead\u53d6\u5f97\u76f8\u5c0d\u61c9\u7684\u8f38\u5165\u6578\u503c\u5c31\u53ef\u4ee5\u4e86\u3002\u7a0b\u5f0f\u5982\u4e0b\uff1a<\/p>\n<p>[code]<br \/>\nvoid setup() {<br \/>\n  Serial.begin(9600);<br \/>\n}<\/p>\n<p>void loop() {<br \/>\n  int vrx, vry, sw;<\/p>\n<p>  vrx = analogRead(A1);<br \/>\n  vry = analogRead(A2);<br \/>\n  sw = analogRead(A3);<\/p>\n<p>  char buf[100];<br \/>\n  sprintf(buf, &quot;VRx=%d, VRy=%d, SW=%d&quot;, vrx, vry, sw);<br \/>\n  Serial.println(buf);<br \/>\n  delay(100);<br \/>\n}<br \/>\n[\/code]<\/p>\n<p>\u7a0b\u5f0f\u5728\u9806\u5229\u5b8c\u6210\u71d2\u9304\u4e4b\u5f8c\uff0c\u5728\u64cd\u4f5c\u6416\u687f\u7684\u904e\u7a0b\u4e2d\uff0c\u76e3\u63a7\u8996\u7a97\u4e2d\u5c31\u53ef\u4ee5\u5f97\u5230\u5982\u4e0b\u6240\u793a\u7684\u8f38\u51fa\uff1a<\/p>\n<p style=\"text-align: center;\"><a href=\"https:\/\/104.es\/wp-content\/uploads\/2018\/05\/2018-05-20_2306.png\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-2169\" src=\"https:\/\/104.es\/wp-content\/uploads\/2018\/05\/2018-05-20_2306.png\" alt=\"\" width=\"501\" height=\"468\" \/><\/a><\/p>\n<p>\u9084\u8a18\u5f97\u4e4b\u524d\u6211\u5011\u4f7f\u7528\u53ef\u8b8a\u96fb\u963b\u63a7\u5236\u4f3a\u670d\u99ac\u9054\u7684\u5be6\u7fd2\u55ce\uff1f\u540c\u5b78\u5011\u662f\u4e0d\u662f\u53ef\u4ee5\u8a66\u8a66\u770b\u5229\u7528\u9019\u500b\u6416\u687f\u6a21\u7d44\u4f86\u63a7\u5236\u662f\u5426\u6703\u66f4\u52a0\u5730\u65b9\u4fbf\u548c\u76f4\u89ba\u5462\uff1f\u5148\u4f86\u770b\u770b\u4ee5\u4e0b\u9019\u500b\u5f71\u7247\uff1a<\/p>\n<p><iframe loading=\"lazy\" title=\"Arduino \u4f7f\u7528\u6416\u687f\u63a7\u5236\u4f3a\u670d\u99ac\u9054\" width=\"640\" height=\"360\" src=\"https:\/\/www.youtube.com\/embed\/ZGz7ys5EnUI?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><\/p>\n<p>\u5047\u8a2d\u6211\u5011\u5206\u5225\u628a\u4f3a\u670d\u99ac\u9054\u7684\u5169\u689d\u4fe1\u865f\u7dda\u9023\u63a5\u5230D10\u548cD11\uff0c\u7136\u5f8c\u628aVRx\u548cVRy\u5206\u5225\u63a5\u5230A1\u548cA2\uff0c\u90a3\u9ebc\u4f7f\u7528\u4ee5\u4e0b\u7684\u7a0b\u5f0f\u5373\u53ef\u5b8c\u6210\u4e0a\u8ff0\u7684\u6548\u679c\uff1a<\/p>\n<p>[code]<br \/>\n#include &lt;Servo.h&gt;<\/p>\n<p>Servo base, head;<\/p>\n<p>void setup() {<br \/>\n  base.attach(10);<br \/>\n  head.attach(11);<br \/>\n}<\/p>\n<p>int base_degree = 90;<br \/>\nint head_degree = 90;<\/p>\n<p>void loop() {<br \/>\n  int vrx = analogRead(A1);<br \/>\n  int vry = analogRead(A2);<br \/>\n  base_degree = map(vrx, 0, 1023, 0, 180);<br \/>\n  head_degree = map(vry, 0, 1023, 0, 180);<br \/>\n  base.write(base_degree);<br \/>\n  head.write(head_degree);<br \/>\n}<\/p>\n<p>[\/code]<\/p>\n<p>\u5f88\u795e\u5947\u5427\uff01<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Arduino\u5728\u9032\u884c\u63a7\u5236\u7684\u6642\u5019\uff0c\u6709\u6642\u5019\u9700\u8981\u900f\u904e\u6309\u9215\uff0c\u6709\u6642\u5019\u5247\u662f\u9700\u8981\u6578\u5b57\u9375\u76e4\uff0c\u82e5\u662f\u540c\u6642\u9700\u8981\u63a7\u5236\u4e8c\u500b\u8ef8\u4ee5\u4e0a\u7684\u8f38\u51fa\u6642\uff0c\u4f7f\u7528\u6416\u687f\u6703\u662f\u975e\u5e38\u65b9\u4fbf\u7684\u9078\u64c7\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":[3],"tags":[],"class_list":["post-2799","post","type-post","status-publish","format-standard","hentry","category-arduino"],"jetpack_featured_media_url":"","jetpack-related-posts":[],"jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/104.es\/index.php\/wp-json\/wp\/v2\/posts\/2799","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=2799"}],"version-history":[{"count":0,"href":"https:\/\/104.es\/index.php\/wp-json\/wp\/v2\/posts\/2799\/revisions"}],"wp:attachment":[{"href":"https:\/\/104.es\/index.php\/wp-json\/wp\/v2\/media?parent=2799"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/104.es\/index.php\/wp-json\/wp\/v2\/categories?post=2799"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/104.es\/index.php\/wp-json\/wp\/v2\/tags?post=2799"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}