Project 7.03 Move Mouse
This project demonstrates the Mouse object that it supported by the Arno and Arduino Leonardo. Upload the sketch and then press the SW1. Watch the mouse pointer quickly move in a square pattern.
Concepts: Mouse object
Circuits:
Concepts: Mouse object
Circuits:
At the top of the loop() block, we wait until SW1 is pressed. Then we create an instance of the Mouse object:
if(digitalRead(SW1)==LOW){
Mouse.begin();
Next we use the Mouse.move command to move the mouse pointer. Mouse.move has three arguments: the number of pixels to move in the horizontally direction (x-axis), the vertical direction (y-axis) and the amount to move the scroll wheel. The point where the x and y values equal zero (the origin) is at the top-left corner of the screen.
Within the if block, we first move 100 pixels to the right:
for(int x = 0; x < 100; x++){
Mouse.move(1,0,0);
}
Next we move down the screen:
for(int x = 0; x < 100; x++){
Mouse.move(0,1,0);
}
And back left:
for(int x = 0; x < 100; x++){
Mouse.move(-1,0,0);
}
And then back up the where we began:
for(int x = 0; x < 100; x++){
Mouse.move(0,-1,0);
}
That finished the if block:
}//end if for SW1
We could have moved the mouse 100 pixels at a time (e.g, Mouse.move(100,0,0) ) but it can produce a jerky effect. We instead chose to move the mouse pointer 1 pixel at a time within the for loops.
if(digitalRead(SW1)==LOW){
Mouse.begin();
Next we use the Mouse.move command to move the mouse pointer. Mouse.move has three arguments: the number of pixels to move in the horizontally direction (x-axis), the vertical direction (y-axis) and the amount to move the scroll wheel. The point where the x and y values equal zero (the origin) is at the top-left corner of the screen.
Within the if block, we first move 100 pixels to the right:
for(int x = 0; x < 100; x++){
Mouse.move(1,0,0);
}
Next we move down the screen:
for(int x = 0; x < 100; x++){
Mouse.move(0,1,0);
}
And back left:
for(int x = 0; x < 100; x++){
Mouse.move(-1,0,0);
}
And then back up the where we began:
for(int x = 0; x < 100; x++){
Mouse.move(0,-1,0);
}
That finished the if block:
}//end if for SW1
We could have moved the mouse 100 pixels at a time (e.g, Mouse.move(100,0,0) ) but it can produce a jerky effect. We instead chose to move the mouse pointer 1 pixel at a time within the for loops.