// remote control for XCSoar, emulates a keyboard and mouse // hardware is just pushbuttons connected between pins of an Arduino Leonardo and Gnd // for each button press a keystroke or mouse action is sent // code is a wild mix of various snippets found on the net mixed up by an software illiterate // I started from http://forum.arduino.cc/index.php?topic=80913.msg1077713#msg1077713 and // modified by copy & paste trial and error. Kudos to Paul for the great starting point! // // in my remote buttons are arranged in the following pattern // // 1 2 3 //0 4 5 6 // 7 8 9 // // 0 switches between mouse and keyboard emulation // 2, 4, 6, 8 are arrow keys // 7 is ESC, 9 Enter // 1, 3, 5 call screens I want to access directly during flight // #include byte buttons[]={10,0,4,9,2,12,8,3,1,6};//seperate array from definitions to set up the pins #define NUMBUTTONS sizeof(buttons)//gives size of array *helps for adding buttons int debounce_delay = 20; //Debounce delay in milliseconds int rebounce_interval = 5; int button_pressed = 99; boolean Mouse_Active = 0; const int Mouse_Move_Distance = 1; // I really dont see getting around doing this manually Bounce bouncer[] = {//would guess thats what the fuss is about Bounce(10,debounce_delay), Bounce(0,debounce_delay), Bounce(4,debounce_delay), Bounce(9,debounce_delay), Bounce(2,debounce_delay), Bounce(12,debounce_delay), Bounce(8,debounce_delay), Bounce(3,debounce_delay), Bounce(1,debounce_delay), Bounce(6,debounce_delay) }; void setup() { for (byte set=0;set<=NUMBUTTONS;set++){//sets the button pins pinMode(buttons[set],INPUT); digitalWrite(buttons[set],HIGH);//<-comment out this line if not using internal pull ups }//-----------------------------------and change read()==to high if your set up requires // pinMode(LED,OUTPUT);//------------------otherwise event will occure on release // Wait five seconds since the HID drivers need a bit of time to re-mount after upload. delay(5000); Keyboard.begin(); Mouse.begin(); // Serial.begin(57600); // Serial.println("Pushbutton Bounce library test:"); } void loop() { while (button_pressed == 99) { for(int num=0;num