Advertisement
nyptus

yotube-controller.ino

Aug 20th, 2023 (edited)
1,268
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Arduino 3.57 KB | Source Code | 0 0
  1. /*
  2. What is it?
  3. -----------
  4. Controller for Youtube video playback: Pause/Play (k), Backward (j)/Forward (l), Volume Up (up)/Down (down).
  5.  
  6. The Latest Version
  7. ------------------
  8. Versioning is not applicable for this repo.
  9.  
  10. Documentation
  11. -------------
  12. You can read in header of files and, maybe, README for each folder will be created.
  13.  
  14. Requirements
  15. ------------
  16. Gyver EncButton library https://github.com/GyverLibs/EncButton
  17.  
  18. Installation
  19. ------------
  20. Arduino IDE => Tools => Board => "Arduino Leonardo"
  21.  
  22. Licensing
  23. ---------
  24. Please see the file called LICENSE.
  25.  
  26. Contacts
  27. --------
  28. If you have a concrete bug report please contact me via email.
  29.  
  30. Connections
  31. ----------
  32. Arduino Leonardo or same
  33.    S1 - D3
  34.    S2 - D2
  35.    Key - D4
  36.  
  37. Miscellaneous
  38. ----------
  39.  
  40. Keyboard shortcut   Function
  41. Spacebar              Play/Pause when the seek bar is selected. Activate a button if a button has focus.
  42. k                   Pause/Play in player.
  43. m                   Mute/unmute the video.
  44. Left/Right          Seek backward/forward 5 seconds.
  45. j                   Seek backward 10 seconds in player.
  46. l                   Seek forward 10 seconds in player.
  47. .                   While the video is paused, skip to the next frame.
  48. ,                   While the video is paused, go back to the previous frame.
  49. >                   Speed up the video playback rate.
  50. <                   Slow down the video playback rate.
  51. Up/Down             Increase/Decrease volume 5%.
  52. Numbers 1 to 9      Seek to the 10% to 90% of the video.
  53. Number 0              Seek to the beginning of the video.
  54. /                   Go to search box.
  55. f                   Activate full screen.
  56. c                   Activate closed captions and subtitles if available.
  57. Shift+N               Move to the next video
  58. Shift+P               Move to the previous video.
  59. i                   Open the Miniplayer.
  60.  
  61. Controller for Youtube video playback:
  62. Pause/Play (k),
  63. Backward (j)/Forward (l),
  64. Volume Up (up)/Down (down).
  65. */
  66.  
  67. #include <Arduino.h>
  68. #include <Keyboard.h>
  69. #include <EncButton.h>
  70.  
  71. const int ENCA = 2;
  72. const int ENCB = 3;
  73. const int BTN = 4;
  74.  
  75. EncButton enc(ENCA, ENCB, BTN);
  76.  
  77. volatile int value = 0;
  78. volatile int step = 3;  //1 шаг за каждые step сигналов энкодера, чтобы снизить чувствительность (так удобнее)
  79.  
  80. void setup() {
  81.   Serial.begin(115200);
  82.  
  83.   enc.setEncType(EB_STEP4_LOW);
  84.  
  85.   // показаны значения по умолчанию
  86.   enc.setBtnLevel(LOW);
  87.   enc.setClickTimeout(500);
  88.   enc.setDebTimeout(50);
  89.   enc.setHoldTimeout(600);
  90.   enc.setStepTimeout(200);
  91.   enc.setEncReverse(0);
  92.   enc.setFastTimeout(30);
  93. }
  94.  
  95. void loop() {
  96.   enc.tick();  // опрос происходит здесь
  97.  
  98.   if (enc.right())
  99.   {
  100.     value = value + step; //поворот вправо
  101.   }
  102.   if (enc.left())
  103.   {
  104.     value = value - step; //поворот влево
  105.   }
  106.  
  107.   if (enc.leftH()) {
  108.     Keyboard.press(KEY_UP_ARROW);
  109.     delay(10);
  110.     Keyboard.releaseAll();
  111.  
  112.   }
  113.   if (enc.rightH()) {
  114.     Keyboard.press(KEY_DOWN_ARROW);
  115.     delay(10);
  116.     Keyboard.releaseAll();
  117.   }
  118.  
  119.   if (enc.click()) {
  120.     Keyboard.press('K');
  121.     delay(10);
  122.     Keyboard.releaseAll();
  123.   }
  124.  
  125.   if (value > 9) {
  126.     Keyboard.press('J'); // каждые value поворотов вправо нажимаем J
  127.     delay(10);
  128.     Keyboard.releaseAll();
  129.     value = 0;
  130.   }
  131.   if (value < -9) {
  132.     Keyboard.press('L'); // каждые value поворотов влево нажимаем
  133.     delay(10);
  134.     Keyboard.releaseAll();
  135.     value = 0;
  136.   }
  137. }
  138.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement