04_Arduino简单实例之四_PS2游戏摇杆
Arduino 简单实例之四 _PS2 游戏摇杆
#Arduino
1) 说明:
PS2 游戏双轴摇杆传感器模块由采用金属 PS2 摇杆电位器制作,具有 (X,Y)2 轴模拟输出,(Z) 1 路按钮数字输出。可制作遥控器等互动作品。 SW 引脚按下去时输出低电平,反之输出高电平
2) 硬件:
PS2 游戏摇杆 joystick,Arduino uno,杜邦线
3) 连接:
5V 接 Arduino 5V
GND 接 Arduino GND
URx 接 Analog 0
URy 接 Analog 1
SW 接 Digital 2
[](https://img-
blog.csdn.net/20170220130702165?watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQveGlleWFuMDgxMQ==/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/Center)
4) 代码
#define PIN_X 0
#define PIN_Y 1
#define PIN_Z 2
void setup() {
pinMode(PIN_X, INPUT);
pinMode(PIN_Y, INPUT);
pinMode(PIN_Z, INPUT);
Serial.begin(9600);
}
void loop() {
int x,y,z;
x=analogRead(PIN_X);
y=analogRead(PIN_Y);
z=analogRead(PIN_Z);
Serial.print("X=");
Serial.print(x);
Serial.print("\tY=");
Serial.print(y);
Serial.print("\tZ=");
Serial.println(z);
delay(1000);
}
(请注意:因各厂商硬件不同,引脚位置可能有差异,具体请见硬件说明书)
All articles in this blog are licensed under CC BY-NC-SA 4.0 unless stating additionally.