Skip to content

Commit 96fab9b

Browse files
authored
Merge pull request MHeironimus#151 from MHeironimus/community-updates
Community Updates 1
2 parents 81c7109 + a648e7e commit 96fab9b

File tree

21 files changed

+129
-74
lines changed

21 files changed

+129
-74
lines changed

.github/ISSUE_TEMPLATE/bug_report.md

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
---
2+
name: Bug report
3+
about: Create a report to help us improve
4+
title: ''
5+
labels: ''
6+
assignees: ''
7+
8+
---
9+
10+
## Description of Issue
11+
Enter description of issue here. Include a clear and concise description of what you expected to happen and what actually happened.
12+
13+
## Technical Details
14+
15+
- Arduino Board (e.g. Arduino Leonardo):
16+
- Host OS (e.g. Windows 10):
17+
- Arduino IDE Version (e.g. 1.8.3):
18+
19+
## Sketch File that Reproduces Issue
20+
21+
~~~
22+
Sketch file goes here (if applicable)
23+
~~~
24+
25+
## Wiring Details
26+
Any pin wiring details that may be relevant.
27+
28+
## Additional context
29+
Add any other context about the problem here.
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
---
2+
name: Feature request
3+
about: Suggest an idea for this project
4+
title: ''
5+
labels: ''
6+
assignees: ''
7+
8+
---
9+
10+
**Describe your feature request**
11+
A clear and concise description of what you feature you would like to see added to the library.
12+
13+
**Additional context**
14+
Add any other context or screenshots about the feature request here.
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
---
2+
name: Support new board
3+
about: Suggest a new board to support
4+
title: ''
5+
labels: ''
6+
assignees: ''
7+
8+
---
9+
10+
Please indicate which board you would like to see supported.

README.md

Lines changed: 73 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
11
# Arduino Joystick Library
2-
#### Version 2.0.5
2+
3+
#### Version 2.0.6
4+
35
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.).
46

57
## Features
8+
69
The joystick or gamepad can have the following features:
710
- Buttons (default: 32)
811
- Up to 2 Hat Switches
@@ -15,13 +18,14 @@ The joystick or gamepad can have the following features:
1518
- Steering (up to 16-bit precision)
1619

1720
## Installation Instructions
18-
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.
19-
### Microsoft Windows
20-
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).
21-
### Linux
22-
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.]
21+
22+
The following instructions can be used to install the latest version of the library in the Arduino IDE (thanks to [@per1234](https://github.com/per1234) for this update):
23+
24+
1. Download https://github.com/MHeironimus/ArduinoJoystickLibrary/archive/master.zip
25+
2. In the Arduino IDE, select `Sketch` > `Include Library` > `Add .ZIP Library...`. Browse to where the downloaded ZIP file is located and click `Open`. The Joystick library's examples will now appear under `File` > `Examples` > `Joystick`.
2326

2427
## Examples
28+
2529
The following example Arduino sketch files are included in this library:
2630

2731
- `JoystickTest` - Simple test of the Joystick library. It exercises many of the Joystick library’s functions when pin A0 is grounded.
@@ -35,42 +39,46 @@ The following example Arduino sketch files are included in this library:
3539

3640
### Simple example
3741

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);
42+
```C++
43+
#include <Joystick.h>
44+
45+
// Create the Joystick
46+
Joystick_ Joystick;
47+
48+
// Constant that maps the physical pin to the joystick button.
49+
const int pinToButtonMap = 9;
50+
51+
void setup() {
52+
// Initialize Button Pins
53+
pinMode(pinToButtonMap, INPUT_PULLUP);
54+
55+
// Initialize Joystick Library
56+
Joystick.begin();
57+
}
58+
59+
// Last state of the button
60+
int lastButtonState = 0;
61+
62+
void loop() {
63+
64+
// Read pin values
65+
int currentButtonState = !digitalRead(pinToButtonMap);
66+
if (currentButtonState != lastButtonState)
67+
{
68+
Joystick.setButton(0, currentButtonState);
69+
lastButtonState = currentButtonState;
6870
}
6971

72+
delay(50);
73+
}
74+
```
75+
7076
## Joystick Library API
77+
7178
The following API is available if the Joystick library in included in a sketch file.
7279

7380
### Joystick\_(...)
81+
7482
Constructor used to initialize and setup the Joystick. The following optional parameters are available:
7583

7684
- `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 +107,119 @@ The following constants define the default values for the constructor parameters
99107
- `JOYSTICK_DEFAULT_HATSWITCH_COUNT` is set to `2`
100108

101109
### Joystick.begin(bool initAutoSendState)
110+
102111
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.
103112

104113
### Joystick.end()
114+
105115
Stops the game controller emulation to a connected computer.
106116

107117
### Joystick.setXAxisRange(int16_t minimum, int16_t maximum)
118+
108119
Sets the range of values that will be used for the X axis. Default: `0` to `1023`
109120

110121
### Joystick.setXAxis(int16_t value)
122+
111123
Sets the X axis value. See `setXAxisRange` for the range.
112124

113125
### Joystick.setYAxisRange(int16_t minimum, int16_t maximum)
126+
114127
Sets the range of values that will be used for the Y axis. Default: `0` to `1023`
115128

116129
### Joystick.setYAxis(int16_t value)
130+
117131
Sets the Y axis value. See `setYAxisRange` for the range.
118132

119133
### Joystick.setZAxisRange(int16_t minimum, int16_t maximum)
134+
120135
Sets the range of values that will be used for the Z axis. Default: `0` to `1023`
121136

122137
### Joystick.setZAxis(int16_t value)
138+
123139
Sets the Z axis value. See `setZAxisRange` for the range.
124140

125141
### Joystick.setRxAxisRange(int16_t minimum, int16_t maximum)
142+
126143
Sets the range of values that will be used for the X axis rotation. Default: `0` to `1023`
127144

128145
### Joystick.setRxAxis(int16_t value)
146+
129147
Sets the X axis rotation value. See `setRxAxisRange` for the range.
130148

131149
### Joystick.setRyAxisRange(int16_t minimum, int16_t maximum)
150+
132151
Sets the range of values that will be used for the Y axis rotation. Default: `0` to `1023`
133152

134153
### Joystick.setRyAxis(int16_t value)
154+
135155
Sets the Y axis rotation value. See `setRyAxisRange` for the range.
136156

137157
### Joystick.setRzAxisRange(int16_t minimum, int16_t maximum)
158+
138159
Sets the range of values that will be used for the Z axis rotation. Default: `0` to `1023`
139160

140161
### Joystick.setRzAxis(int16_t value)
162+
141163
Sets the Z axis rotation value. See `setRzAxisRange` for the range.
142164

143165
### Joystick.setRudderRange(int16_t minimum, int16_t maximum)
166+
144167
Sets the range of values that will be used for the Rudder. Default: `0` to `1023`
145168

146169
### Joystick.setRudder(int16_t value)
170+
147171
Sets the Rudder value. See `setRudderRange` for the range.
148172

149173
### Joystick.setThrottleRange(int16_t minimum, int16_t maximum)
174+
150175
Sets the range of values that will be used for the Throttle. Default: `0` to `1023`
151176

152177
### Joystick.setThrottle(int16_t value)
178+
153179
Sets the Throttle value. See `setThrottleRange` for the range.
154180

155181
### Joystick.setAcceleratorRange(int16_t minimum, int16_t maximum)
182+
156183
Sets the range of values that will be used for the Accelerator. Default: `0` to `1023`
157184

158185
### Joystick.setAccelerator(int16_t value)
186+
159187
Sets the Accelerator value. See `setAcceleratorRange` for the range.
160188

161189
### Joystick.setBrakeRange(int16_t minimum, int16_t maximum)
190+
162191
Sets the range of values that will be used for the Brake. Default: `0` to `1023`
163192

164193
### Joystick.setBrake(int16_t value)
194+
165195
Sets the Brake value. See `setBrakeRange` for the range.
166196

167197
### Joystick.setSteeringRange(int16_t minimum, int16_t maximum)
198+
168199
Sets the range of values that will be used for the Steering. Default: `0` to `1023`
169200

170201
### Joystick.setSteering(int16_t value)
202+
171203
Sets the Steering value. See `setSteeringRange` for the range.
172204

173205
### Joystick.setButton(uint8_t button, uint8_t value)
206+
174207
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.
175208

176209
### Joystick.pressButton(uint8_t button)
210+
177211
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.).
178212

179213
### Joystick.releaseButton(uint8_t button)
214+
180215
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.).
181216

182217
### Joystick.setHatSwitch(int8_t hatSwitch, int16_t value)
218+
183219
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.
184220

185221
### Joystick.sendState()
222+
186223
Sends the updated joystick state to the host computer. Only needs to be called if `AutoSendState` is `false` (see `Joystick.begin` for more details).
187224

188225
See the [Wiki](https://github.com/MHeironimus/ArduinoJoystickLibrary/wiki) for more details on things like FAQ, supported boards, testing, etc.

deploy.bat

Lines changed: 0 additions & 3 deletions
This file was deleted.

deploy.sh

Lines changed: 0 additions & 5 deletions
This file was deleted.

0 commit comments

Comments
 (0)