Error compiling joystick scripts

I keep receiving errors when I try to compile my sketch. This should work just fine as it's listed as a working code.

Sketch:
/*

#include <Joystick.h>
#include "AVRPort23.h"

#define CHAN1 D,0
#define _INT1 0
#define CHAN2 D,1
#define _INT2 1
#define CHAN3 D,3
#define _INT3 3
#define CHAN4 D,2
#define _INT4 2
#define RXLED B,0
#define TXLED D,5

Joystick_Joystick(JOYSTICK_DEFAULT_REPORT_ID,JOYSTICK_TYPE_GAMEPAD,
0, 0, // Button Count, Hat Switch Count
true, true, false, // X, Y, Z
true, true, false, // Rx, Ry, Rz
false, false, // Rudder, Throttle
false, false, false); // Accelerator, Brake, Steering

void setup()
{
portMode(CHAN1, INPUT, HIGH);
portMode(CHAN2, INPUT, HIGH);
portMode(CHAN3, INPUT, HIGH);
portMode(CHAN4, INPUT, HIGH);
portMode(RXLED, OUTPUT, LOW);
portMode(TXLED, OUTPUT, LOW);

Joystick.begin();
Joystick.setXAxisRange(2250, 750);
Joystick.setYAxisRange(2250, 750);
Joystick.setRxAxisRange(2250, 750);
Joystick.setRyAxisRange(2250, 750);

attachInterrupt(_INT1, isr1, CHANGE);
attachInterrupt(_INT2, isr2, CHANGE);
attachInterrupt(_INT3, isr3, CHANGE);
attachInterrupt(_INT4, isr4, CHANGE);
}

volatile unsigned long Time[4];
volatile unsigned int Value[4];
volatile bool ValChanged[4];
unsigned int NewValue[4];

void loop()
{
if (ValChanged[0])
{
NewValue[0] = (NewValue[0]+Value[0])/2;
Joystick.setXAxis(NewValue[0]);
ValChanged[0] = false;
}

if (ValChanged[1])
{
NewValue[1] = (NewValue[1]+Value[1])/2;
Joystick.setYAxis(NewValue[1]);
ValChanged[1] = false;
}

if (ValChanged[2])
{
NewValue[2] = (NewValue[2]+Value[2])/2;
Joystick.setRxAxis(NewValue[2]);
ValChanged[2] = false;
}

if (ValChanged[3])
{
NewValue[3] = (NewValue[3]+Value[3])/2;
Joystick.setRyAxis(NewValue[3]);
ValChanged[3] = false;
}

delay(1);
}

void isr1()
{
if (portRead(CHAN1)) Time[0] = micros();
else if (micros() > Time[0])
{
Value[0] = (Value[0]+(micros()-Time[0]))/2;
ValChanged[0] = true;
}
}

void isr2()
{
if (portRead(CHAN2)) Time[1] = micros();
else if (micros() > Time[1])
{
Value[1] = (Value[1]+(micros()-Time[1]))/2;
ValChanged[1] = true;
}
}

void isr3()
{
if (portRead(CHAN3)) Time[2] = micros();
else if (micros() > Time[2])
{
Value[2] = (Value[2]+(micros()-Time[2]))/2;
ValChanged[2] = true;
}
}

void isr4()
{
if (portRead(CHAN4)) Time[3] = micros();
else if (micros() > Time[3])
{
Value[3] = (Value[3]+(micros()-Time[3]))/2;
ValChanged[3] = true;
}
}

Errors:
Arduino: 1.8.19 (Windows 10), Board: "Arduino Micro"

RCUSB4:15:18: error: expected constructor, destructor, or type conversion before '(' token

Joystick_Joystick(JOYSTICK_DEFAULT_REPORT_ID, JOYSTICK_TYPE_GAMEPAD,

              ^

C:\Users\Army_\Documents\Arduino\RCUSB4_v1.1\RCUSB4\RCUSB4.ino: In function 'void setup()':

RCUSB4:31:11: error: expected unqualified-id before '.' token

Joystick.begin();

       ^

RCUSB4:32:11: error: expected unqualified-id before '.' token

Joystick.setXAxisRange(2250, 750);

       ^

RCUSB4:33:11: error: expected unqualified-id before '.' token

Joystick.setYAxisRange(2250, 750);

       ^

RCUSB4:34:11: error: expected unqualified-id before '.' token

Joystick.setRxAxisRange(2250, 750);

       ^

RCUSB4:35:11: error: expected unqualified-id before '.' token

Joystick.setRyAxisRange(2250, 750);

       ^

C:\Users\Army_\Documents\Arduino\RCUSB4_v1.1\RCUSB4\RCUSB4.ino: In function 'void loop()':

RCUSB4:53:13: error: expected unqualified-id before '.' token

 Joystick.setXAxis(NewValue[0]);

         ^

RCUSB4:60:13: error: expected unqualified-id before '.' token

 Joystick.setYAxis(NewValue[1]);

         ^

RCUSB4:67:13: error: expected unqualified-id before '.' token

 Joystick.setRxAxis(NewValue[2]);

         ^

RCUSB4:74:13: error: expected unqualified-id before '.' token

 Joystick.setRyAxis(NewValue[3]);

         ^

exit status 1

expected constructor, destructor, or type conversion before '(' token

This report would have more information with
"Show verbose output during compilation"
option enabled in File -> Preferences.

Any help is greatly appreciated

Joystick_Joystick(JOYSTICK_DEFAULT_REPORT_ID,JOYSTICK_TYPE_GAMEPAD

Is "Joystick" the name of the class or of the object?

Please remember to use code tags when posting code

I'm honestly not 100% sure. This is a preset code. I have some experience in coding, but it's been awhile.

These were the instructions:

How to make your own:

  1. Have Arduino IDE
  2. Download the RCUSB4 zip
  3. Extract the zip to your preferred documents area
  4. Download the Arduino Joystick Library
  5. Extract the zip to your preferred documents area
  6. Add the Joystick library from the ArduinoJoystickLibary folder. I did this by copying the Joystick folder and pasting it into the Libraries folder of my Arduino documents.
  7. Start Arduino IDE and open the RCUSB sketch
  8. Plug in Arduino Micro into USB port
  9. Select Tools>Board>Arduino/Genuino Micro
  10. Select Tools>Port>Arduino Micro
  11. Select the “Check” Verify button to compile the sketch

So you're saying the underscore ('_') between "Joystick" and "Joystick" was there in the code you copied?

Here's the original

Joystick_ Joystick(JOYSTICK_DEFAULT_REPORT_ID,JOYSTICK_TYPE_GAMEPAD

See the difference?

No, originally it was:
Joystick_ Joystick(JOYSTICK_DEFAULT_REPORT_ID, JOYSTICK_TYPE_GAMEPAD,
0, 0, // Button Count, Hat Switch Count
true, true, false, // X, Y, Z
true, true, false, // Rx, Ry, Rz
false, false, // Rudder, Throttle
false, false, false); // Accelerator, Brake, Steering

There's a space between Joystick_ & the rest. But it threw out other errors

New error list:

Arduino: 1.8.19 (Windows 10), Board: "Arduino Micro"

RCUSB4:15:1: error: 'Joystick_' does not name a type; did you mean 'Joystick'?

Joystick_ Joystick(JOYSTICK_DEFAULT_REPORT_ID, JOYSTICK_TYPE_GAMEPAD,

^~~~~~~~~

Joystick

C:\Users\Army_\Documents\Arduino\RCUSB4_v1.1\RCUSB4\RCUSB4.ino: In function 'void setup()':

RCUSB4:31:11: error: expected unqualified-id before '.' token

Joystick.begin();

       ^

RCUSB4:32:11: error: expected unqualified-id before '.' token

Joystick.setXAxisRange(2250, 750);

       ^

RCUSB4:33:11: error: expected unqualified-id before '.' token

Joystick.setYAxisRange(2250, 750);

       ^

RCUSB4:34:11: error: expected unqualified-id before '.' token

Joystick.setRxAxisRange(2250, 750);

       ^

RCUSB4:35:11: error: expected unqualified-id before '.' token

Joystick.setRyAxisRange(2250, 750);

       ^

C:\Users\Army_\Documents\Arduino\RCUSB4_v1.1\RCUSB4\RCUSB4.ino: In function 'void loop()':

RCUSB4:53:13: error: expected unqualified-id before '.' token

 Joystick.setXAxis(NewValue[0]);

         ^

RCUSB4:60:13: error: expected unqualified-id before '.' token

 Joystick.setYAxis(NewValue[1]);

         ^

RCUSB4:67:13: error: expected unqualified-id before '.' token

 Joystick.setRxAxis(NewValue[2]);

         ^

RCUSB4:74:13: error: expected unqualified-id before '.' token

 Joystick.setRyAxis(NewValue[3]);

         ^

exit status 1

'Joystick_' does not name a type; did you mean 'Joystick'?

This report would have more information with
"Show verbose output during compilation"
option enabled in File -> Preferences.

There should be a space after the underscore.

It's clearly there on GitHub.

Open up your Joystick.h - that should tell you.

Correct, but there are still errors that I can't correct on my own. I just posted the new error list from changing it back to the "space" between the two.

exit status 1

'Joystick_' does not name a type; did you mean 'Joystick'?

Please post the contents of your Joystick.h

#ifndef __JOYSTICK_h
#define __JOYSTICK_h

#include "Arduino.h"

class Joystick {
public: Joystick(int, int, int);
void printX(String, int, int);
void printY(String, int, int);
void printZ(String);
void print(String, String, String, int, int);
String toString();
private: int pinX;
int pinY;
int pinZ;
};

#endif

Is that all of it?

Because I can't see a

setRyAxisRange

function in there (and I suspect neither will the compiler)

Please remember to use code tags when posting code.

I appreciate your help. I was able to get it to compile.
First error "Joystick_ Joystick"
Second error: used correct joystick.h file. There was another file from a different project labeled the same and it was trying to use the other.

Next time you post… please use CODE TAGS .

Thanks

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