-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathReadJoystick.ino
71 lines (61 loc) · 1.65 KB
/
ReadJoystick.ino
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
/*
This example shows how to read a joystick value on PS2 Controller.
Function:
readButton(button); // Read button status, it will return corresponding data
// Digital button: 0 = pressed, 1 = released
// Analog button: return a value
Digital button:
PS2_SELECT
PS2_JOYSTICK_LEFT
PS2_JOYSTICK_RIGHT
PS2_START
PS2_UP
PS2_RIGHT
PS2_DOWN
PS2_LEFT
PS2_LEFT_2
PS2_RIGHT_2
PS2_LEFT_1
PS2_RIGHT_1
PS2_TRIANGLE
PS2_CIRCLE
PS2_CROSS
PS2_SQUARE
Analog button:
PS2_JOYSTICK_LEFT_X_AXIS
PS2_JOYSTICK_LEFT_Y_AXIS
PS2_JOYSTICK_RIGHT_X_AXIS
PS2_JOYSTICK_RIGHT_Y_AXIS
PS2_JOYSTICK_LEFT_UP
PS2_JOYSTICK_LEFT_DOWN
PS2_JOYSTICK_LEFT_LEFT
PS2_JOYSTICK_LEFT_RIGHT
PS2_JOYSTICK_RIGHT_UP
PS2_JOYSTICK_RIGHT_DOWN
PS2_JOYSTICK_RIGHT_LEFT
PS2_JOYSTICK_RIGHT_RIGHT
Product page:
Cytron PS2 Shield: http://www.cytron.com.my/p-shield-ps2
PS2 Controller: http://www.cytron.com.my/p-ps-gp-1
CT-UNO: http://www.cytron.com.my/p-ct-uno
Original written by:
Cytron Technologies
Modified:
29/06/15 Idris, Cytron Technologies
*/
#include <SoftwareSerial.h>
#include <Cytron_PS2Shield.h>
Cytron_PS2Shield ps2(2, 3); // SoftwareSerial: Rx and Tx pin
//Cytron_PS2Shield ps2; // HardwareSerial, note:
void setup()
{
ps2.begin(9600); // This baudrate must same with the jumper setting at PS2 shield
Serial.begin(9600); // Set monitor baudrate to 9600
}
void loop()
{
// Open monitor and move left joystick in x axis
// Analog value will be displayed
Serial.println(ps2.readButton(PS2_JOYSTICK_LEFT_X_AXIS));
delay(100);
}