0

I want to move the mouse pointer with an Arduino and ultrasonic sensor but when I compiled it says

Mouse.h not found

and I don't know what I can do.

Here is my code;

 #include <Mouse.h>
int echoPinCursor=2;
int trigPinCursor=3;
int echoPinBtn=4;
int trigPinBtn=5;
int echoPinScroll=6;
int trigPinScroll=7;
int x;
int y;
long duracionCursor, distanciaCursor;
void setup() {
 Serial.begin(9600);
 pinMode(trigPinCursor, OUTPUT);
 pinMode(echoPinCursor, INPUT);
 pinMode(trigPinBtn, OUTPUT);
 pinMode(echoPinBtn, INPUT);
 pinMode(trigPinScroll, OUTPUT);
 pinMode(echoPinScroll, INPUT);
}
void loop() {
 //mover el cursor
 int direccionx=moverx();
 int direcciony=movery();
 Mouse.move(direccionx, direcciony,0);
 delay(2);
}
int moverx(){
 distanciaCursor=obtener_distanciaCursor();
 if (distanciaCursor >= 1 || distanciaCursor <= 11){
 x--;
 }
 if (distanciaCursor >= 12 || distanciaCursor <= 24){
 x++;
 }
 return x;
}
int movery(){
 distanciaCursor=obtener_distanciaCursor();
 if (distanciaCursor >= 25 || distanciaCursor <= 37){
 y--;
 }
 if (distanciaCursor >= 38 || distanciaCursor <= 50){
 y++;
 }
 return y;
}
long obtener_distanciaCursor(void)
{
 digitalWrite(trigPinCursor, LOW);
 delayMicroseconds(2);
 digitalWrite(trigPinCursor, HIGH);
 delayMicroseconds(10);
 digitalWrite(trigPinCursor, LOW);
 duracionCursor = pulseIn(echoPinCursor, HIGH);
 distanciaCursor = duracionCursor/58.2;
return(distanciaCursor);
}
Greenonline
3,1527 gold badges36 silver badges48 bronze badges
asked Nov 24, 2015 at 23:20

1 Answer 1

2

That's because the Uno can't be a mouse. For that you need the Leonardo or something else with a similar "U" style microcontroller.

If you are adventurous, and you have a genuine Arduino, you can reprogram the USB controller chip with new firmware so it thinks it's a mouse, but programming the main MCU is then a real chore.

answered Nov 24, 2015 at 23:27

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.