#include "USB.h"
#include "USBHIDKeyboard.h"
USBHIDKeyboard Keyboard;

const int buttonPinUp = 9;      // the number of the pushbutton pin
const int buttonPinRight = 10;  // the number of the pushbutton pin
const int buttonPinDown = 11;   // the number of the pushbutton pin
const int buttonPinLeft = 12;   // the number of the pushbutton pin
const int buttonPinDodge = 14;
const int buttonPinPause = 13;

int buttonStateUp = 0;
int buttonStateRight = 0;
int buttonStateDown = 0;
int buttonStateLeft = 0;
int buttonStateDodge = 0;
int buttonStatePause = 0;

void setup() {
  // put your setup code here, to run once:
  pinMode(buttonPinUp, INPUT);
  pinMode(buttonPinRight, INPUT);
  pinMode(buttonPinDown, INPUT);
  pinMode(buttonPinLeft, INPUT);
  pinMode(buttonPinDodge, INPUT);
  pinMode(buttonPinPause, INPUT);
  Keyboard.begin();
  USB.begin();
  Serial.begin(9600);
}

void loop() {
  // put your main code here, to run repeatedly:
  buttonStateUp = digitalRead(buttonPinUp);
  buttonStateRight = digitalRead(buttonPinRight);
  buttonStateDown = digitalRead(buttonPinDown);
  buttonStateLeft = digitalRead(buttonPinLeft);
  buttonStateDodge = digitalRead(buttonPinDodge);
  buttonStatePause = digitalRead(buttonPinPause);

  if (buttonStateUp == HIGH) {
    Keyboard.press(KEY_UP_ARROW);
  }
  else{
    Keyboard.release(KEY_UP_ARROW);
  }
  if (buttonStateRight == HIGH) {
    Keyboard.press(KEY_RIGHT_ARROW);
  }
  else{
    Keyboard.release(KEY_RIGHT_ARROW);
  }
  if (buttonStateDown == HIGH) {
    Keyboard.press(KEY_DOWN_ARROW);
  }
  else{
    Keyboard.release(KEY_DOWN_ARROW);
  }
  if (buttonStateLeft == HIGH) {
    Keyboard.press(KEY_LEFT_ARROW);
  }
  else{
    Keyboard.release(KEY_LEFT_ARROW);
  }
  if (buttonStateDodge == HIGH) {
    Keyboard.press(KEY_RETURN);
  }
  else{
    Keyboard.release(KEY_RETURN);
  }
  if (buttonStatePause == HIGH) {
    Keyboard.press('p');
  }
  else{
    Keyboard.release('p');
  }
}
