I'm making arduino trackpad, aka convert ps2 to usb. I have problem that serial communication is not working when ps2 is doing something, when I comment out ps2 commands in loop function then it works Serial communication works perfectly. I tried with Serial and SerialUSB, no luck.
#include <Mouse.h>
#include <ps2.h>
#define PS2_DATA 10
#define PS2_CLK 9
PS2 mouse(10, 9);
void setup() {
mouse.write(0xff); // Reset
mouse.read(); // ACK byte
mouse.read(); // Blank
mouse.read(); // Blank
mouse.write(0xf0); // Remote mode
mouse.read(); // ACK
delayMicroseconds(100);
//Mouse.begin();
SerialUSB.begin(9600);
while (!SerialUSB);
SerialUSB.println("Hello!");
}
void loop() {
char mstat;
char mx;
char my;
char mz;
mouse.write(0xeb); // Give me data
mouse.read(); // Ignore ack
mstat = mouse.read();
mx = mouse.read();
my = mouse.read();
mz = mouse.read();
SerialUSB.print("X: ");
SerialUSB.print(mx);
SerialUSB.print(" Y: ");
SerialUSB.print(my);
SerialUSB.print(" Z: ");
SerialUSB.println(mz);
SerialUSB.flush();
delay(1000);
//Mouse.move(mx, -my);
}