// for use with an Arduino Pro Micro
// connections are accurate for a Pro Micro, NOT THE UNO
// check the code before making the connections
#include <Joystick.h>
const int totalButtonCount = 11;
const int handleButtons[2] = {0, 1};
const int handleButtonPins[2] = {14, 15};
int lastButtonState[2];
unsigned int throttleState, xAxisState, yAxisState;
Joystick_ LegoThrottle(JOYSTICK_DEFAULT_REPORT_ID, JOYSTICK_TYPE_JOYSTICK,
2, 0,
true, true, false,
false, false, false,
false, true,
false, false, false);
void checkHandleButtons() {
for (int n = 0; n < 2; n++){
int currentButtonState = !digitalRead(handleButtonPins[n]);
if (currentButtonState != lastButtonState[n]){
LegoThrottle.setButton(handleButtons[n], currentButtonState);
lastButtonState[n] = currentButtonState;
}
}
}
void setup() {
for (int n = 0; n < 2; n++){
pinMode(handleButtonPins[n], INPUT_PULLUP);
lastButtonState[n] = 0;
}
LegoThrottle.begin();
}
void loop() {
checkHandleButtons();
throttleState = analogRead(A0);
LegoThrottle.setThrottle(throttleState);
xAxisState = analogRead(A2);
LegoThrottle.setXAxis(xAxisState);
yAxisState = analogRead(A1);
LegoThrottle.setYAxis(yAxisState);
delay(10);
}