#include <Joystick.h>
// Create a Joystick object
Joystick_ joystick;
// Define the switch pin
const int switchPin = 2;
// Variable to store the switch state
int switchState = 0;
void setup() {
// Initialize the Joystick library
joystick.begin();
// Set the switch pin as INPUT_PULLUP
pinMode(switchPin, INPUT_PULLUP);
}
void loop() {
// Read the switch state
switchState = digitalRead(switchPin);
// Map the switch state to Joystick button states
int buttonState = (switchState == LOW) ? HIGH : LOW;
// Update the Joystick button states based on switch position
joystick.setButton(1, buttonState);
joystick.setButton(2, switchState);
// Send Joystick state
joystick.sendState();
// Add a small delay if needed
delay(10);
}