2-Axis Joystick

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

            2. int JoyStick_Y = A1; // // Analog Pin Y

            3. int JoyStick_button = 8; // IO Pin

            4. void setup()

            5. {

            6. pinMode(JoyStick_X, INPUT);

            7. pinMode(JoyStick_Y, INPUT);

            8. pinMode(JoyStick_button, INPUT_PULLUP);

            9. Serial.begin(9600);

            10. }

            11. void loop()

            12. {

            13. int x, y, button;

            14. x = analogRead(JoyStick_X); // X

            15. y = analogRead(JoyStick_Y); // Y

            16. button = digitalRead(JoyStick_button); //

            17. x = map(x, 0, 1023, -512, 512);

            18. y = map(y, 0, 1023, 512, -512);

            19. Serial.print("X : ");

            20. Serial.print(x, DEC);

            21. Serial.print(" / Y : ");

            22. Serial.print(y, DEC);

            23. Serial.print(" , B : ");

            24. Serial.println(button, DEC);

            25. delay(100);

            26. }