Skip to content

Instantly share code, notes, and snippets.

@navin-mohan
Created February 12, 2017 07:36
Show Gist options
  • Save navin-mohan/3411e3bba7379d50bbd44d94a1b44bc9 to your computer and use it in GitHub Desktop.
Save navin-mohan/3411e3bba7379d50bbd44d94a1b44bc9 to your computer and use it in GitHub Desktop.
Arduino Leonardo Joystick Library
#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