2-Axis Joystick

    This page is to Setup and Config 2-Axis Joystick
 

Hardware and Software

Hardware 
    
2-Axis Joystick

Software 
    Arduino IDE


Sanki Notes

  • Count Range : 0 to 1024 in DEC and Button 1/0
  • Button : D8
  • X : A0
  • Y : A1

Examples

          This example is ..........

  1. int JoyStick_X = A0; // Analog Pin  X
    int JoyStick_Y = A1; // // Analog Pin  Y
    int JoyStick_button = 8; // IO Pin

    void setup()
    {
        pinMode(JoyStick_X, INPUT);
        pinMode(JoyStick_Y, INPUT);
        pinMode(JoyStick_button, INPUT_PULLUP);

        Serial.begin(9600);
    }

    void loop()
    {
        int x, y, button;

        x = analogRead(JoyStick_X); //  X
        y = analogRead(JoyStick_Y); //  Y

        button = digitalRead(JoyStick_button); // 

        x = map(x, 0, 1023, -512, 512);
        y = map(y, 0, 1023, 512, -512);
        
        Serial.print("X : ");
        Serial.print(x, DEC);
        Serial.print(" / Y : ");
        Serial.print(y, DEC);
        Serial.print(" , B : ");
        Serial.println(button, DEC);

        delay(100);
    }