Upload error "expected unqualified id before..." HELP !

So I an using an Arduino Leonardo controller to control a RaspberryPie w/ RetroPie. Basically to convert Joystick and buttons to control a videogame.
When I upload the sketch, I get the error: "expected unqualified-id before numeric constant".

I can see the Arduino controller on my laptop and can communicate with it, but there is an error uploading the sketch.

Any suggestions??

Thanks!

Here is the code I am trying to upload:

01.//element14 PIK3A Gaming Table Controls, using an Arduino Leonardo//
02.
03.void setup() {
04. Keyboard.begin();
05.
06.
07. //Joystick and buttons pin allocations
08. pinMode(0, INPUT_PULLUP); //Joystick Up
09. pinMode(1, INPUT_PULLUP); //Joystick Down
10. pinMode(2, INPUT_PULLUP); //Joystick Left
11. pinMode(3, INPUT_PULLUP); //Joystick Right
12. pinMode(4, INPUT_PULLUP); //Button 1
13. pinMode(5, INPUT_PULLUP); //Button 2
14. pinMode(6, INPUT_PULLUP); //Button 3
15. pinMode(7, INPUT_PULLUP); //Button 4
16. pinMode(8, INPUT_PULLUP); //Coin
17. pinMode(9, INPUT_PULLUP); //Start
18.}
19.
20.
21.void loop() {
22.
23.
24. // Button labels:
25. int joystickUp = digitalRead(0);
26. int joystickDown = digitalRead(1);
27. int joystickLeft = digitalRead(2);
28. int joystickRight = digitalRead(3);
29. int button1 = digitalRead(4);
30. int button2 = digitalRead(5);
31. int button3 = digitalRead(6);
32. int button4 = digitalRead(7);
33. int coin = digitalRead(8);
34. int start = digitalRead(9);
35.
36.
37. // Joystick Up - Arrow Up Key
38. if (joystickUp == LOW) {
39. Keyboard.press(218);
40. }
41. else {
42. Keyboard.release(218);
43. }
44.
45.
46. // Joystick Down - Arrow Down Key
47. if (joystickDown == LOW) {
48. Keyboard.press(217);
49. }
50. else {
51. Keyboard.release(217);
52. }
53.
54.
55. // Joystick Left - Arrow Left Key
56. if (joystickLeft == LOW) {
57. Keyboard.press(216);
58. }
59. else {
60. Keyboard.release(216);
61. }
62.
63.
64. // Joystick Right - Arrow Right Key
65. if (joystickRight == LOW) {
66. Keyboard.press(215);
67. }
68. else {
69. Keyboard.release(215);
70. }
71.
72.
73. // Button 1 - Left CTRL
74. if (button1 == LOW) {
75. Keyboard.press(128);
76. }
77. else {
78. Keyboard.release(128);
79. }
80.
81.
82. // Button 2 - Left ALT
83. if (button2 == LOW) {
84. Keyboard.press(130);
85. }
86. else {
87. Keyboard.release(130);
88. }
89.
90.
91. // Button 3 - Left CTRL
92. if (button3 == LOW) {
93. Keyboard.press(32);
94. }
95. else {
96. Keyboard.release(32);
97. }
98.
99.
100. // Button 4 - Left CTRL
101. if (button4 == LOW) {
102. Keyboard.press(129);
103. }
104. else {
105. Keyboard.release(129);
106. }
107.
108.
109. // Coin - 5
110. if (coin == LOW) {
111. Keyboard.press(53);
112. }
113. else {
114. Keyboard.release(53);
115. }
116.
117.
118. // Start - 1
119. if (start == LOW) {
120. Keyboard.press(49); delay(100);
121. }
122. else {
123. Keyboard.release(49);
124. }
125.
126.}

Did you type in all those line numbers?

If so, they're the problem.

If not, could you edit your post to show your sketch as it really is. Also please use code tags so the forum software doesn't try to turn your code into smilies etc.

Also, show us the rest of the error message - it'll say where the error is.

This is the full error I get:

sketch_jan06a:2:1: error: expected unqualified-id before numeric constant

^

sketch_jan06a:3:1: error: expected unqualified-id before numeric constant

03.void setup() {

^

sketch_jan06a:19:1: error: expected unqualified-id before numeric constant

^

exit status 1
expected unqualified-id before numeric constant

Yes. Definitely, you need to lose the line numbers.

So it should look like this:

.
.void setup() {
. Keyboard.begin();
.
.
. //Joystick and buttons pin allocations
. pinMode(0, INPUT_PULLUP); //Joystick Up
. pinMode(1, INPUT_PULLUP); //Joystick Down
. pinMode(2, INPUT_PULLUP); //Joystick Left
. pinMode(3, INPUT_PULLUP); //Joystick Right
. pinMode(4, INPUT_PULLUP); //Button 1
. pinMode(5, INPUT_PULLUP); //Button 2
. pinMode(6, INPUT_PULLUP); //Button 3
. pinMode(7, INPUT_PULLUP); //Button 4
. pinMode(8, INPUT_PULLUP); //Coin
. pinMode(9, INPUT_PULLUP); //Start

and not like this ??:
02.
03.void setup() {
04. Keyboard.begin();
05.
06.
07. //Joystick and buttons pin allocations
08. pinMode(0, INPUT_PULLUP); //Joystick Up
09. pinMode(1, INPUT_PULLUP); //Joystick Down
10. pinMode(2, INPUT_PULLUP); //Joystick Left
11. pinMode(3, INPUT_PULLUP); //Joystick Right
12. pinMode(4, INPUT_PULLUP); //Button 1
13. pinMode(5, INPUT_PULLUP); //Button 2
14. pinMode(6, INPUT_PULLUP); //Button 3
15. pinMode(7, INPUT_PULLUP); //Button 4
16. pinMode(8, INPUT_PULLUP); //Coin
17. pinMode(9, INPUT_PULLUP); //Start

No, you also need to lose the full-stops at the start of every line.

Also learn about how to use the forum's code tags. It needs to look like this:

void setup() {  
  Keyboard.begin();  
  
  
  //Joystick and buttons pin allocations  
  pinMode(0, INPUT_PULLUP); //Joystick Up  
  pinMode(1, INPUT_PULLUP); //Joystick Down  
  pinMode(2, INPUT_PULLUP); //Joystick Left  

//etc

Sorry for the noob questions, but I am getting this error now after removing the numbers and full stop:

ketch_jan06a:39:5: error: 'Keyboard' not found. Does your sketch include the line '#include <Keyboard.h>'?
Keyboard.press(218);

^

sketch_jan06a:42:5: error: 'Keyboard' not found. Does your sketch include the line '#include <Keyboard.h>'?
Keyboard.release(218);

^

sketch_jan06a:48:5: error: 'Keyboard' not found. Does your sketch include the line '#include <Keyboard.h>'?
Keyboard.press(217);

Does your sketch include the line '#include <Keyboard.h>'?
     Keyboard.press(218);

Well, does it?

Shanedm1 -- why is it you still haven't managed to properly post a complete sketch with Code Tags? People on the forum are willing to help you FOR FREE. Why are you making it harder for them?

Heres the complete sketch:
//element14 PIK3A Gaming Table Controls, using an Arduino Leonardo//

void setup() {
Keyboard.begin();

//Joystick and buttons pin allocations
pinMode(0, INPUT_PULLUP); //Joystick Up
pinMode(1, INPUT_PULLUP); //Joystick Down
pinMode(2, INPUT_PULLUP); //Joystick Left
pinMode(3, INPUT_PULLUP); //Joystick Right
pinMode(4, INPUT_PULLUP); //Button 1
pinMode(5, INPUT_PULLUP); //Button 2
pinMode(6, INPUT_PULLUP); //Button 3
pinMode(7, INPUT_PULLUP); //Button 4
pinMode(8, INPUT_PULLUP); //Coin
pinMode(9, INPUT_PULLUP); //Start
}

void loop() {

// Button labels:
int joystickUp = digitalRead(0);
int joystickDown = digitalRead(1);
int joystickLeft = digitalRead(2);
int joystickRight = digitalRead(3);
int button1 = digitalRead(4);
int button2 = digitalRead(5);
int button3 = digitalRead(6);
int button4 = digitalRead(7);
int coin = digitalRead(8);
int start = digitalRead(9);

// Joystick Up - Arrow Up Key
if (joystickUp == LOW) {
Keyboard.press(218);
}
else {
Keyboard.release(218);
}

// Joystick Down - Arrow Down Key
if (joystickDown == LOW) {
Keyboard.press(217);
}
else {
Keyboard.release(217);
}

// Joystick Left - Arrow Left Key
if (joystickLeft == LOW) {
Keyboard.press(216);
}
else {
Keyboard.release(216);
}

// Joystick Right - Arrow Right Key
if (joystickRight == LOW) {
Keyboard.press(215);
}
else {
Keyboard.release(215);
}

// Button 1 - Left CTRL
if (button1 == LOW) {
Keyboard.press(128);
}
else {
Keyboard.release(128);
}

// Button 2 - Left ALT
if (button2 == LOW) {
Keyboard.press(130);
}
else {
Keyboard.release(130);
}

// Button 3 - Left CTRL
if (button3 == LOW) {
Keyboard.press(32);
}
else {
Keyboard.release(32);
}

// Button 4 - Left CTRL
if (button4 == LOW) {
Keyboard.press(129);
}
else {
Keyboard.release(129);
}

// Coin - 5
if (coin == LOW) {
Keyboard.press(53);
}
else {
Keyboard.release(53);
}

// Start - 1
if (start == LOW) {
Keyboard.press(49); delay(100);
}
else {
Keyboard.release(49);
}

}

Heres the complete sketch:

As suspected, you have not #included the Keyboard library

and heres the errors I am getting:
C:\Users\Shane\Documents\Arduino\sketch_dec29a\sketch_jan06a\sketch_jan06a\sketch_jan06a\sketch_jan06a\sketch_jan06a.ino: In function 'void setup()':

sketch_jan06a:4:3: error: 'Keyboard' not found. Does your sketch include the line '#include <Keyboard.h>'?
Keyboard.begin();

^

C:\Users\Shane\Documents\Arduino\sketch_dec29a\sketch_jan06a\sketch_jan06a\sketch_jan06a\sketch_jan06a\sketch_jan06a.ino: In function 'void loop()':

sketch_jan06a:39:5: error: 'Keyboard' not found. Does your sketch include the line '#include <Keyboard.h>'?
Keyboard.press(218);

^

sketch_jan06a:42:5: error: 'Keyboard' not found. Does your sketch include the line '#include <Keyboard.h>'?
Keyboard.release(218);

^

sketch_jan06a:48:5: error: 'Keyboard' not found. Does your sketch include the line '#include <Keyboard.h>'?
Keyboard.press(217);

^

sketch_jan06a:51:5: error: 'Keyboard' not found. Does your sketch include the line '#include <Keyboard.h>'?
Keyboard.release(217);

^

sketch_jan06a:57:5: error: 'Keyboard' not found. Does your sketch include the line '#include <Keyboard.h>'?
Keyboard.press(216);

^

sketch_jan06a:60:5: error: 'Keyboard' not found. Does your sketch include the line '#include <Keyboard.h>'?
Keyboard.release(216);

^

sketch_jan06a:66:5: error: 'Keyboard' not found. Does your sketch include the line '#include <Keyboard.h>'?
Keyboard.press(215);

^

sketch_jan06a:69:5: error: 'Keyboard' not found. Does your sketch include the line '#include <Keyboard.h>'?
Keyboard.release(215);

^

sketch_jan06a:75:5: error: 'Keyboard' not found. Does your sketch include the line '#include <Keyboard.h>'?
Keyboard.press(128);

^

sketch_jan06a:78:5: error: 'Keyboard' not found. Does your sketch include the line '#include <Keyboard.h>'?
Keyboard.release(128);

^

sketch_jan06a:84:5: error: 'Keyboard' not found. Does your sketch include the line '#include <Keyboard.h>'?
Keyboard.press(130);

^

sketch_jan06a:87:5: error: 'Keyboard' not found. Does your sketch include the line '#include <Keyboard.h>'?
Keyboard.release(130);

^

sketch_jan06a:93:5: error: 'Keyboard' not found. Does your sketch include the line '#include <Keyboard.h>'?
Keyboard.press(32);

^

sketch_jan06a:96:5: error: 'Keyboard' not found. Does your sketch include the line '#include <Keyboard.h>'?
Keyboard.release(32);

^

sketch_jan06a:102:5: error: 'Keyboard' not found. Does your sketch include the line '#include <Keyboard.h>'?
Keyboard.press(129);

^

sketch_jan06a:105:5: error: 'Keyboard' not found. Does your sketch include the line '#include <Keyboard.h>'?
Keyboard.release(129);

^

sketch_jan06a:111:5: error: 'Keyboard' not found. Does your sketch include the line '#include <Keyboard.h>'?
Keyboard.press(53);

^

sketch_jan06a:114:5: error: 'Keyboard' not found. Does your sketch include the line '#include <Keyboard.h>'?
Keyboard.release(53);

^

sketch_jan06a:120:5: error: 'Keyboard' not found. Does your sketch include the line '#include <Keyboard.h>'?
Keyboard.press(49); delay(100);

^

sketch_jan06a:123:5: error: 'Keyboard' not found. Does your sketch include the line '#include <Keyboard.h>'?
Keyboard.release(49);

^

exit status 1
'Keyboard' not found. Does your sketch include the line '#include <Keyboard.h>'?

Shanedm1:
Heres the complete sketch:

And, still no Code Tags. Are you really that dense?

Does your sketch include the line '#include <Keyboard.h>'?

Answer : No

UKHeliBob:
As suspected, you have not #included the Keyboard library

How do I include the keyboard library? What do I add to the code??

A HUGE THANK YOU!!!!

Shanedm1:
How do I include the keyboard library? What do I add to the code??

A HUGE THANK YOU!!!!

I don't know if this means you've fixed it or not.

You need to add the line

#include <Keyboard.h>

at the top of your sketch.

I added the #incude <Keyboard.h> at the top and am getting this now:

Sketch uses 6180 bytes (21%) of program storage space. Maximum is 28672 bytes.
Global variables use 224 bytes (8%) of dynamic memory, leaving 2336 bytes for local variables. Maximum is 2560 bytes.
An error occurred while uploading the sketch

That's not the entire error message. Please add code tags to your code and error messages. I you really want help there are instructions on how to get help, and so much else here. Go here and check it out: How to use this forum

I'm not getting any errors anymore and the joystick is now working !

Buttons not working tho...