Advertisement
Guest User

Untitled

a guest
Feb 26th, 2017
207
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.10 KB | None | 0 0
  1. #include "ADNS3050.h"
  2. #include <SPI.h>
  3. #include <Mouse.h>
  4. #include <Keyboard.h>
  5. #include "Rotary.h"
  6. //https://github.com/buxtronix/arduino/blob/master/libraries/Rotary/examples/poll/poll.ino
  7.  
  8. byte x = 0;
  9. byte y = 0;
  10. unsigned long timerMillis = 0;
  11.  
  12. // 5 pin Rotary encoder is wired with the common to ground and the two
  13. // outputs to pins 2 and 5. push button is wired to pin 12 and ground.
  14. Rotary rotary = Rotary(5, 2);
  15.  
  16. void setup() {
  17. startup();//setup communication
  18.  
  19. pinMode(4, INPUT_PULLUP);
  20. pinMode(8, INPUT_PULLUP);
  21. pinMode(9, INPUT_PULLUP);
  22. pinMode(12, INPUT_PULLUP);
  23.  
  24. Mouse.begin(); //start mouse emulation
  25.  
  26. }
  27.  
  28.  
  29. void loop() {
  30. x = getX();
  31. y = 0 - getY();
  32. Mouse.move(x, y, 0); //Move the cursor
  33.  
  34. unsigned char result = rotary.process();
  35. if (result == DIR_CW) {
  36. x = getX();
  37. y = 0 - getY();
  38. Mouse.move(x, y, -1);
  39. } else if (result == DIR_CCW) {
  40. x = getX();
  41. y = 0 - getY();
  42. Mouse.move(x, y, 1);
  43. }
  44.  
  45. while (digitalRead(4) == 0) { //if the the right mouse button is pressed, press it
  46. Mouse.press(MOUSE_RIGHT);
  47. // while it is pressed move the cursor if the mouse is moved
  48. x = getX();
  49. y = 0 - getY();
  50. Mouse.move(x, y, 0);
  51. }
  52. Mouse.release(MOUSE_RIGHT);//release the right mouse button
  53.  
  54. while (digitalRead(8) == 0) { //if the the middle mouse button is pressed, press it
  55. Mouse.press(MOUSE_MIDDLE);
  56. // while it is pressed move the cursor if the mouse is moved
  57. x = getX();
  58. y = 0 - getY();
  59. Mouse.move(x, y, 0);
  60. }
  61. Mouse.release(MOUSE_MIDDLE);//release the middle mouse button
  62.  
  63. while (digitalRead(9) == 0) { //if the the left mouse button is pressed, press it
  64. Mouse.press(MOUSE_LEFT);
  65. // while it is pressed move the cursor if the mouse is moved
  66. x = getX();
  67. y = 0 - getY();
  68. Mouse.move(x, y, 0);
  69. }
  70. Mouse.release(MOUSE_LEFT);//release the left mouse button
  71.  
  72. while (digitalRead(12) == 0) {
  73. Keyboard.write(KEY_F5);
  74. // while it is pressed move the cursor if the mouse is moved
  75. x = getX();
  76. y = 0 - getY();
  77. Mouse.move(x, y, 0);
  78. }
  79.  
  80. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement