joystick code error?

I am building a usb handbrake for sim racing copying this video DIY Analog USB Handbrake - YouTube

Now I have copied the code in the video but it will not compile.

I am using a pro micro but windows 10 sees it as a leonardo

Now here is the code

#include <Joystick.h>

void setup()

{pinMode(A3, INPUT);

   Joystick.begin();}

const int pinToButtonMap = A3;

void loop()

{int pot = analogRead(A3);
int mapped = map(pot,525,870,0,255);
{Joystick.setThrottle(mapped);}}

And here is the error message

R:\Mark\new gaming sim pc\handbrake mod\Analog-E-Brake-master (1)\Analog-E-Brake-master\ANALOG_EBRAKE\ANALOG_EBRAKE.ino: In function 'void setup()':
ANALOG_EBRAKE:7:12: error: expected unqualified-id before '.' token
Joystick.begin();}
^
R:\Mark\new gaming sim pc\handbrake mod\Analog-E-Brake-master (1)\Analog-E-Brake-master\ANALOG_EBRAKE\ANALOG_EBRAKE.ino: In function 'void loop()':
ANALOG_EBRAKE:15:10: error: expected unqualified-id before '.' token
{Joystick.setThrottle(mapped);}}
^
exit status 1
expected unqualified-id before '.' token

Now if anyone can help me out that would be great.

Aren't you forgetting to create a joystick object? Look at the examples to see how to use the library.
Object declaration:

Joystick_ Joystick;

Here is your code with the joystick object declared and code formatted with the IDE tool, autoformat (ctrl-t or Tools, Auto Format). It compiles with no errors or warnings. It is, however, untested as I do not have a Leo.

#include <Joystick.h>

Joystick_ Joystick;  // ********  added declaration

void setup()

{
   pinMode(A3, INPUT);  // ************ unnecessary as the pin defaults to input

   Joystick.begin();
}

const int pinToButtonMap = A3;  // *********** not used, why bother

void loop()
{
   int pot = analogRead(A3);
   int mapped = map(pot, 525, 870, 0, 255);
   {
      Joystick.setThrottle(mapped);
   }
}

groundFungus:
Aren't you forgetting to create a joystick object? Look at the examples to see how to use the library.
Object declaration:

Joystick_ Joystick;

Here is your code with the joystick object declared and code formatted with the IDE tool, autoformat (ctrl-t or Tools, Auto Format). It compiles with no errors or warnings. It is, however, untested as I do not have a Leo.

#include <Joystick.h>

Joystick_ Joystick;  // ********  added declaration

void setup()

{
  pinMode(A3, INPUT);  // ************ unnecessary as the pin defaults to input

Joystick.begin();
}

const int pinToButtonMap = A3;  // *********** not used, why bother

void loop()
{
  int pot = analogRead(A3);
  int mapped = map(pot, 525, 870, 0, 255);
  {
     Joystick.setThrottle(mapped);
  }
}

Thanks for that I have tried but when I compile it I get the following error
Arduino: 1.8.14 Hourly Build 2021/01/29 11:33 (Windows 10), Board: "Arduino Leonardo"

ANALOG_EBRAKE:3:1: error: 'Joystick_' does not name a type; did you mean 'Joystick'?
Joystick_ Joystick; // ******** added declaration
^~~~~~~~~
Joystick
R:\Mark\new gaming sim pc\handbrake mod\Analog-E-Brake-master (1)\Analog-E-Brake-master\ANALOG_EBRAKE\ANALOG_EBRAKE.ino: In function 'void setup()':
ANALOG_EBRAKE:10:12: error: expected unqualified-id before '.' token
Joystick.begin();
^
R:\Mark\new gaming sim pc\handbrake mod\Analog-E-Brake-master (1)\Analog-E-Brake-master\ANALOG_EBRAKE\ANALOG_EBRAKE.ino: In function 'void loop()':
ANALOG_EBRAKE:20:15: error: expected unqualified-id before '.' token
Joystick.setThrottle(mapped);
^
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.

So there must be more than one version of the Joystick library and I picked the wrong one. Please provide a link to the library that you are using.

Go to the examples that come with the library that you have and look at how the Joystick object is declared.

Did you try:

#include <Joystick.h>

Joystick joystick;  // ********  note lower case j

void setup()

{
   pinMode(A3, INPUT); 

   joystick.begin();  // ********  note lower case j
}

const int pinToButtonMap = A3;  // *********** not used, why bother

void loop()
{
   int pot = analogRead(A3);
   int mapped = map(pot, 525, 870, 0, 255);
   {
      joystick.setThrottle(mapped); // ********  note lower case j
   }
}

The library I am using can be downloaded here 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.

I have fixed it I just used a different pc and all compiled and uploaded fine. so thanks for your help

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