Hello guys, I'm trying to connect a mouse in Arduino Leonardo, I would like to catch the mouse data and converts to centimeters and make a ruler for a TCC in school, that will be algue there have any idea or library for mouse. Thank you!!!.
(deleted)
Note that the Leonardo/ Micro can emulate a HID device such as a USB mouse, but cannot directly interface as a "host" to a USB mouse.
Code is available for all Arduino variants to interface to a PS/2 mouse. Look for a PS/2 mouse - should be dirt cheap at garage sales.
Yes, I found the mouse library, but when I compile this giving error.
code:
/**
- Reads X/Y values from a PS/2 mouse connected to an Arduino
- using the PS2Mouse library available from
- GitHub - kristopher/PS2-Mouse-Arduino: Arduino/Wiring Library for interfacing with a PS2 mouse.
- Original by Kristopher Chambers kristopher.chambers@gmail.com
- Updated by Jonathan Oxer jon@oxer.com.au
*/
#include <PS2Mouse.h>
#define MOUSE_DATA 5
#define MOUSE_CLOCK 6
PS2Mouse mouse(MOUSE_CLOCK, MOUSE_DATA, STREAM);
void setup() {
Serial.begin(9600);
mouse.initialize();
}
void loop() {
int data[3];
mouse.report(data);
Serial.print(data[0]); // Status Byte
Serial.print(":");
Serial.print(data[1]); // X Movement Data
Serial.print(",");
Serial.print(data[2]); // Y Movement Data
Serial.println();
}
Error:
C:\Program Files (x86)\Arduino\libraries\PS2-Mouse-Arduino-master\PS2Mouse.cpp:1:24: fatal error: WConstants.h: No such file or directory
#include "WConstants.h"
^
compilation terminated.
exit status 1
Error compiling for board Arduino Leonardo.
Biblioteca inválida encontrada em C:\Program Files (x86)\Arduino\libraries__MACOSX: C:\Program Files (x86)\Arduino\libraries__MACOSX
(deleted)
C:\Program Files (x86)\Arduino\libraries\PS2-Mouse-Arduino-master\PS2Mouse.cpp:1:24: fatal error: WConstants.h: No such file or directory
#include "WConstants.h"
The WConstants.h file is for a much older version of the IDE. In the PS2Mouse.cpp file, try replacing #include "WConstants.h with #include <arduino.h>.