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);

}
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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.