This is the code that I used (from one of the comments in the Instructables page):
/*
* PSMouse Library - http://github.com/jazzycamel/PS2Mouse
* Script adapted by Collie147 from example - added Mouse.h and press/release functions
*/
#include "PS2Mouse.h"
#include "Mouse.h"
PS2Mouse PS2mouse(9,10)
void setup(){
Mouse.begin();
PS2mouse.begin();
}
void loop(){
uint8_t stat;
int x,y;
PS2mouse.getPosition(stat,x,y);
Mouse.move(x, -y, 0);
if (bitRead(stat, 0) == 1){
Mouse.press();
}
else{
Mouse.release();
}
}
This makes the touchpad work as a USB mouse, and double-tap to double-click works.
However, I am unable to scroll or right-click using the touchpad. Is there some code I can add that will enable this? Do I need a different library? Are there different connections that should be made between the two boards?
The Mouse library doesn't support scrolling but you can add the right click using the following code segment, given the used touchpad supports right clicks:
if (bitRead(stat, 2) == 1){
Mouse.press(MOUSE_RIGHT);
}
else{
Mouse.release(MOUSE_RIGHT);
}
This doesn't seem to be working, but maybe I'm adding it to the wrong section? It compiles and uploads successfully, but then it does not seem to register as a HID.
Here is my code as it stands.
/*
* PSMouse Library - http://github.com/jazzycamel/PS2Mouse
* Script adapted by Collie147 from example - added Mouse.h and press/release functions
*/
#include "PS2Mouse.h"
#include "Mouse.h"
PS2Mouse PS2mouse(9,10);
void setup(){
Mouse.begin();
PS2mouse.begin();
}
void loop(){
uint8_t stat;
int x,y;
PS2mouse.getPosition(stat,x,y);
Mouse.move(x, -y, 0);
if (bitRead(stat, 0) == 1){
Mouse.press();
}
else{
Mouse.release();
}
if (bitRead(stat, 2) == 1){
Mouse.press(MOUSE_RIGHT);
}
else{
Mouse.release(MOUSE_RIGHT);
}
}
}
I appreciate any assistance.
EDIT: It seems that if I disconnect and then re-connect the ground wire, the touchpad does work again, but right clicking still does not. Note that simply unplugging the USB and plugging it back in again does not seem to do the trick.