Joystick Module XY & Z-axis
- Was RM14.00
-
RM5.00
- Product Code: Joystick Module XY
- Availability: In Stock
PS2 game joystick axis sensor module consists of using original quality metal PS2 joystick potentiometer system For the (X, Y) a 2-axis analog output and for (Z) 1 digital output channel button.
Features
Package Content
/* Example sketch for the Addicore 2-Axis Joystick with push switch Wire the Addicore joystick to your Arduino as detailed below. Then Upload this code to your Arduino and open the Serial Monitor on your computer to see the states of the joystick axes and push switch. (Make sure the baud is set to 9600 in your Serial Monitor) Wiring: Joystick ---> Arduino GND GND +5V 5V VRx A0 VRy A1 SW 3 Created: by Craig Thompson, December 15, 2014 */ //Arduino pins attached to joystick #define joystick_switch_pin 3 #define joystick_x_pin A0 #define joystick_y_pin A1 // the setup routine runs once when you press reset: void setup() { Serial.begin(9600); // initialize serial communication at 9600 bits per second: pinMode(joystick_switch_pin, INPUT_PULLUP); // Enable the pullup resistor on pin 3 for the joystick's switch signal } // the loop routine runs over and over again forever: void loop() { int X_Axis = analogRead(joystick_x_pin); // read the x axis value int Y_Axis = analogRead(joystick_y_pin); // read the x axis value Y_Axis = map(Y_Axis, 0, 1023, 1023, 0); // invert the input from the y axis so that pressing the stick forward gives larger values int SwitchValue = digitalRead(joystick_switch_pin); // read the state of the switch SwitchValue = map(SwitchValue, 0, 1, 1, 0); // invert the input from the switch to be high when pressed // print out the values you read: Serial.print("Switch: "); Serial.print(SwitchValue); Serial.print(" X_Axis: "); Serial.print(X_Axis); Serial.print(" Y_Axis: "); Serial.println(Y_Axis); delay(10); // delay in between reads }