You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+73-31Lines changed: 73 additions & 31 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,8 +1,11 @@
1
1
# Arduino Joystick Library
2
-
#### Version 2.0.5
2
+
3
+
#### Version 2.0.6
4
+
3
5
This library can be used with Arduino IDE 1.6.6 (or above) to add one or more joysticks (or gamepads) to the list of HID devices an [Arduino Leonardo](https://www.arduino.cc/en/Main/ArduinoBoardLeonardo) or [Arduino Micro](https://www.arduino.cc/en/Main/ArduinoBoardMicro) (or any Arduino clone that is based on the ATmega32u4) can support. This library will also work with the [Arduino Due](https://www.arduino.cc/en/Main/ArduinoBoardDue), thanks to [@Palakis](https://github.com/Palakis). A complete list of supported boards can be found in the [Wiki](https://github.com/MHeironimus/ArduinoJoystickLibrary/wiki/Supported-Boards). This will not work with Arduino IDE 1.6.5 (or below) or with non-32u4 based Arduino devices (e.g. Arduino UNO, Arduino MEGA, etc.).
4
6
5
7
## Features
8
+
6
9
The joystick or gamepad can have the following features:
7
10
- Buttons (default: 32)
8
11
- Up to 2 Hat Switches
@@ -15,13 +18,19 @@ The joystick or gamepad can have the following features:
15
18
- Steering (up to 16-bit precision)
16
19
17
20
## Installation Instructions
21
+
18
22
Copy the `Joystick` folder to the Arduino libraries folder. Once the folder has been copied, the Joystick library should appear in the Arduino IDE list of libraries. The examples should also appear in the examples menu in the Arduino IDE.
23
+
19
24
### Microsoft Windows
25
+
20
26
On Microsoft Windows machines, this is typically `%userprofile%\Documents\Arduino\libraries`. The `deploy.bat` file can be executed to install the Joystick folder on Microsoft Windows machines (assuming a default Arduino installation).
27
+
21
28
### Linux
29
+
22
30
On Linux machines, this is typically `$HOME/Arduino/libraries`. The `deploy.sh` file can be executed to install the Joystick folder on Linux machines (assuming a default Arduino installation). [Thanks to @Nihlus (Jarl Gullberg) for his help with this.]
23
31
24
32
## Examples
33
+
25
34
The following example Arduino sketch files are included in this library:
26
35
27
36
-`JoystickTest` - Simple test of the Joystick library. It exercises many of the Joystick library’s functions when pin A0 is grounded.
@@ -35,42 +44,46 @@ The following example Arduino sketch files are included in this library:
35
44
36
45
### Simple example
37
46
38
-
#include <Joystick.h>
39
-
40
-
// Create the Joystick
41
-
Joystick_ Joystick;
42
-
43
-
// Constant that maps the phyical pin to the joystick button.
44
-
const int pinToButtonMap = 9;
45
-
46
-
void setup() {
47
-
// Initialize Button Pins
48
-
pinMode(pinToButtonMap, INPUT_PULLUP);
49
-
50
-
// Initialize Joystick Library
51
-
Joystick.begin();
52
-
}
53
-
54
-
// Last state of the button
55
-
int lastButtonState = 0;
56
-
57
-
void loop() {
58
-
59
-
// Read pin values
60
-
int currentButtonState = !digitalRead(pinToButtonMap);
61
-
if (currentButtonState != lastButtonState)
62
-
{
63
-
Joystick.setButton(0, currentButtonState);
64
-
lastButtonState = currentButtonState;
65
-
}
66
-
67
-
delay(50);
47
+
```C++
48
+
#include<Joystick.h>
49
+
50
+
// Create the Joystick
51
+
Joystick_ Joystick;
52
+
53
+
// Constant that maps the physical pin to the joystick button.
54
+
constint pinToButtonMap = 9;
55
+
56
+
voidsetup() {
57
+
// Initialize Button Pins
58
+
pinMode(pinToButtonMap, INPUT_PULLUP);
59
+
60
+
// Initialize Joystick Library
61
+
Joystick.begin();
62
+
}
63
+
64
+
// Last state of the button
65
+
int lastButtonState = 0;
66
+
67
+
voidloop() {
68
+
69
+
// Read pin values
70
+
int currentButtonState = !digitalRead(pinToButtonMap);
71
+
if (currentButtonState != lastButtonState)
72
+
{
73
+
Joystick.setButton(0, currentButtonState);
74
+
lastButtonState = currentButtonState;
68
75
}
69
76
77
+
delay(50);
78
+
}
79
+
```
80
+
70
81
## Joystick Library API
82
+
71
83
The following API is available if the Joystick library in included in a sketch file.
72
84
73
85
### Joystick\_(...)
86
+
74
87
Constructor used to initialize and setup the Joystick. The following optional parameters are available:
75
88
76
89
-`uint8_t hidReportId` - Default: `0x03` - Indicates the joystick's HID report ID. This value must be unique if you are creating multiple instances of Joystick. Do not use `0x01` or `0x02` as they are used by the built-in Arduino Keyboard and Mouse libraries.
@@ -99,90 +112,119 @@ The following constants define the default values for the constructor parameters
99
112
-`JOYSTICK_DEFAULT_HATSWITCH_COUNT` is set to `2`
100
113
101
114
### Joystick.begin(bool initAutoSendState)
115
+
102
116
Starts emulating a game controller connected to a computer. By default, all methods update the game controller state immediately. If `initAutoSendState` is set to `false`, the `Joystick.sendState` method must be called to update the game controller state.
103
117
104
118
### Joystick.end()
119
+
105
120
Stops the game controller emulation to a connected computer.
Sets the state (`0` or `1`) of the specified button (range: `0` - (`buttonCount - 1`)). The button is the 0-based button number (i.e. button #1 is `0`, button #2 is `1`, etc.). The value is `1` if the button is pressed and `0` if the button is released.
175
213
176
214
### Joystick.pressButton(uint8_t button)
215
+
177
216
Press the indicated button (range: `0` - (`buttonCount - 1`)). The button is the 0-based button number (i.e. button #1 is `0`, button #2 is `1`, etc.).
178
217
179
218
### Joystick.releaseButton(uint8_t button)
219
+
180
220
Release the indicated button (range: `0` - (`buttonCount - 1`)). The button is the 0-based button number (i.e. button #1 is `0`, button #2 is `1`, etc.).
Sets the value of the specified hat switch. The hatSwitch is 0-based (i.e. hat switch #1 is `0` and hat switch #2 is `1`). The value is from 0° to 360°, but in 45° increments. Any value less than 45° will be rounded down (i.e. 44° is rounded down to 0°, 89° is rounded down to 45°, etc.). Set the value to `JOYSTICK_HATSWITCH_RELEASE` or `-1` to release the hat switch.
184
225
185
226
### Joystick.sendState()
227
+
186
228
Sends the updated joystick state to the host computer. Only needs to be called if `AutoSendState` is `false` (see `Joystick.begin` for more details).
187
229
188
230
See the [Wiki](https://github.com/MHeironimus/ArduinoJoystickLibrary/wiki) for more details on things like FAQ, supported boards, testing, etc.
0 commit comments