操纵杆"/>
arduino控制ps2操纵杆
一、实物连接
二、代码实现
const int xPin = A0; //X attach to A0
const int yPin = A1; //Y attach to A1
const int btPin = 7; //Bt attach to digital 7void setup()
{pinMode(btPin,INPUT); //set btpin as INPUTdigitalWrite(btPin, HIGH); //and HIGHSerial.begin(9600); //initialize serial
}void loop()
{Serial.print("X: ");//print "X: "Serial.print(analogRead(xPin),DEC); //read the value of A0 and print it in decimalSerial.print("\tY: "); //print "Y: "Serial.print(analogRead(yPin),DEC); //read the value of A1 and print it in decimalSerial.print("\tZ: "); //print "Z: "Serial.println(digitalRead(btPin)); read the value of pin7 and print itdelay(100);//delay 100ms
}
更多推荐
arduino控制ps2操纵杆
发布评论