I am running the following code to move the mouse and click it using input from the keyboard:
void setup() {
// initialize serial communications at 9600 bps:
Serial.begin(9600);
Mouse.begin();
}
void loop() {
// use serial input to control the mouse:
if (Serial.available() > 0) {
char inChar = Serial.read();
Mouse.begin();
switch (inChar) {
case 'u':
// move mouse up
Serial.println("u received");
Mouse.move(0, -40);
break;
case 'd':
// move mouse down
Mouse.move(0, 40);
break;
case 'l':
// move mouse left
Mouse.move(-40, 0);
break;
case 'r':
// move mouse right
Mouse.move(40, 0);
break;
case 'm':
// perform mouse left click
Mouse.click(MOUSE_LEFT);
break;
}
}
}
When I run my code on the Arduino Due, and send 'u' on the serial port for example, which should move my mouse cursor up, nothing at all happens. Same goes for Mouse.click(). I have no idea what I'm doing incorrectly.