Created
February 12, 2017 07:36
-
-
Save navin-mohan/3411e3bba7379d50bbd44d94a1b44bc9 to your computer and use it in GitHub Desktop.
Arduino Leonardo Joystick Library
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <Joystick.h> | |
Joystick_ Joystick(JOYSTICK_DEFAULT_REPORT_ID, | |
JOYSTICK_TYPE_MULTI_AXIS, 32, 0, | |
false, false, false, false, false, false, | |
true, true, false, false, false); // only rudder and throttle | |
const int rudderPin = A1; | |
const int throttlePin = A2; | |
void setup(){ | |
Joystick.setThrottleRange(0, 255); | |
Joystick.setRudderRange(0, 255); | |
Joystick.begin(); | |
} | |
unsigned int lastRudderVal = 0; | |
unsigned int lastThrottleVal = 0; | |
void loop(){ | |
unsigned int rudderVal = analogRead(rudderPin); | |
unsigned int throttleVal = analogRead(throttlePin); | |
if(rudderVal != lastRudderVal){ | |
Joystick.setRudder(rudderVal); | |
} | |
if(throttleVal != lastThrottleVal){ | |
Joystick.setThrottle(throttleVal); | |
} | |
delay(50); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment