Arduino程序(修改自参考文献1,只是把串口数据格式变了)
#define JoyStick_X 0
#define JoyStick_Y 1
#define JoyStick_Z 2
void setup(){
Serial.begin(9600);
}
void loop(){
int x,y,z;
x=analogRead(JoyStick_X);
y=analogRead(JoyStick_Y);
z=analogRead(JoyStick_Z);
Serial.print("X:");
Serial.print(x);
Serial.print(":Y:");
Serial.print(y);
if(analogRead(JoyStick_Z)==0){
Serial.println(":B:1");
}else
{
Serial.println(":B:0");
}
delay(1000);
}
串口输出
X:501:Y:503:B:0
X:501:Y:503:B:0
X:501:Y:503:B:0
X:501:Y:503:B:0
X:0:Y:0:B:0
X:0:Y:0:B:0
X:0:Y:0:B:0
X:0:Y:0:B:0
X:501:Y:503:B:0
X:501:Y:503:B:0
X:501:Y:503:B:0
X:502:Y:503:B:0
参考文献: