{"id":2,"date":"2025-04-23T21:15:40","date_gmt":"2025-04-23T21:15:40","guid":{"rendered":"http:\/\/mrbenshoof.com\/JeffsPlayground\/?page_id=2"},"modified":"2025-04-24T19:38:51","modified_gmt":"2025-04-24T19:38:51","slug":"wind-up-youtube-device-apr-2025","status":"publish","type":"page","link":"https:\/\/mrbenshoof.com\/JeffsPlayground\/wind-up-youtube-device-apr-2025\/","title":{"rendered":"Wind Up YouTube Device &#8211; Apr 2025"},"content":{"rendered":"\n<p>One thing I do too much is watch <a href=\"http:\/\/YouTube.com\" data-type=\"link\" data-id=\"YouTube.com\">YouTube<\/a> videos. While doing so recently, I came across someone jesting at the idea of a device that only lets you watch videos for as long as you&#8217;re cranking the handle of a device.<\/p>\n\n\n\n<p>I found this idea to be funny and novel, and quite possible for me to make in a few hours. So 2 hours later I had this rapid prototype:<\/p>\n\n\n\n<figure class=\"wp-block-image aligncenter size-full is-resized\"><img loading=\"lazy\" decoding=\"async\" width=\"800\" height=\"799\" src=\"http:\/\/mrbenshoof.com\/JeffsPlayground\/wp-content\/uploads\/2025\/04\/IMG_0020-5.png\" alt=\"\" class=\"wp-image-16\" style=\"width:383px;height:auto\" srcset=\"https:\/\/mrbenshoof.com\/JeffsPlayground\/wp-content\/uploads\/2025\/04\/IMG_0020-5.png 800w, https:\/\/mrbenshoof.com\/JeffsPlayground\/wp-content\/uploads\/2025\/04\/IMG_0020-5-300x300.png 300w, https:\/\/mrbenshoof.com\/JeffsPlayground\/wp-content\/uploads\/2025\/04\/IMG_0020-5-150x150.png 150w, https:\/\/mrbenshoof.com\/JeffsPlayground\/wp-content\/uploads\/2025\/04\/IMG_0020-5-768x767.png 768w\" sizes=\"auto, (max-width: 800px) 100vw, 800px\" \/><\/figure>\n\n\n\n<figure class=\"wp-block-image aligncenter size-full is-resized\"><img loading=\"lazy\" decoding=\"async\" width=\"800\" height=\"800\" src=\"http:\/\/mrbenshoof.com\/JeffsPlayground\/wp-content\/uploads\/2025\/04\/IMG_0019.png\" alt=\"\" class=\"wp-image-18\" style=\"width:385px;height:auto\" srcset=\"https:\/\/mrbenshoof.com\/JeffsPlayground\/wp-content\/uploads\/2025\/04\/IMG_0019.png 800w, https:\/\/mrbenshoof.com\/JeffsPlayground\/wp-content\/uploads\/2025\/04\/IMG_0019-300x300.png 300w, https:\/\/mrbenshoof.com\/JeffsPlayground\/wp-content\/uploads\/2025\/04\/IMG_0019-150x150.png 150w, https:\/\/mrbenshoof.com\/JeffsPlayground\/wp-content\/uploads\/2025\/04\/IMG_0019-768x768.png 768w\" sizes=\"auto, (max-width: 800px) 100vw, 800px\" \/><\/figure>\n\n\n\n<p>The device uses a small DC motor with a prebuilt gearbox connected to a Makey Makey (an Atmega32U4 based microcontroller board) which can send keyboard inputs through a USB connection. When the crude handle on the box is spun, it uses the motor as a small generator to produce a current that is sent to the microcontroller. Because the microcontroller uses the grounding of pins to trigger, when we spin a motor connected to the &#8220;A&#8221; pin and GND pin it stops the pin from being grounded. The micro controller then sends the signal to the computer via USB telling it that the &#8220;A&#8221; key is being released. Yes, this means while you&#8217;re not spinning the motor, the computer thinks you&#8217;re holding down the &#8220;A&#8221; key.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">The Programming<\/h2>\n\n\n\n<p>For as long as the motor is spun, the &#8220;A&#8221; key is not read as being pressed, however that by itself doesn&#8217;t start and stop a YouTube video. For that I needed to write a Python script.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>import pynput\nfrom pynput import keyboard\nfrom pynput.keyboard import Controller, Key\nimport sys\n\nkeyboard_controller = Controller()\na_pressed = False\n\ndef on_press(key):\n    global a_pressed\n    try:\n        if key.char == 'a' and not a_pressed:\n            a_pressed = True\n            print(\"Pressed A\")\n            keyboard_controller.press(Key.space)\n            keyboard_controller.release(Key.space)\n        elif key.char == 'j':\n            print(\"Exiting program\")\n            sys.exit()\n    except AttributeError:\n        pass\n\ndef on_release(key):\n    global a_pressed\n    try:\n        if key.char == 'a' and a_pressed:\n            a_pressed = False\n            print(\"Released A\")\n            keyboard_controller.press(Key.space)\n            keyboard_controller.release(Key.space)\n    except AttributeError:\n        pass\n\nwith keyboard.Listener(on_press=on_press, on_release=on_release) as listener:\n    listener.join()<\/code><\/pre>\n\n\n\n<p>*It should be noted that this was written with the assistance of ChatGPT, I&#8217;m still learning Python*<\/p>\n\n\n\n<p>This is a simple script that simulates a press of the space bar whenever the letter &#8220;A&#8221; is released (spinning starts), and simulates it again when the letter &#8220;A&#8221; is pressed (spinning stops). This causes the space bar to be hit both when the motor starts to be spun, and when it stops being spun.<\/p>\n\n\n\n<p>You might notice part of the script is for when &#8220;J&#8221; is pressed, and this is simply a means to stop the program with the &#8216;break&#8217; method.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">The Results<\/h2>\n\n\n\n<p>When you have a YouTube video on the screen thats currently paused, spinning the motor will &#8216;un-ground&#8217; the &#8220;A&#8221; pin on the Makey Makey which sends that signal to the computer. The program on the computer sees that &#8220;A&#8221; is no longer being held down, so it hits space unpausing the video.<\/p>\n\n\n\n<p>When you inevitably get tired and have to stop spinning the motor, the &#8220;A&#8221; pin becomes grounded through the motor, and the script hits the space bar again to pause the video.<\/p>\n\n\n\n<p>Now I can rest easy knowing that as long as I&#8217;m watching YouTube, at least I&#8217;m getting a workout in.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>One thing I do too much is watch YouTube videos. While doing so recently, I came across someone jesting at the idea of a device that only lets you watch videos for as long as you&#8217;re cranking the handle of a device. I found this idea to be funny and novel, and quite possible for [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"parent":0,"menu_order":0,"comment_status":"closed","ping_status":"closed","template":"","meta":{"footnotes":""},"class_list":["post-2","page","type-page","status-publish","hentry"],"_links":{"self":[{"href":"https:\/\/mrbenshoof.com\/JeffsPlayground\/wp-json\/wp\/v2\/pages\/2","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/mrbenshoof.com\/JeffsPlayground\/wp-json\/wp\/v2\/pages"}],"about":[{"href":"https:\/\/mrbenshoof.com\/JeffsPlayground\/wp-json\/wp\/v2\/types\/page"}],"author":[{"embeddable":true,"href":"https:\/\/mrbenshoof.com\/JeffsPlayground\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/mrbenshoof.com\/JeffsPlayground\/wp-json\/wp\/v2\/comments?post=2"}],"version-history":[{"count":7,"href":"https:\/\/mrbenshoof.com\/JeffsPlayground\/wp-json\/wp\/v2\/pages\/2\/revisions"}],"predecessor-version":[{"id":45,"href":"https:\/\/mrbenshoof.com\/JeffsPlayground\/wp-json\/wp\/v2\/pages\/2\/revisions\/45"}],"wp:attachment":[{"href":"https:\/\/mrbenshoof.com\/JeffsPlayground\/wp-json\/wp\/v2\/media?parent=2"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}