Trying to build Flight Sim controller

Hello everyone , I'm a newbie to Arduino programming and I'm trying to build a flight Simulator controller from here 3D Printed Flight Yoke for Flight Simulator by m2rechtin - Thingiverse . I'm having trouble compiling the code provided by the creator of said controls.
Here is the code :
// Requires Arduino Joystick Library GitHub - MHeironimus/ArduinoJoystickLibrary: An Arduino library that adds one or more joysticks to the list of HID devices an Arduino Leonardo or Arduino Micro can support.
#include <Joystick.h>
Joystick_ Joystick

int JoystickX;
int JoystickY;
int JoystickZ;
int Throttle;
int Rudder;
int Aux1;
int Aux2;
int currentButtonState0;
int lastButtonState0;
int currentButtonState1;
int lastButtonState1;
int currentButtonState2;
int lastButtonState2;
int currentButtonState3;
int lastButtonState3;
int currentButtonState4;
int lastButtonState4;
int currentButtonState5;
int lastButtonState5;
int currentButtonState6;
int lastButtonState6;

void setup() {
Serial.begin(9600);
pinMode(2, INPUT_PULLUP);
pinMode(3, INPUT_PULLUP);
pinMode(4, INPUT_PULLUP);
pinMode(5, INPUT_PULLUP);
pinMode(6, INPUT_PULLUP);
pinMode(7, INPUT_PULLUP);
// Initialize Joystick Library
Joystick.begin();
Joystick.setXAxisRange(0, 965);
Joystick.setYAxisRange(192, 522);
Joystick.setZAxisRange(143, 735);
Joystick.setRxAxisRange(158, 456);
Joystick.setRyAxisRange(158, 456);
Joystick.setThrottleRange(154, 448);
}

void loop() {

// Read Joystick
JoystickX = analogRead(A0);
JoystickY = analogRead(A1);
JoystickZ=analogRead(A8);
Throttle=analogRead(A2);
Aux1=analogRead(A9);
Aux2=analogRead(A3);
Serial.print(JoystickX);
Serial.print(" ");
Serial.print(JoystickY);
Serial.print(" ");
Serial.println(JoystickZ);

// Read Switches
int currentButtonState0 = !digitalRead(2); // Button 0
if (currentButtonState0 != lastButtonState0)
{
Joystick.setButton(0, currentButtonState0);
lastButtonState0 = currentButtonState0;
}

int currentButtonState1 = !digitalRead(3); // Button 1
if (currentButtonState1 != lastButtonState1)
{
Joystick.setButton(1, currentButtonState1);
lastButtonState1 = currentButtonState1;
}

int currentButtonState2 = !digitalRead(4); // Button 2
if (currentButtonState2 != lastButtonState2)
{
Joystick.setButton(2, currentButtonState2);
lastButtonState2 = currentButtonState2;
}

int currentButtonState3 = !digitalRead(5); // Button 3
if (currentButtonState3 != lastButtonState3)
{
Joystick.setButton(3, currentButtonState3);
lastButtonState3 = currentButtonState3;
}

int currentButtonState4 = !digitalRead(6); // Button 4
if (currentButtonState4 != lastButtonState4)
{
Joystick.setButton(4, currentButtonState4);
lastButtonState4 = currentButtonState4;
}

int currentButtonState5 = !digitalRead(7); // Button 5
if (currentButtonState5 != lastButtonState5)
{
Joystick.setButton(5, currentButtonState5);
lastButtonState5 = currentButtonState5;
}

// Output Controls
Joystick.setXAxis(JoystickX);
Joystick.setYAxis(JoystickY);
Joystick.setZAxis(JoystickZ);
Joystick.setThrottle(Throttle);
Joystick.setRxAxis(Aux1);
Joystick.setRyAxis(Aux2);
Joystick.sendState();

}
So the error I'm getting is :

Arduino: 1.8.19 (Windows Store 1.8.57.0) (Windows 10), Board: "Arduino Micro"
C:\Program Files\WindowsApps\ArduinoLLC.ArduinoIDE_1.8.57.0_x86__mdqgnx93n4wtt\arduino-builder -dump-prefs -logger=machine -hardware C:\Program Files\WindowsApps\ArduinoLLC.ArduinoIDE_1.8.57.0_x86__mdqgnx93n4wtt\hardware -hardware C:\Users\alima\Documents\ArduinoData\packages -tools C:\Program Files\WindowsApps\ArduinoLLC.ArduinoIDE_1.8.57.0_x86__mdqgnx93n4wtt\tools-builder -tools C:\Program Files\WindowsApps\ArduinoLLC.ArduinoIDE_1.8.57.0_x86__mdqgnx93n4wtt\hardware\tools\avr -tools C:\Users\alima\Documents\ArduinoData\packages -built-in-libraries C:\Program Files\WindowsApps\ArduinoLLC.ArduinoIDE_1.8.57.0_x86__mdqgnx93n4wtt\libraries -libraries C:\Users\alima\Documents\Arduino\libraries -fqbn=arduino:avr:micro -ide-version=10819 -build-path C:\Users\alima\AppData\Local\Temp\arduino_build_138666 -warnings=none -build-cache C:\Users\alima\AppData\Local\Temp\arduino_cache_597556 -prefs=build.warn_data_percentage=75 -prefs=runtime.tools.arduinoOTA.path=C:\Users\alima\Documents\ArduinoData\packages\arduino\tools\arduinoOTA\1.3.0 -prefs=runtime.tools.arduinoOTA-1.3.0.path=C:\Users\alima\Documents\ArduinoData\packages\arduino\tools\arduinoOTA\1.3.0 -prefs=runtime.tools.avr-gcc.path=C:\Users\alima\Documents\ArduinoData\packages\arduino\tools\avr-gcc\7.3.0-atmel3.6.1-arduino7 -prefs=runtime.tools.avr-gcc-7.3.0-atmel3.6.1-arduino7.path=C:\Users\alima\Documents\ArduinoData\packages\arduino\tools\avr-gcc\7.3.0-atmel3.6.1-arduino7 -prefs=runtime.tools.avrdude.path=C:\Users\alima\Documents\ArduinoData\packages\arduino\tools\avrdude\6.3.0-arduino17 -prefs=runtime.tools.avrdude-6.3.0-arduino17.path=C:\Users\alima\Documents\ArduinoData\packages\arduino\tools\avrdude\6.3.0-arduino17 -verbose C:\Users\alima\Downloads\Flight_Yoke_Code-20220802T002738Z-001\Flight_Yoke_Code\Flight_Yoke_Code.ino

C:\Program Files\WindowsApps\ArduinoLLC.ArduinoIDE_1.8.57.0_x86__mdqgnx93n4wtt\arduino-builder -compile -logger=machine -hardware C:\Program Files\WindowsApps\ArduinoLLC.ArduinoIDE_1.8.57.0_x86__mdqgnx93n4wtt\hardware -hardware C:\Users\alima\Documents\ArduinoData\packages -tools C:\Program Files\WindowsApps\ArduinoLLC.ArduinoIDE_1.8.57.0_x86__mdqgnx93n4wtt\tools-builder -tools C:\Program Files\WindowsApps\ArduinoLLC.ArduinoIDE_1.8.57.0_x86__mdqgnx93n4wtt\hardware\tools\avr -tools C:\Users\alima\Documents\ArduinoData\packages -built-in-libraries C:\Program Files\WindowsApps\ArduinoLLC.ArduinoIDE_1.8.57.0_x86__mdqgnx93n4wtt\libraries -libraries C:\Users\alima\Documents\Arduino\libraries -fqbn=arduino:avr:micro -ide-version=10819 -build-path C:\Users\alima\AppData\Local\Temp\arduino_build_138666 -warnings=none -build-cache C:\Users\alima\AppData\Local\Temp\arduino_cache_597556 -prefs=build.warn_data_percentage=75 -prefs=runtime.tools.arduinoOTA.path=C:\Users\alima\Documents\ArduinoData\packages\arduino\tools\arduinoOTA\1.3.0 -prefs=runtime.tools.arduinoOTA-1.3.0.path=C:\Users\alima\Documents\ArduinoData\packages\arduino\tools\arduinoOTA\1.3.0 -prefs=runtime.tools.avr-gcc.path=C:\Users\alima\Documents\ArduinoData\packages\arduino\tools\avr-gcc\7.3.0-atmel3.6.1-arduino7 -prefs=runtime.tools.avr-gcc-7.3.0-atmel3.6.1-arduino7.path=C:\Users\alima\Documents\ArduinoData\packages\arduino\tools\avr-gcc\7.3.0-atmel3.6.1-arduino7 -prefs=runtime.tools.avrdude.path=C:\Users\alima\Documents\ArduinoData\packages\arduino\tools\avrdude\6.3.0-arduino17 -prefs=runtime.tools.avrdude-6.3.0-arduino17.path=C:\Users\alima\Documents\ArduinoData\packages\arduino\tools\avrdude\6.3.0-arduino17 -verbose C:\Users\alima\Downloads\Flight_Yoke_Code-20220802T002738Z-001\Flight_Yoke_Code\Flight_Yoke_Code.ino

Using board 'micro' from platform in folder: C:\Users\alima\Documents\ArduinoData\packages\arduino\hardware\avr\1.8.5

Using core 'arduino' from platform in folder: C:\Users\alima\Documents\ArduinoData\packages\arduino\hardware\avr\1.8.5

Detecting libraries used...

"C:\Users\alima\Documents\ArduinoData\packages\arduino\tools\avr-gcc\7.3.0-atmel3.6.1-arduino7/bin/avr-g++" -c -g -Os -w -std=gnu++11 -fpermissive -fno-exceptions -ffunction-sections -fdata-sections -fno-threadsafe-statics -Wno-error=narrowing -flto -w -x c++ -E -CC -mmcu=atmega32u4 -DF_CPU=16000000L -DARDUINO=10819 -DARDUINO_AVR_MICRO -DARDUINO_ARCH_AVR -DUSB_VID=0x2341 -DUSB_PID=0x8037 "-DUSB_MANUFACTURER="Unknown"" "-DUSB_PRODUCT="Arduino Micro"" "-IC:\Users\alima\Documents\ArduinoData\packages\arduino\hardware\avr\1.8.5\cores\arduino" "-IC:\Users\alima\Documents\ArduinoData\packages\arduino\hardware\avr\1.8.5\variants\micro" "C:\Users\alima\AppData\Local\Temp\arduino_build_138666\sketch\Flight_Yoke_Code.ino.cpp" -o nul

Alternatives for Joystick.h: [ArduinoJoystickLibrary-master@2.1.1]

ResolveLibrary(Joystick.h)

-> candidates: [ArduinoJoystickLibrary-master@2.1.1]

"C:\Users\alima\Documents\ArduinoData\packages\arduino\tools\avr-gcc\7.3.0-atmel3.6.1-arduino7/bin/avr-g++" -c -g -Os -w -std=gnu++11 -fpermissive -fno-exceptions -ffunction-sections -fdata-sections -fno-threadsafe-statics -Wno-error=narrowing -flto -w -x c++ -E -CC -mmcu=atmega32u4 -DF_CPU=16000000L -DARDUINO=10819 -DARDUINO_AVR_MICRO -DARDUINO_ARCH_AVR -DUSB_VID=0x2341 -DUSB_PID=0x8037 "-DUSB_MANUFACTURER="Unknown"" "-DUSB_PRODUCT="Arduino Micro"" "-IC:\Users\alima\Documents\ArduinoData\packages\arduino\hardware\avr\1.8.5\cores\arduino" "-IC:\Users\alima\Documents\ArduinoData\packages\arduino\hardware\avr\1.8.5\variants\micro" "-IC:\Users\alima\Documents\Arduino\libraries\ArduinoJoystickLibrary-master\src" "C:\Users\alima\AppData\Local\Temp\arduino_build_138666\sketch\Flight_Yoke_Code.ino.cpp" -o nul

"C:\Users\alima\Documents\ArduinoData\packages\arduino\tools\avr-gcc\7.3.0-atmel3.6.1-arduino7/bin/avr-g++" -c -g -Os -w -std=gnu++11 -fpermissive -fno-exceptions -ffunction-sections -fdata-sections -fno-threadsafe-statics -Wno-error=narrowing -flto -w -x c++ -E -CC -mmcu=atmega32u4 -DF_CPU=16000000L -DARDUINO=10819 -DARDUINO_AVR_MICRO -DARDUINO_ARCH_AVR -DUSB_VID=0x2341 -DUSB_PID=0x8037 "-DUSB_MANUFACTURER="Unknown"" "-DUSB_PRODUCT="Arduino Micro"" "-IC:\Users\alima\Documents\ArduinoData\packages\arduino\hardware\avr\1.8.5\cores\arduino" "-IC:\Users\alima\Documents\ArduinoData\packages\arduino\hardware\avr\1.8.5\variants\micro" "-IC:\Users\alima\Documents\Arduino\libraries\ArduinoJoystickLibrary-master\src" "C:\Users\alima\Documents\Arduino\libraries\ArduinoJoystickLibrary-master\src\DynamicHID\DynamicHID.cpp" -o nul

"C:\Users\alima\Documents\ArduinoData\packages\arduino\tools\avr-gcc\7.3.0-atmel3.6.1-arduino7/bin/avr-g++" -c -g -Os -w -std=gnu++11 -fpermissive -fno-exceptions -ffunction-sections -fdata-sections -fno-threadsafe-statics -Wno-error=narrowing -flto -w -x c++ -E -CC -mmcu=atmega32u4 -DF_CPU=16000000L -DARDUINO=10819 -DARDUINO_AVR_MICRO -DARDUINO_ARCH_AVR -DUSB_VID=0x2341 -DUSB_PID=0x8037 "-DUSB_MANUFACTURER="Unknown"" "-DUSB_PRODUCT="Arduino Micro"" "-IC:\Users\alima\Documents\ArduinoData\packages\arduino\hardware\avr\1.8.5\cores\arduino" "-IC:\Users\alima\Documents\ArduinoData\packages\arduino\hardware\avr\1.8.5\variants\micro" "-IC:\Users\alima\Documents\Arduino\libraries\ArduinoJoystickLibrary-master\src" "C:\Users\alima\Documents\Arduino\libraries\ArduinoJoystickLibrary-master\src\Joystick.cpp" -o nul

Generating function prototypes...

"C:\Users\alima\Documents\ArduinoData\packages\arduino\tools\avr-gcc\7.3.0-atmel3.6.1-arduino7/bin/avr-g++" -c -g -Os -w -std=gnu++11 -fpermissive -fno-exceptions -ffunction-sections -fdata-sections -fno-threadsafe-statics -Wno-error=narrowing -flto -w -x c++ -E -CC -mmcu=atmega32u4 -DF_CPU=16000000L -DARDUINO=10819 -DARDUINO_AVR_MICRO -DARDUINO_ARCH_AVR -DUSB_VID=0x2341 -DUSB_PID=0x8037 "-DUSB_MANUFACTURER="Unknown"" "-DUSB_PRODUCT="Arduino Micro"" "-IC:\Users\alima\Documents\ArduinoData\packages\arduino\hardware\avr\1.8.5\cores\arduino" "-IC:\Users\alima\Documents\ArduinoData\packages\arduino\hardware\avr\1.8.5\variants\micro" "-IC:\Users\alima\Documents\Arduino\libraries\ArduinoJoystickLibrary-master\src" "C:\Users\alima\AppData\Local\Temp\arduino_build_138666\sketch\Flight_Yoke_Code.ino.cpp" -o "C:\Users\alima\AppData\Local\Temp\arduino_build_138666\preproc\ctags_target_for_gcc_minus_e.cpp"

"C:\Program Files\WindowsApps\ArduinoLLC.ArduinoIDE_1.8.57.0_x86__mdqgnx93n4wtt\tools-builder\ctags\5.8-arduino11/ctags" -u --language-force=c++ -f - --c++-kinds=svpf --fields=KSTtzns --line-directives "C:\Users\alima\AppData\Local\Temp\arduino_build_138666\preproc\ctags_target_for_gcc_minus_e.cpp"

Compiling sketch...

"C:\Users\alima\Documents\ArduinoData\packages\arduino\tools\avr-gcc\7.3.0-atmel3.6.1-arduino7/bin/avr-g++" -c -g -Os -w -std=gnu++11 -fpermissive -fno-exceptions -ffunction-sections -fdata-sections -fno-threadsafe-statics -Wno-error=narrowing -MMD -flto -mmcu=atmega32u4 -DF_CPU=16000000L -DARDUINO=10819 -DARDUINO_AVR_MICRO -DARDUINO_ARCH_AVR -DUSB_VID=0x2341 -DUSB_PID=0x8037 "-DUSB_MANUFACTURER="Unknown"" "-DUSB_PRODUCT="Arduino Micro"" "-IC:\Users\alima\Documents\ArduinoData\packages\arduino\hardware\avr\1.8.5\cores\arduino" "-IC:\Users\alima\Documents\ArduinoData\packages\arduino\hardware\avr\1.8.5\variants\micro" "-IC:\Users\alima\Documents\Arduino\libraries\ArduinoJoystickLibrary-master\src" "C:\Users\alima\AppData\Local\Temp\arduino_build_138666\sketch\Flight_Yoke_Code.ino.cpp" -o "C:\Users\alima\AppData\Local\Temp\arduino_build_138666\sketch\Flight_Yoke_Code.ino.cpp.o"

Flight_Yoke_Code:5:1: error: expected initializer before 'int'

int JoystickX;

^~~

C:\Users\alima\Downloads\Flight_Yoke_Code-20220802T002738Z-001\Flight_Yoke_Code\Flight_Yoke_Code.ino: In function 'void setup()':

Flight_Yoke_Code:36:3: error: 'Joystick' was not declared in this scope

Joystick.begin();

^~~~~~~~

C:\Users\alima\Downloads\Flight_Yoke_Code-20220802T002738Z-001\Flight_Yoke_Code\Flight_Yoke_Code.ino:36:3: note: suggested alternative: 'JoystickZ'

Joystick.begin();

^~~~~~~~

JoystickZ

C:\Users\alima\Downloads\Flight_Yoke_Code-20220802T002738Z-001\Flight_Yoke_Code\Flight_Yoke_Code.ino: In function 'void loop()':

Flight_Yoke_Code:48:3: error: 'JoystickX' was not declared in this scope

JoystickX = analogRead(A0);

^~~~~~~~~

C:\Users\alima\Downloads\Flight_Yoke_Code-20220802T002738Z-001\Flight_Yoke_Code\Flight_Yoke_Code.ino:48:3: note: suggested alternative: 'JoystickZ'

JoystickX = analogRead(A0);

^~~~~~~~~

JoystickZ

Flight_Yoke_Code:65:3: error: 'Joystick' was not declared in this scope

Joystick.setButton(0, currentButtonState0);

^~~~~~~~

C:\Users\alima\Downloads\Flight_Yoke_Code-20220802T002738Z-001\Flight_Yoke_Code\Flight_Yoke_Code.ino:65:3: note: suggested alternative: 'JoystickZ'

Joystick.setButton(0, currentButtonState0);

^~~~~~~~

JoystickZ

Flight_Yoke_Code:72:3: error: 'Joystick' was not declared in this scope

Joystick.setButton(1, currentButtonState1);

^~~~~~~~

C:\Users\alima\Downloads\Flight_Yoke_Code-20220802T002738Z-001\Flight_Yoke_Code\Flight_Yoke_Code.ino:72:3: note: suggested alternative: 'JoystickZ'

Joystick.setButton(1, currentButtonState1);

^~~~~~~~

JoystickZ

Flight_Yoke_Code:79:3: error: 'Joystick' was not declared in this scope

Joystick.setButton(2, currentButtonState2);

^~~~~~~~

C:\Users\alima\Downloads\Flight_Yoke_Code-20220802T002738Z-001\Flight_Yoke_Code\Flight_Yoke_Code.ino:79:3: note: suggested alternative: 'JoystickZ'

Joystick.setButton(2, currentButtonState2);

^~~~~~~~

JoystickZ

Flight_Yoke_Code:86:3: error: 'Joystick' was not declared in this scope

Joystick.setButton(3, currentButtonState3);

^~~~~~~~

C:\Users\alima\Downloads\Flight_Yoke_Code-20220802T002738Z-001\Flight_Yoke_Code\Flight_Yoke_Code.ino:86:3: note: suggested alternative: 'JoystickZ'

Joystick.setButton(3, currentButtonState3);

^~~~~~~~

JoystickZ

Flight_Yoke_Code:93:3: error: 'Joystick' was not declared in this scope

Joystick.setButton(4, currentButtonState4);

^~~~~~~~

C:\Users\alima\Downloads\Flight_Yoke_Code-20220802T002738Z-001\Flight_Yoke_Code\Flight_Yoke_Code.ino:93:3: note: suggested alternative: 'JoystickZ'

Joystick.setButton(4, currentButtonState4);

^~~~~~~~

JoystickZ

Flight_Yoke_Code:100:3: error: 'Joystick' was not declared in this scope

Joystick.setButton(5, currentButtonState5);

^~~~~~~~

C:\Users\alima\Downloads\Flight_Yoke_Code-20220802T002738Z-001\Flight_Yoke_Code\Flight_Yoke_Code.ino:100:3: note: suggested alternative: 'JoystickZ'

Joystick.setButton(5, currentButtonState5);

^~~~~~~~

JoystickZ

Flight_Yoke_Code:106:3: error: 'Joystick' was not declared in this scope

Joystick.setXAxis(JoystickX);

^~~~~~~~

C:\Users\alima\Downloads\Flight_Yoke_Code-20220802T002738Z-001\Flight_Yoke_Code\Flight_Yoke_Code.ino:106:3: note: suggested alternative: 'JoystickZ'

Joystick.setXAxis(JoystickX);

^~~~~~~~

JoystickZ

Using library ArduinoJoystickLibrary-master at version 2.1.1 in folder: C:\Users\alima\Documents\Arduino\libraries\ArduinoJoystickLibrary-master

exit status 1

expected initializer before 'int'

any help with this would be awesome, thanks a lot !!!

Please edit your post to add code tags, for both the code and the error messages.

This is often caused by a formatting error, like a missing semicolon or brace. Use the CRLT-T autoformat in the code editor, to see the indenting.

Right....there.
Missing semicolon and space.

sorry real newbie , semi colon and space where ?

Semicolon at the end of the line, space after the _

You've got a load of variables that have global scope, but don't need it.

Unbelievable .... a semicolon wow.
Thanks for your help , so awesome .!!!

Isn't that an issue too?
Should it be A3?

Edit: sorry, I didn't know the Micro has so many analogue inputs! :red face:

no worries man , i would never have figured out the semicolon thing , thanks a lot

I was trying to add a Left Brake and Right Brake to the above code ,I was trying to use pin A10 and A6 for the R & L Brake , any help would be Awesome .

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.