{"id":1159,"date":"2016-11-17T10:49:27","date_gmt":"2016-11-17T02:49:27","guid":{"rendered":"https:\/\/www.webteach.tw\/?p=1159"},"modified":"2016-11-17T10:49:27","modified_gmt":"2016-11-17T02:49:27","slug":"arduino-%e8%97%8d%e8%8a%bd-%e5%9d%a6%e5%85%8b%e8%bb%8a-ps2%e6%90%96%e6%a1%bf-%e7%99%bc%e9%80%81%e7%ab%af-%e7%a8%8b%e5%bc%8f%e7%a2%bc","status":"publish","type":"post","link":"https:\/\/www.webteach.tw\/?p=1159","title":{"rendered":"[ Arduino ] &#8211; \u85cd\u82bd \u5766\u514b\u8eca -PS2\u6416\u687f \u767c\u9001\u7aef \u7a0b\u5f0f\u78bc"},"content":{"rendered":"<p>\t\t\t\t[javascript]<br \/>\n#include  &lt;SoftwareSerial.h&gt;<br \/>\nSoftwareSerial BTSerial(10, 11); \/\/ RX | TX<br \/>\nint xpotPin = 14;  \/\/\u8bbe\u7f6e\u6a21\u62df\u53e30\u4e3aX\u7684\u4fe1\u53f7\u8f93\u5165\u7aef\u53e3<br \/>\nint ypotPin = 15;  \/\/\u8bbe\u7f6e\u6a21\u62df\u53e31\u4e3aY\u7684\u4fe1\u53f7\u8f93\u5165\u7aef\u53e3<br \/>\nint xval=0;<br \/>\nint yval=0;<br \/>\nvoid setup()<br \/>\n{<br \/>\n  Serial.begin(9600);<br \/>\n  Serial.println(&quot;Enter AT commands:&quot;);<br \/>\n  BTSerial.begin(9600);<br \/>\n  pinMode(xpotPin,INPUT);<br \/>\n  pinMode(ypotPin,INPUT);<br \/>\n}<br \/>\nvoid loop(){<br \/>\n \/\/ if (BTSerial.available())<br \/>\n \/\/   Serial.write(BTSerial.read());<br \/>\n \/\/ if (Serial.available())<br \/>\n \/\/   BTSerial.write(Serial.read());<br \/>\nint  x = analogRead(xpotPin);   \/\/xval\u53d8\u91cf\u4e3a\u4ece0\u4fe1\u53f7\u53e3\u8bfb\u53d6\u5230\u7684\u6570\u503c<br \/>\nint  y = analogRead(ypotPin);   \/\/yval\u53d8\u91cf\u4e3a\u4ece1\u4fe1\u53f7\u53e3\u8bfb\u53d6\u5230\u7684\u6570\u503c<br \/>\n Serial.println(&quot;x:&quot;);<br \/>\n Serial.println(x);<br \/>\n Serial.println(&quot;y:&quot;);<br \/>\n Serial.println(y);<br \/>\n \/\/ BTSerial.write(&#8216;s&#8217;);<br \/>\n \/\/ delay(2000);<br \/>\n \/\/ BTSerial.write(&#8216;s&#8217;);<br \/>\n if(x&gt;340 &amp;&amp; x &lt;350 &amp;&amp; y &gt;340 &amp;&amp; y&lt;346){BTSerial.write(&#8216;s&#8217;);}<br \/>\n if(y==0){BTSerial.write(&#8216;f&#8217;);  Serial.println(&quot;f&quot;);}\/\/\u524d<br \/>\n if(y&gt;670){BTSerial.write(&#8216;b&#8217;);}\/\/\u5f8c<br \/>\n if(x==0){BTSerial.write(&#8216;l&#8217;);}\/\/\u5de6<br \/>\n if(x&gt;680){BTSerial.write(&#8216;r&#8217;); Serial.println(&quot;r&quot;);}\/\/\u53f3<br \/>\n  delay(300);<br \/>\n}<br \/>\n[\/javascript]\t\t<\/p>\n","protected":false},"excerpt":{"rendered":"<p>[javascript] #include &#038;lt&#8230;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[19],"tags":[],"class_list":["post-1159","post","type-post","status-publish","format-standard","hentry","category-arduino"],"_links":{"self":[{"href":"https:\/\/www.webteach.tw\/index.php?rest_route=\/wp\/v2\/posts\/1159","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.webteach.tw\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.webteach.tw\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.webteach.tw\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.webteach.tw\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=1159"}],"version-history":[{"count":0,"href":"https:\/\/www.webteach.tw\/index.php?rest_route=\/wp\/v2\/posts\/1159\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.webteach.tw\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=1159"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.webteach.tw\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=1159"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.webteach.tw\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=1159"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}