Joystick con arduino Leonardo y teclas de flecha

#include <Button.h>
#include <Keyboard.h>

const int BOTON_UP = 4;
const int BOTON_DOWN = 5;
const int BOTON_LEFT = 2;
const int BOTON_RIGHT = 3;

const int BOTON_A = 10;
const int BOTON_B = 8;
const int BOTON_X = 9;

const int BOTON_COIN = 11;

const int BOTON_1P = 7;
const int BOTON_2P = 6;

Button btnUp = Button(BOTON_UP,PULLUP);
Button btnDown = Button(BOTON_DOWN,PULLUP);
Button btnLeft = Button(BOTON_LEFT,PULLUP);
Button btnRight = Button(BOTON_RIGHT,PULLUP);

Button btnA = Button(BOTON_A, PULLUP);
Button btnB = Button(BOTON_B, PULLUP);
Button btnX = Button(BOTON_X, PULLUP);

Button btnCoin = Button(BOTON_COIN, PULLUP);

Button btn1P = Button(BOTON_1P, PULLUP);
Button btn2P = Button(BOTON_2P, PULLUP);

void setup() {
  Keyboard.begin();
}

void loop() { 
  if (btnUp.isPressed()) { 
    Keyboard.press(KEY_UP_ARROW);
  } else {
    Keyboard.release(KEY_UP_ARROW);   
  }

  if (btnDown.isPressed()) { 
    Keyboard.press(KEY_DOWN_ARROW);
  } else {
    Keyboard.release(KEY_DOWN_ARROW);   
  }

  if (btnLeft.isPressed()) { 
    Keyboard.press(KEY_LEFT_ARROW);
  } else {
    Keyboard.release(KEY_LEFT_ARROW);   
  }

  if (btnRight.isPressed()) { 
    Keyboard.press(KEY_RIGHT_ARROW);
  } else {
    Keyboard.release(KEY_RIGHT_ARROW);   
  }

  if (btnA.isPressed()) { 
    Keyboard.press(97);
  } else {
    Keyboard.release(97);
  } 

  if (btnB.isPressed()) { 
    Keyboard.press(98);
  } else {
    Keyboard.release(98);
  } 

  if (btnX.isPressed()) { 
    Keyboard.press(120);
  } else {
    Keyboard.release(120);
  } 

  if (btnCoin.isPressed()) { 
    Keyboard.press(53);
  } else {
    Keyboard.release(53);
  } 

  if (btn1P.isPressed()) { 
    Keyboard.press(49);
  } else {
    Keyboard.release(49);
  } 

  if (btn2P.isPressed()) { 
    Keyboard.press(50);
  } else {
    Keyboard.release(50);
  } 
}












---------------------------------------------------------------------------------------------------------------
VERSION ANTERIOR


#include <Button.h>
#include <Keyboard.h>

const int BOTON_UP = 4;
const int BOTON_DOWN = 5;
const int BOTON_LEFT = 2;
const int BOTON_RIGHT = 3;

const int BOTON_X = 10;
const int BOTON_Y = 8;
const int BOTON_Z = 9;

const int BOTON_A = 11;
const int BOTON_B = 12;

const int BOTON_1P = 7;
const int BOTON_2P = 6;

Button btnUp = Button(BOTON_UP,PULLUP);
Button btnDown = Button(BOTON_DOWN,PULLUP);
Button btnLeft = Button(BOTON_LEFT,PULLUP);
Button btnRight = Button(BOTON_RIGHT,PULLUP);

Button btnX = Button(BOTON_X, PULLUP);
Button btnY = Button(BOTON_Y, PULLUP);
Button btnZ = Button(BOTON_Z, PULLUP);

Button btnA = Button(BOTON_A, PULLUP);
Button btnB = Button(BOTON_B, PULLUP);

Button btn1P = Button(BOTON_1P, PULLUP);
Button btn2P = Button(BOTON_2P, PULLUP);

void setup() {
  Keyboard.begin();
}

void loop() { 
  if (btnUp.isPressed()) {   
    Keyboard.press(KEY_UP_ARROW);
  } else {
    Keyboard.release(KEY_UP_ARROW);     
  }

  if (btnDown.isPressed()) {   
    Keyboard.press(KEY_DOWN_ARROW);
  } else {
    Keyboard.release(KEY_DOWN_ARROW);     
  }

  if (btnLeft.isPressed()) {   
    Keyboard.press(KEY_LEFT_ARROW);
  } else {
    Keyboard.release(KEY_LEFT_ARROW);     
  }

  if (btnRight.isPressed()) {   
    Keyboard.press(KEY_RIGHT_ARROW);
  } else {
    Keyboard.release(KEY_RIGHT_ARROW);     
  }

/*  if (btnEnter.isPressed()) {   
    Keyboard.press(90);
  } else {
    Keyboard.release(90);
  } 
*/
  if (btnX.isPressed()) {   
    Keyboard.press(65);
  } else {
    Keyboard.release(65);
  } 

  if (btnY.isPressed()) {   
    Keyboard.press(66);
  } else {
    Keyboard.release(66);
  } 

  if (btnZ.isPressed()) {   
    Keyboard.press(88);
  } else {
    Keyboard.release(88);
  } 

  if (btnA.isPressed()) {   
    Keyboard.press(53);
  } else {
    Keyboard.release(53);
  } 

/*
  if (btnB.isPressed()) {   
    Keyboard.press(11);
  } else {
    Keyboard.release(11);
  } 
*/
  if (btn1P.isPressed()) {   
    Keyboard.press(49);
  } else {
    Keyboard.release(49);
  } 

  if (btn2P.isPressed()) {   
    Keyboard.press(50);
  } else {
    Keyboard.release(50);
  } 


}