Библиотека для джойстика
Feb. 22nd, 2021 09:35 pmhttp://mheironimus.blogspot.com/2015/11/arduino-joystick-library.html
Проверка подключения -
Go to the Windows Control Panel and select “Hardware and Sound”.
Then select “Devices and Printers”.
The Arduino Micro or Arduino Leonardo should appear in the list of devices.
Right mouse click on the Arduino Leonardo or Arduino Micro to display the settings menu.
Select “Game controller settings” to get to the “Game Controllers” dialog.
The Arduino Leonardo or Micro should appear in the list of installed game controllers. Select the Arduino Leonardo or Micro and click the Properties button to display the game controller test dialog.
While this dialog has focus, ground pin A0 on the Arduino to activate the test script. The test script will test the game controller functionality in the following order:
32 buttons
throttle and rudder
X and Y Axis
Z Axis
2 Hat Switches
X and Y Axis Rotation
Now that the Joystick library is available to the Arduino IDE, an Arduino Leonardo or Arduino Micro can be used for custom game controller projects. The following describes the complete Arduino Joystick Library API.
Методы -
Joystick.begin(bool initAutoSendState)
Старт всего. По умолчанию вызов методов обновляет состояние джойстика, если initAutoSendState==false, для обновдения надо вызвать Joystick.sendState
Joystick.end()
Stops the game controller emulation to a connected computer.
Joystick.setXAxis(byte value)
Sets the X axis value. Range -127 to 127 (0 is center).
Joystick.setYAxis(byte value)
Sets the Y axis value. Range -127 to 127 (0 is center).
Joystick.setZAxis(byte value)
Sets the Z axis value. Range -127 to 127 (0 is center).
Joystick.setXAxisRotation(int value)
Sets the X axis rotation value. Range 0° to 360°.
Joystick.setyAxisRotation(int value)
Sets the Y axis rotation value. Range 0° to 360°.
Joystick.setZAxisRotation(int value)
Sets the Z axis rotation value. Range 0° to 360°.
Joystick.setButton(byte button, byte value)
Устанавливает кнопку в нажатом или отжатом состоянии
Sets the state (0 or 1) of the specified button (0 - 31). 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.
Joystick.pressButton(byte button)
Кнопка нажата
Press the indicated button (0 - 31). The button is the 0-based button number (i.e. button #1 is 0, button #2 is 1, etc.).
Joystick.releaseButton(byte button)
Кнопка отжата
Release the indicated button (0 - 31). The button is the 0-based button number (i.e. button #1 is 0, button #2 is 1, etc.).
Joystick.setThrottle(byte value)
Sets the throttle value. Range 0 to 255.
Joystick.setRudder(byte value)
Значение руля направления, от 0 до 255
Joystick.setHatSwitch(byte hatSwitch, int value)
Hat - грибообразный переключатель ф-ля джойстик.
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 -1 to release the hat switch.
Joystick.sendState()
Sends the updated joystick state to the host computer. Only needs to be called if AutoSendState is false (see Joystick.begin for more details).
Проверка подключения -
Go to the Windows Control Panel and select “Hardware and Sound”.
Then select “Devices and Printers”.
The Arduino Micro or Arduino Leonardo should appear in the list of devices.
Right mouse click on the Arduino Leonardo or Arduino Micro to display the settings menu.
Select “Game controller settings” to get to the “Game Controllers” dialog.
The Arduino Leonardo or Micro should appear in the list of installed game controllers. Select the Arduino Leonardo or Micro and click the Properties button to display the game controller test dialog.
While this dialog has focus, ground pin A0 on the Arduino to activate the test script. The test script will test the game controller functionality in the following order:
32 buttons
throttle and rudder
X and Y Axis
Z Axis
2 Hat Switches
X and Y Axis Rotation
Now that the Joystick library is available to the Arduino IDE, an Arduino Leonardo or Arduino Micro can be used for custom game controller projects. The following describes the complete Arduino Joystick Library API.
Методы -
Joystick.begin(bool initAutoSendState)
Старт всего. По умолчанию вызов методов обновляет состояние джойстика, если initAutoSendState==false, для обновдения надо вызвать Joystick.sendState
Joystick.end()
Stops the game controller emulation to a connected computer.
Joystick.setXAxis(byte value)
Sets the X axis value. Range -127 to 127 (0 is center).
Joystick.setYAxis(byte value)
Sets the Y axis value. Range -127 to 127 (0 is center).
Joystick.setZAxis(byte value)
Sets the Z axis value. Range -127 to 127 (0 is center).
Joystick.setXAxisRotation(int value)
Sets the X axis rotation value. Range 0° to 360°.
Joystick.setyAxisRotation(int value)
Sets the Y axis rotation value. Range 0° to 360°.
Joystick.setZAxisRotation(int value)
Sets the Z axis rotation value. Range 0° to 360°.
Joystick.setButton(byte button, byte value)
Устанавливает кнопку в нажатом или отжатом состоянии
Sets the state (0 or 1) of the specified button (0 - 31). 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.
Joystick.pressButton(byte button)
Кнопка нажата
Press the indicated button (0 - 31). The button is the 0-based button number (i.e. button #1 is 0, button #2 is 1, etc.).
Joystick.releaseButton(byte button)
Кнопка отжата
Release the indicated button (0 - 31). The button is the 0-based button number (i.e. button #1 is 0, button #2 is 1, etc.).
Joystick.setThrottle(byte value)
Sets the throttle value. Range 0 to 255.
Joystick.setRudder(byte value)
Значение руля направления, от 0 до 255
Joystick.setHatSwitch(byte hatSwitch, int value)
Hat - грибообразный переключатель ф-ля джойстик.
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 -1 to release the hat switch.
Joystick.sendState()
Sends the updated joystick state to the host computer. Only needs to be called if AutoSendState is false (see Joystick.begin for more details).