天天看点

joystick遥杆(PS遥杆) 的使用方法

joystick遥杆(PS遥杆) 的使用方法

GND --- GND

+5V  --- 5V

VRx --- A0

VRy --- A1

SW --- D2

当按下按钮的时候,SW会输出低电平。

int sw =2;

void setup() {

Serial.begin(9600);

pinMode(sw,INPUT);

digitalWrite(sw,HIGH); //默认给2号引脚设置高电平,当按钮按下时,2号引脚度数变为0.

}

void loop() {

  int x = analogRead(A0);

  int y = analogRead(A1);

  int z = digitalRead(sw);

  if(x<500)

  {

    Serial.println("向左");

    }

   if(x>600)

   {

    Serial.println("向右");

    } 

     if(y<500)

  {

    Serial.println("向上");

    }

   if(y>600)

   {

    Serial.println("向下");

    } 

   if(x>500 &&x<600 &&y>500 &&y<600)  

   {

    Serial.println("原地不动");

    }

     delay(500);

}

joystick遥杆(PS遥杆) 的使用方法

继续阅读