Arduino Simple Example 4_PS2 Game Joystick

1) Description:

The PS2 game dual-axis joystick sensor module is made of metal PS2 joystick potentiometer, with (X,Y) 2-axis analog output, (Z) 1-way button digital output. Interactive works such as remote controls can be made.
When the SW pin is pressed down, it outputs low level, otherwise it outputs high level

2) Hardware:

PS2 game joystick joystick, Arduino uno, DuPont line

3) Connection:

5V to Arduino 5V
GND to Arduino GND
URx to Analog 0
URy to Analog 1
SW to Digital 2

4) Code

    #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);    
    }  

Guess you like

Origin blog.csdn.net/m0_73391543/article/details/127906801