






2、USB 数据线
3、PS游戏手柄模块
4、面包板
5、条线若干




该模块具有两个模拟输出对(对应于X和Y坐标)和一个数字输出,表示是否在Z轴上按下。




连接说明:在连接实物时,PS2操纵杆的VCC端连接Arduino Uno主板的电源的+5V,PS2操纵杆的GND端连接ArduinoUno主板的“接地”,PS2操纵杆URX和URY分别连接ArduinoUno主板的“A0”端和“A1”端,PS2操纵杆的SW端连接“7”端。





第一步:建立电路


第二步:编辑程序(如下)
const int xPin = A0;
const int yPin = A1;
const int btPin = 7;
void setup()
{
pinMode(btPin,INPUT);
digitalWrite(btPin, HIGH);
Serial.begin(9600);
}
void loop()
{
Serial.print("X: ");
Serial.print(analogRead(xPin),DEC);
Serial.print("tY: ");
Serial.print(analogRead(yPin),DEC);
Serial.print("tZ: ");
Serial.println(digitalRead(btPin));
delay(100);
}


第三步:编译代码


第四步:将代码上传到Arduino Uno板



当程序运行之后你会看到一个Arduino Uno板上的绿色LED灯亮起,和一个红色LED灯闪烁。当推动遥感,串行监视器上显示的X轴和Y轴坐标将相应改变;按下按钮,Z的坐标也会相应显示出来
点击二维码关注我们吧
作者:涂友平
.
--end--
后记,小编朋友公司研发了一个游戏化的少儿编程在线课程(5-12岁),游戏化教学结合scratch(一款在线少儿编程工具,类似乐高的积木拼搭),我家娃娃学了几次课,非常喜欢(超预期),16次课才200多块钱,对锻炼孩子的思维能力和动手动力很有帮助。
声明:本文章由爬虫自动处理和转载作为教育分享用途,原作者可通过邮件及时和我们联系处理:freemanzk@qq.com
声明:转载此文是出于传递更多信息之目的。若有来源标注错误或侵犯了您的合法权益,请作者持权属证明与本网联系,我们将及时更正、删除,谢谢。