This uses the amazing Puck.js (v2) to control media playback and volume via BLE media control.
It translates physical rotation of the Puck into a change in device volume.
- Short press: play/pause
- Long press: CW rotation --> increase volume, CCW rotation --> decrease volume
Espruino YT channel - DIY Hands-free music control with Puck.js This is how I initially found out about the Puck.js. The corresponding code for the video can be found here.
Aaron McBride YT channel - Puck.js Volume Knob Sadly, there was no documentation given on how this was achieved.
The magnetometer of the Puck.js is read out at a predefined interval, an "azimuthal" heading is calculated and then compared to the previous heading. The difference is used to differentiate between CW and CCW rotation, resulting in a command for increasing/decreasing the volume.
The code might be a bit rough, but this was my first project with this device.
Just transfer the code in code.js
via Espruinos Web IDE and web BLE in Chrome to your Puck.js and pair with a phone/computer.