Mouse.Begin(); not working

there is an error with Mouse.begin(); even though I had the #include <Mouse.h>

‘Mouse’ not found. Does your sketch include the line ‘#include <Mouse.h>’?

If you only need to make relative movements, just use Mouse.move():
https://www.arduino.cc/reference/en/language/functions/usb/mouse/mousemove/

If you need to move the mouse pointer to absolute coordinates, it's a bit more tricky. I wrote a library that does this in a very crude manner, by "homing" the mouse pointer to the corner of the screen to get it to a known starting position, then making relative move from there to the target coordinates:

There are some alternatives that may accomplish this in a more "pro" manner. I have listed the ones I'm aware of in the readme:

Because my library met my own needs perfectly, I haven't tried any of the alternatives.

I did it and its having this error when I typed Mouse.begn(); even though I had the #include <Mouse.h>

‘Mouse’ not found. Does your sketch include the line ‘#include <Mouse.h>’?

I did what the error told me to do and it still shows up, any ideas why?

profmonkey07:
I did what the error told me to do and it still shows up, any ideas why?

Did you do declare #include<Mouse.h> before the void setup() and void loop()? That is:

#include<Mouse.h>

void setup() {

}
void loop() {

}
// Did you?

profmonkey07:
I did it and its having this error when I typed Mouse.begn();

It’s Mouse.begin();

heres my script

#include <Mouse.h>

int sensorValuex = 0;
int sensorValuey = 0;

void setup() {
Mouse.begin();
Serial.begin(9600);
int sensorValuex = 0;
int sensorValuey = 0;
}

void loop() {
Mouse.move(sensorValuex, sensorValuey, 0);
// put your main code here, to run repeatedly:
int sensorValuex = analogRead(A0);
int sensorValuey = analogRead(A1);
Serial.println(“sensorvaluex =”);
Serial.println(sensorValuex);
Serial.println(“sensorvaluey =”);
Serial.println(sensorValuey);
analogWrite(13, sensorValuex);
}

I dont see anything wrong with my script, so maybe there are other issues outside the base code?

Which Arduino board do you have selected from the Arduino IDE's Tools > Board menu?

mega2560 its the arduino I am using

and its attached to a joystick

You need a board with native USB support that can act as a HID; the mega is not one of them

If you have a need for all those pins, get a Due (it's 3.3V). If you have a need for a 5V board, get a Leonardo, Micro or ProMicro.

profmonkey07:
int sensorValuex = 0;
int sensorValuey = 0;

void setup() {

int sensorValuex = 0;
int sensorValuey = 0;

Oops...Multiple declaration?

TheUNOGuy:
Oops…Multiple declaration?

…which immediately goes out of scope.
No problem :wink:

I’d be more concerned about

analogWrite(13, sensorValuex);
}