Skip to content

Commit eb719cd

Browse files
committed
Reformatted README
- Reformatted README - Use syntax highlighting for code example - Fixed typo
1 parent a4898ce commit eb719cd

File tree

1 file changed

+73
-31
lines changed

1 file changed

+73
-31
lines changed

README.md

Lines changed: 73 additions & 31 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,19 @@ The joystick or gamepad can have the following features:
1518
- Steering (up to 16-bit precision)
1619

1720
## Installation Instructions
21+
1822
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+
1924
### Microsoft Windows
25+
2026
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+
2128
### Linux
29+
2230
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.]
2331

2432
## Examples
33+
2534
The following example Arduino sketch files are included in this library:
2635

2736
- `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:
3544

3645
### Simple example
3746

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+
const int pinToButtonMap = 9;
55+
56+
void setup() {
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+
void loop() {
68+
69+
// Read pin values
70+
int currentButtonState = !digitalRead(pinToButtonMap);
71+
if (currentButtonState != lastButtonState)
72+
{
73+
Joystick.setButton(0, currentButtonState);
74+
lastButtonState = currentButtonState;
6875
}
6976

77+
delay(50);
78+
}
79+
```
80+
7081
## Joystick Library API
82+
7183
The following API is available if the Joystick library in included in a sketch file.
7284

7385
### Joystick\_(...)
86+
7487
Constructor used to initialize and setup the Joystick. The following optional parameters are available:
7588

7689
- `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
99112
- `JOYSTICK_DEFAULT_HATSWITCH_COUNT` is set to `2`
100113

101114
### Joystick.begin(bool initAutoSendState)
115+
102116
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.
103117

104118
### Joystick.end()
119+
105120
Stops the game controller emulation to a connected computer.
106121

107122
### Joystick.setXAxisRange(int16_t minimum, int16_t maximum)
123+
108124
Sets the range of values that will be used for the X axis. Default: `0` to `1023`
109125

110126
### Joystick.setXAxis(int16_t value)
127+
111128
Sets the X axis value. See `setXAxisRange` for the range.
112129

113130
### Joystick.setYAxisRange(int16_t minimum, int16_t maximum)
131+
114132
Sets the range of values that will be used for the Y axis. Default: `0` to `1023`
115133

116134
### Joystick.setYAxis(int16_t value)
135+
117136
Sets the Y axis value. See `setYAxisRange` for the range.
118137

119138
### Joystick.setZAxisRange(int16_t minimum, int16_t maximum)
139+
120140
Sets the range of values that will be used for the Z axis. Default: `0` to `1023`
121141

122142
### Joystick.setZAxis(int16_t value)
143+
123144
Sets the Z axis value. See `setZAxisRange` for the range.
124145

125146
### Joystick.setRxAxisRange(int16_t minimum, int16_t maximum)
147+
126148
Sets the range of values that will be used for the X axis rotation. Default: `0` to `1023`
127149

128150
### Joystick.setRxAxis(int16_t value)
151+
129152
Sets the X axis rotation value. See `setRxAxisRange` for the range.
130153

131154
### Joystick.setRyAxisRange(int16_t minimum, int16_t maximum)
155+
132156
Sets the range of values that will be used for the Y axis rotation. Default: `0` to `1023`
133157

134158
### Joystick.setRyAxis(int16_t value)
159+
135160
Sets the Y axis rotation value. See `setRyAxisRange` for the range.
136161

137162
### Joystick.setRzAxisRange(int16_t minimum, int16_t maximum)
163+
138164
Sets the range of values that will be used for the Z axis rotation. Default: `0` to `1023`
139165

140166
### Joystick.setRzAxis(int16_t value)
167+
141168
Sets the Z axis rotation value. See `setRzAxisRange` for the range.
142169

143170
### Joystick.setRudderRange(int16_t minimum, int16_t maximum)
171+
144172
Sets the range of values that will be used for the Rudder. Default: `0` to `1023`
145173

146174
### Joystick.setRudder(int16_t value)
175+
147176
Sets the Rudder value. See `setRudderRange` for the range.
148177

149178
### Joystick.setThrottleRange(int16_t minimum, int16_t maximum)
179+
150180
Sets the range of values that will be used for the Throttle. Default: `0` to `1023`
151181

152182
### Joystick.setThrottle(int16_t value)
183+
153184
Sets the Throttle value. See `setThrottleRange` for the range.
154185

155186
### Joystick.setAcceleratorRange(int16_t minimum, int16_t maximum)
187+
156188
Sets the range of values that will be used for the Accelerator. Default: `0` to `1023`
157189

158190
### Joystick.setAccelerator(int16_t value)
191+
159192
Sets the Accelerator value. See `setAcceleratorRange` for the range.
160193

161194
### Joystick.setBrakeRange(int16_t minimum, int16_t maximum)
195+
162196
Sets the range of values that will be used for the Brake. Default: `0` to `1023`
163197

164198
### Joystick.setBrake(int16_t value)
199+
165200
Sets the Brake value. See `setBrakeRange` for the range.
166201

167202
### Joystick.setSteeringRange(int16_t minimum, int16_t maximum)
203+
168204
Sets the range of values that will be used for the Steering. Default: `0` to `1023`
169205

170206
### Joystick.setSteering(int16_t value)
207+
171208
Sets the Steering value. See `setSteeringRange` for the range.
172209

173210
### Joystick.setButton(uint8_t button, uint8_t value)
211+
174212
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.
175213

176214
### Joystick.pressButton(uint8_t button)
215+
177216
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.).
178217

179218
### Joystick.releaseButton(uint8_t button)
219+
180220
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.).
181221

182222
### Joystick.setHatSwitch(int8_t hatSwitch, int16_t value)
223+
183224
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.
184225

185226
### Joystick.sendState()
227+
186228
Sends the updated joystick state to the host computer. Only needs to be called if `AutoSendState` is `false` (see `Joystick.begin` for more details).
187229

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

0 commit comments

Comments
 (0)