error: 'Joystick' was not declared in this scope

A friend of mine gave me a code to use but it wont work because of joystick not declared ....
the problem is in the void setup

 #include <Encoder.h>

#include <Joystick.h>



#include <Joystick.h>

long oldPosition  = -999;

Encoder myEnc(5,6);


void setup() {
  Serial.begin(9600);
  Serial.println("Basic Encoder Test:");

  
 [color=red] Joystick.begin();[/color]
}

void loop() {
  
long newPosition = myEnc.read();
  if (newPosition != oldPosition) {
    oldPosition = newPosition;
    Serial.println(newPosition);
  }
 
Joystick.setXAxis(newPosition);

  delay(10);
}

Which Arduino board are you compiling for ?

Most don't support the Joystick library

You're missing

#include <Encoder.h>
#include <Joystick.h>

// Create Joystick
Joystick_ Joystick;

...
...

arduino micro

Hello,

I rewriten a code that uses a rotary encoder to control a X or Y axis but up on uploading it said that the Joystick was not declared in this scope. I need help

#include <Joystick.h>
#include <Encoder.h>
Encoder knobLeft(5, 6);

void setup() {
  Serial.begin(9600);
  Serial.println("MUhahah:");
}

long positionLeft  = -999;

void loop() {
  long newLeft, newRight;
  newLeft = knobLeft.read();
  
  if (newLeft != positionLeft ) {
    Serial.print("Left = ");
    Serial.print(newLeft);
   
    Serial.println();
    positionLeft = newLeft;
  
  }
    
  if (Serial.available()) {
    Serial.read();
    Serial.println("Reset");
    knobLeft.write(0);
  
  }
  Joystick.setXAxis(positionLeft);

  delay(10);

I hope someone can help me resolve my issue

Threads merged.