error: a function-definition is not allowed here

Hi, I'm trying to make a fight stick for a MAME cabinet I'm building. I know that Unojoy seems to be the preferred way of doing this but I couldn't find much about compatibility with Linux. I'm trying to get my Arduino Micro to give keyboard inputs, my previous approach was to take apart a keyboard and use the pcb out of it but this way is more fun and I'm learning more. I have the following code but its giving me these error messages.

fight.ino: In function 'void loop()':
fight:118: error: a function-definition is not allowed here before '{' token
fight:134: error: expected `}' at end of input

That last line repeats probably 15 times. Any help would be much appreciated.

#define	KEY_RIGHT	0x4F  // Right arrow
#define	KEY_LEFT	0x50  // Left arrow
#define	KEY_DOWN	0x51  // Down arrow
#define	KEY_UP	        0x52  // Up arrow

//int horzPin = A0;  // Analog output of horizontal joystick pin
//int vertPin = A1;  // Analog output of vertical joystick pin
int Button1 = 1;  // select pin of Button 1
int Button2 = 2;  // select pin of Button 2
int Button3 = 3;  // select pin of Button 3
int Button4 = 4;  // select pin of Button 4
int Button5 = 5;  // select pin of Button 5
int Button6 = 6;  // select pin of Button 6
int Button7 = 7;  // select pin of Button 7
int Button8 = 8;  // select pin of Button 8
int Button9 = 9;  // select pin of Button 9
int Button10 = 10;  // select pin of Button 10
int up = 11;
int down = 12;
int left = 13;
int right = 14;


void setup()
{

  pinMode(Button1, INPUT);  // set Button select pin as input
  digitalWrite(Button1, HIGH);  // Pull Button select pin high
  pinMode(Button2, INPUT);  // set Button select pin as input
  digitalWrite(Button2, HIGH);  // Pull Button select pin high
  pinMode(Button3, INPUT);  // set Button select pin as input
  digitalWrite(Button3, HIGH);  // Pull Button select pin high
  pinMode(Button4, INPUT);  // set Button select pin as input
  digitalWrite(Button4, HIGH);  // Pull Button select pin high
  pinMode(Button5, INPUT);  // set Button select pin as input
  digitalWrite(Button5, HIGH);  // Pull Button select pin high
  pinMode(Button6, INPUT);  // set Button select pin as input
  digitalWrite(Button6, HIGH);  // Pull Button select pin high
  pinMode(Button7, INPUT);  // set Button select pin as input
  digitalWrite(Button7, HIGH);  // Pull Button select pin high
  pinMode(Button8, INPUT);  // set Button select pin as input
  digitalWrite(Button8, HIGH);  // Pull Button select pin high
  pinMode(Button9, INPUT);  // set Button select pin as input
  digitalWrite(Button9, HIGH);  // Pull Button select pin high
  pinMode(Button10, INPUT);  // set Button select pin as input
  digitalWrite(Button10, HIGH);  // Pull Button select pin high
    pinMode(up, INPUT);  // set Button select pin as input
  digitalWrite(up, HIGH);  // Pull Button select pin high
    pinMode(down, INPUT);  // set Button select pin as input
  digitalWrite(down, HIGH);  // Pull Button select pin high
    pinMode(left, INPUT);  // set Button select pin as input
  digitalWrite(left, HIGH);  // Pull Button select pin high
    pinMode(right, INPUT);  // set Button select pin as input
  digitalWrite(right, HIGH);  // Pull Button select pin high
  delay(1000);  // short delay to let outputs settle


}

void loop()
{

  if (!digitalRead(Button1)){ Keyboard.press('1');}else{Keyboard.release('1');
  if (!digitalRead(Button2)){ Keyboard.press('2');}else{Keyboard.release('2');
  if (!digitalRead(Button3)){ Keyboard.press('3');}else{Keyboard.release('3');
  if (!digitalRead(Button4)){ Keyboard.press('4');}else{Keyboard.release('4');
  if (!digitalRead(Button5)){ Keyboard.press('5');}else{Keyboard.release('5');
  if (!digitalRead(Button6)){ Keyboard.press('6');}else{Keyboard.release('6');
  if (!digitalRead(Button7)){ Keyboard.press('7');}else{Keyboard.release('7');
  if (!digitalRead(Button8)){ Keyboard.press('8');}else{Keyboard.release('8');
  if (!digitalRead(Button9)){ Keyboard.press('9');}else{Keyboard.release('9');
  if (!digitalRead(Button10)){ Keyboard.press('0');}else{Keyboard.release('0');
  if (!digitalRead(up)){ Keyboard.press(KEY_UP);}else{Keyboard.release(KEY_UP);
  if (!digitalRead(down)){ Keyboard.press(KEY_DOWN);}else{Keyboard.release(KEY_DOWN);
  if (!digitalRead(left)){ Keyboard.press(KEY_LEFT);}else{Keyboard.release(KEY_LEFT);
  if (!digitalRead(right)){ Keyboard.press(KEY_RIGHT);}else{Keyboard.release(KEY_RIGHT);


}

void sendKey(byte key, byte modifiers)
{

  KeyReport report = {0};  // Create an empty KeyReport
  
  /* First send a report with the keys and modifiers pressed */
  report.keys[0] = key;  // set the KeyReport to key
  report.modifiers = modifiers;  // set the KeyReport's modifiers
  report.reserved = 1;
  Keyboard.sendReport(&report);  // send the KeyReport
  
  /* Now we've got to send a report with nothing pressed */
  for (int i=0; i<6; i++)
    report.keys[i] = 0;  // clear out the keys
  report.modifiers = 0x00;  // clear out the modifires
  report.reserved = 0;
  Keyboard.sendReport(&report);  // send the empty key report
}

a lot of this is a copy paste from another source, I'm not gonna lie.

Thank you

  if (!digitalRead(Button1)){ Keyboard.press('1');}else{Keyboard.release('1');

Each opening brace needs a corresponding closing brace. None of the opening braces on these else clauses seem to have closing braces.

Thank you so much, I've been fighting with this for a while and I completely missed it. Then I copied and pasted the same issue, over and over again. Don't I feel dumb. This is not my first programming language but that was fairly obvious. :blush:

If you had tried auto-format (Tools->Auto Format or Command-T on a Mac) you would have gotten the error: "Auto Format Canceled: Too many left curly braces." That might have pointed you to the error earlier.

If you had tried auto-format (Tools->Auto Format or Command-T on a Mac) you would have gotten the error: "Auto Format Canceled: Too many left curly braces."

Not with 1.5.6-r2 you don't, but the code layout is obviously wrong because it gets wider and wider and never goes back to the left margin.