Advertisement
Guest User

Untitled

a guest
Aug 28th, 2020
286
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.20 KB | None | 0 0
  1. #include "HID-Project.h"
  2.  
  3.  
  4. #define pageup 16
  5. #define pagedwn 10
  6.  
  7. #define mouseleft A3
  8. #define mouseright A1
  9. //#define mousemiddle 4
  10.  
  11. //#define mousescrolldown 5
  12. //#define mousescrollup 6
  13.  
  14. #define mouseXp 14
  15. #define mouseXm A0
  16. #define mouseYp 15
  17. #define mouseYm A2
  18.  
  19. //#define led 3
  20.  
  21. int8_t Xval = 0 ;
  22. int8_t Yval = 0 ;
  23. int8_t scrollval = 0;
  24. bool pageuppressed = 0 ;
  25. bool pagedwnpressed = 0 ;
  26.  
  27.  
  28.  
  29.  
  30.  
  31.  
  32.  
  33. void setup() {
  34.  
  35. //Serial.begin(9600);
  36.  
  37. //Serial.println("hello");
  38.  
  39. // pinMode(led, OUTPUT);
  40. // analogWrite(led, 0);
  41.  
  42. pinMode(pageup, INPUT_PULLUP);
  43. pinMode(pagedwn, INPUT_PULLUP);
  44.  
  45. pinMode(mouseleft, INPUT_PULLUP);
  46. pinMode(mouseright, INPUT_PULLUP);
  47. // pinMode(mousemiddle, INPUT_PULLUP);
  48.  
  49. // pinMode(mousescrolldown, INPUT_PULLUP);
  50. // pinMode(mousescrollup, INPUT_PULLUP);
  51.  
  52. pinMode(mouseXp, INPUT_PULLUP);
  53. pinMode(mouseXm, INPUT_PULLUP);
  54. pinMode(mouseYp, INPUT_PULLUP);
  55. pinMode(mouseYm, INPUT_PULLUP);
  56.  
  57. Mouse.begin();
  58. Keyboard.begin();
  59.  
  60. }
  61.  
  62. void loop() {
  63.  
  64. delay(20) ;
  65.  
  66. bool isPageup = digitalRead(pageup) ;
  67. if(isPageup == LOW && pageuppressed == 0){
  68. //Serial.println("PAGE UP");
  69. Keyboard.press(KEY_PAGE_UP);
  70. pageuppressed = 1 ;
  71. }
  72. if (isPageup == HIGH && pageuppressed == 1) {
  73. Keyboard.release(KEY_PAGE_UP);
  74. pageuppressed = 0 ;
  75. }
  76.  
  77.  
  78. bool isPagedwn = digitalRead(pagedwn) ;
  79. if(isPagedwn == LOW && pagedwnpressed == 0){
  80. //Serial.println("PAGE DOWN");
  81. Keyboard.press(KEY_PAGE_DOWN);
  82. pagedwnpressed = 1 ;
  83. }
  84. if (isPagedwn == HIGH && pagedwnpressed == 1) {
  85. Keyboard.release(KEY_PAGE_DOWN);
  86. pagedwnpressed = 0 ;
  87. }
  88.  
  89.  
  90.  
  91.  
  92. if(digitalRead(mouseleft) == LOW){
  93. if(Mouse.isPressed(MOUSE_LEFT) == LOW){
  94. //Serial.println("MOUSE_LEFT");
  95. Mouse.press(MOUSE_LEFT);
  96. }
  97. } else if (Mouse.isPressed(MOUSE_LEFT)){
  98. Mouse.release(MOUSE_LEFT);
  99. }
  100.  
  101. if(digitalRead(mouseright) == LOW){
  102. if(Mouse.isPressed(MOUSE_RIGHT) == LOW){
  103. //Serial.println("MOUSE_RIGHT");
  104. Mouse.press(MOUSE_RIGHT);
  105. }
  106. } else if (Mouse.isPressed(MOUSE_RIGHT)){
  107. Mouse.release(MOUSE_RIGHT);
  108. }
  109.  
  110. // if(digitalRead(mousemiddle) == LOW){
  111. // if (Mouse.isPressed(MOUSE_MIDDLE) == LOW){
  112. // //Serial.println("MOUSE_MIDDLE");
  113. // Mouse.press(MOUSE_MIDDLE);
  114. // }
  115. // } else if (Mouse.isPressed(MOUSE_MIDDLE)){
  116. // Mouse.release(MOUSE_MIDDLE);
  117. // }
  118.  
  119.  
  120.  
  121. scrollval = 0;
  122. // if(digitalRead(mousescrolldown) == LOW){
  123. // //Serial.println("mousescrolldown");
  124. // scrollval = -1;
  125. // }
  126. // if(digitalRead(mousescrollup) == LOW){
  127. // //Serial.println("mousescrollup");
  128. // scrollval = 1;
  129. // }
  130.  
  131.  
  132. if(digitalRead(mouseXp) == HIGH && digitalRead(mouseXm) == HIGH){
  133. Xval = 0 ;
  134. }
  135. if(digitalRead(mouseXp) == LOW){
  136. //Serial.println("mouseXp");
  137. Xval++ ;
  138. }
  139. if(digitalRead(mouseXm) == LOW){
  140. //Serial.println("mouseXm");
  141. Xval-- ;
  142. }
  143.  
  144.  
  145. if(digitalRead(mouseYp) == HIGH && digitalRead(mouseYm) == HIGH){
  146. Yval = 0 ;
  147. }
  148. if(digitalRead(mouseYp) == LOW){
  149. //Serial.println("mouseYp");
  150. Yval++ ;
  151. }
  152. if(digitalRead(mouseYm) == LOW){
  153. //Serial.println("mouseYm");
  154. Yval-- ;
  155. }
  156.  
  157. if(scrollval != 0 || Xval != 0 || Yval != 0 ){
  158. Mouse.move(Xval, Yval, scrollval);
  159. }
  160.  
  161.  
  162. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement