Arduino Leonardo usb handbrake

I am using an Arduino leonardo to make a usb handbrake with a 10k potentiometer whenever i upload the code to the leonardo it says that Joystick was not declared in this scope i am following a tutorial that i have linked below and here is the code itself

#include <Joystick.h>

void setup()

{pinMode(A0, INPUT);
Joystick.begin();}

const int pinToButtonMap = A0;

void loop()

{int pot = analogRead(A0);
int mapped = map(pot,0,1023,0,255);
{Joystick.setThrottle(mapped);}}

does anybody have any ideas what to do so this program works for me you will be a lifesaver

If you grabbed the “joystick” library from the Library Manager you got the wrong one. You need to find the library that actually does USB output. It is not available through Library Manager.

where do i get it

Remove the one you installed, the correct one is supplied with the IDE, no need to install any.

Update code

#include <Joystick.h>

void setup()
{
  Joystick.begin();
}

void loop()
{
    Joystick.setThrottle(analogRead(A0)/4);
}

missdrew:
Remove the one you installed, the correct one is supplied with the IDE, no need to install any.

Are you sure? I tried to compile your example for a Leonardo on Arduino 1.8.13.

sketch_nov17a:1:10: fatal error: Joystick.h: No such file or directory
 #include <Joystick.h>
          ^~~~~~~~~~~~
compilation terminated.

sgbsuitelife:
where do i get it

  • Click on the green "Code" button and select "Download ZIP" from the menu.
  • In the IDE, select "Sketch->Include Library->Add .ZIP library..." and point it to the downloaded .ZIP file.

My appologies - While I have never installed the library, someone has on this system.