Error programming a sequential gear knob

Hi, one year ago i built a sequential gear lever and a handbrake lever for racing simulators, but the old PC is off.. now i have to re-write the sketch, but i have an issue..
I Use Arduino LEonardo, I have two buttons for the gear lever and a potentiometer for the handbrake... the buttons are one normally open, and one normally closed... I used the Martini joystick library, otherwise the games won't recognize my Arduino..now the sketch


#include <Joystick.h>

int pulsante6 = 5;

int pulsante8 = 7;

void setup()

{

  pinMode(pulsante6, INPUT);

  pinMode(pulsante8, INPUT);

  pinMode(A2, INPUT);
  Joystick begin ();
}



void loop() 
{

  if (digitalRead(pulsante6) == LOW) {Joystick.setButton(5, HIGH);}
   else Joystick.setButton(5, LOW);
  }

  if (digitalRead(pulsante8) == LOW) {Joystick.setButton(7, HIGH);
  } else {Joystick.setButton(7, LOW);
  }


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

and there the errors..


C:\Users\Andrea\Documents\DEFINITIVO\DEFINITIVO.ino: In function 'void loop()':
C:\Users\Andrea\Documents\DEFINITIVO\DEFINITIVO.ino:24:47: error: expected unqualified-id before '.' token
   if (digitalRead(pulsante6) == LOW) {Joystick.setButton(5, HIGH);}
                                               ^
C:\Users\Andrea\Documents\DEFINITIVO\DEFINITIVO.ino:25:17: error: expected unqualified-id before '.' token
    else Joystick.setButton(5, LOW);
                 ^
C:\Users\Andrea\Documents\DEFINITIVO\DEFINITIVO.ino: At global scope:
C:\Users\Andrea\Documents\DEFINITIVO\DEFINITIVO.ino:28:3: error: expected unqualified-id before 'if'
   if (digitalRead(pulsante8) == LOW) {Joystick.setButton(7, HIGH);
   ^~
C:\Users\Andrea\Documents\DEFINITIVO\DEFINITIVO.ino:29:5: error: expected unqualified-id before 'else'
   } else {Joystick.setButton(7, LOW);
     ^~~~
C:\Users\Andrea\Documents\DEFINITIVO\DEFINITIVO.ino:35:11: error: expected unqualified-id before '.' token
   Joystick.setThrottle(mapped);

I have read many guides, posts, examples on the net but I haven't been able to find an answer.. can anyone help me? Thank you

Welcome to the forum

Your sketch has a number of mistakes in it

You do not have an object named Joystick in it
Look at the Joystick examples to see how to create it

  Joystick begin ();

This should be

  Joystick.begin ();
void loop() 
{

  if (digitalRead(pulsante6) == LOW) {Joystick.setButton(5, HIGH);}
   else Joystick.setButton(5, LOW);
  }

The loop() function has its terminating } in the wrong place, hence the code that follows it is outside of a function. This is much easier to see if you format your code like this

void loop()
{
    if (digitalRead(pulsante6) == LOW)
    {
        Joystick.setButton(5, HIGH);
    }
    else
        Joystick.setButton(5, LOW);
}

if (digitalRead(pulsante8) == LOW)