Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "ADNS3050.h"
- #include <SPI.h>
- #include <Mouse.h>
- #include <Keyboard.h>
- #include "Rotary.h"
- //https://github.com/buxtronix/arduino/blob/master/libraries/Rotary/examples/poll/poll.ino
- byte x = 0;
- byte y = 0;
- unsigned long timerMillis = 0;
- // 5 pin Rotary encoder is wired with the common to ground and the two
- // outputs to pins 2 and 5. push button is wired to pin 12 and ground.
- Rotary rotary = Rotary(5, 2);
- void setup() {
- startup();//setup communication
- pinMode(4, INPUT_PULLUP);
- pinMode(8, INPUT_PULLUP);
- pinMode(9, INPUT_PULLUP);
- pinMode(12, INPUT_PULLUP);
- Mouse.begin(); //start mouse emulation
- }
- void loop() {
- x = getX();
- y = 0 - getY();
- Mouse.move(x, y, 0); //Move the cursor
- unsigned char result = rotary.process();
- if (result == DIR_CW) {
- x = getX();
- y = 0 - getY();
- Mouse.move(x, y, -1);
- } else if (result == DIR_CCW) {
- x = getX();
- y = 0 - getY();
- Mouse.move(x, y, 1);
- }
- while (digitalRead(4) == 0) { //if the the right mouse button is pressed, press it
- Mouse.press(MOUSE_RIGHT);
- // while it is pressed move the cursor if the mouse is moved
- x = getX();
- y = 0 - getY();
- Mouse.move(x, y, 0);
- }
- Mouse.release(MOUSE_RIGHT);//release the right mouse button
- while (digitalRead(8) == 0) { //if the the middle mouse button is pressed, press it
- Mouse.press(MOUSE_MIDDLE);
- // while it is pressed move the cursor if the mouse is moved
- x = getX();
- y = 0 - getY();
- Mouse.move(x, y, 0);
- }
- Mouse.release(MOUSE_MIDDLE);//release the middle mouse button
- while (digitalRead(9) == 0) { //if the the left mouse button is pressed, press it
- Mouse.press(MOUSE_LEFT);
- // while it is pressed move the cursor if the mouse is moved
- x = getX();
- y = 0 - getY();
- Mouse.move(x, y, 0);
- }
- Mouse.release(MOUSE_LEFT);//release the left mouse button
- while (digitalRead(12) == 0) {
- Keyboard.write(KEY_F5);
- // while it is pressed move the cursor if the mouse is moved
- x = getX();
- y = 0 - getY();
- Mouse.move(x, y, 0);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement