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:
/*
- kekse23.de RCUSB4 v1.1
- Copyright (c) 2020, Nicholas Regitz
- Diese Datei ist Lizensiert unter der Creative Commons 4.0 CC BY-NC-SA
-
Creative Commons — Attribution-NonCommercial-ShareAlike 4.0 International — CC BY-NC-SA 4.0
*/
#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