From 822e08be3d54ea42f184b6cdd78dfb38848115f2 Mon Sep 17 00:00:00 2001 From: DAProgs Date: Wed, 14 Jan 2026 14:20:41 -0500 Subject: [PATCH] Upload files to "libraries/ArduinoJoystickLibrary/examples/JoystickKeyboard" --- .../JoystickKeyboard/JoystickKeyboard.ino | 63 +++++++++++++++++++ 1 file changed, 63 insertions(+) create mode 100644 libraries/ArduinoJoystickLibrary/examples/JoystickKeyboard/JoystickKeyboard.ino diff --git a/libraries/ArduinoJoystickLibrary/examples/JoystickKeyboard/JoystickKeyboard.ino b/libraries/ArduinoJoystickLibrary/examples/JoystickKeyboard/JoystickKeyboard.ino new file mode 100644 index 0000000..d1670c9 --- /dev/null +++ b/libraries/ArduinoJoystickLibrary/examples/JoystickKeyboard/JoystickKeyboard.ino @@ -0,0 +1,63 @@ +// Simple example application that shows how to read four Arduino +// digital pins and map them to buttons on a joystick or keys on a +// keyboard uisng the Arduino Joystick and Keyboard libraries. +// +// The digital pins 9, 10, 11, and 12 are grounded when they are pressed. +// +// NOTE: This sketch file is for use with Arduino Leonardo and +// Arduino Micro only. +// +// Pin 9 = Joystick Button 0 +// Pin 10 = Joystick Button 1 +// Pin 11 = 1 key on the Keyboard +// Pin 12 = 2 key on the Keyboard +// +// by Matthew Heironimus +// 2016-05-13 +//-------------------------------------------------------------------- + +#include +#include + +Joystick_ Joystick; + +void setup() { + // Initialize Button Pins + pinMode(9, INPUT_PULLUP); + pinMode(10, INPUT_PULLUP); + pinMode(11, INPUT_PULLUP); + pinMode(12, INPUT_PULLUP); + + // Initialize Joystick Library + Joystick.begin(); +} + +// Constant that maps the phyical pin to the joystick button. +const int pinToButtonMap = 9; + +// Last state of the button +int lastButtonState[4] = {0,0,0,0}; + +void loop() { + + // Read pin values + for (int index = 0; index < 4; index++) + { + int currentButtonState = !digitalRead(index + pinToButtonMap); + if (currentButtonState != lastButtonState[index]) + { + if (index < 2) { + Joystick.setButton(index, currentButtonState); + lastButtonState[index] = currentButtonState; + } else { + if (currentButtonState) { + Keyboard.write(47 + index); + delay(500); + } + } + } + } + + delay(100); +} +