Spinning the knob changes the volume and clicking the knob plays/pauses the music or video.
#if ARDUINO_USB_MODE
#warning This sketch should be used when USB is in OTG mode
void setup() {}
void loop() {}
#else
#include "USB.h"
#include "USBHIDConsumerControl.h"
#include <CtrlEnc.h>
USBHIDConsumerControl ConsumerControl;
// Define an onTurnleft handler.
void onTurnleft() {
ConsumerControl.press(CONSUMER_CONTROL_VOLUME_DECREMENT);
ConsumerControl.release();
}
// Define an onTurnRight handler.
void onTurnRight() {
ConsumerControl.press(CONSUMER_CONTROL_VOLUME_INCREMENT);
ConsumerControl.release();
}
//-----------------------------------------------------------//
//OTHER CONTROLL OPTIONS
//-----------------------------------------------------------//
/*
// Power Control
#define CONSUMER_CONTROL_POWER 0x0030
#define CONSUMER_CONTROL_RESET 0x0031
#define CONSUMER_CONTROL_SLEEP 0x0032
// Screen Brightness
#define CONSUMER_CONTROL_BRIGHTNESS_INCREMENT 0x006F
#define CONSUMER_CONTROL_BRIGHTNESS_DECREMENT 0x0070
// These HID usages operate only on mobile systems (battery powered) and
// require Windows 8 (build 8302 or greater).
#define CONSUMER_CONTROL_WIRELESS_RADIO_CONTROLS 0x000C
#define CONSUMER_CONTROL_WIRELESS_RADIO_BUTTONS 0x00C6
#define CONSUMER_CONTROL_WIRELESS_RADIO_LED 0x00C7
#define CONSUMER_CONTROL_WIRELESS_RADIO_SLIDER_SWITCH 0x00C8
// Media Control
#define CONSUMER_CONTROL_PLAY_PAUSE 0x00CD
#define CONSUMER_CONTROL_SCAN_NEXT 0x00B5
#define CONSUMER_CONTROL_SCAN_PREVIOUS 0x00B6
#define CONSUMER_CONTROL_STOP 0x00B7
#define CONSUMER_CONTROL_VOLUME 0x00E0
#define CONSUMER_CONTROL_MUTE 0x00E2
#define CONSUMER_CONTROL_BASS 0x00E3
#define CONSUMER_CONTROL_TREBLE 0x00E4
#define CONSUMER_CONTROL_BASS_BOOST 0x00E5
#define CONSUMER_CONTROL_VOLUME_INCREMENT 0x00E9
#define CONSUMER_CONTROL_VOLUME_DECREMENT 0x00EA
#define CONSUMER_CONTROL_BASS_INCREMENT 0x0152
#define CONSUMER_CONTROL_BASS_DECREMENT 0x0153
#define CONSUMER_CONTROL_TREBLE_INCREMENT 0x0154
#define CONSUMER_CONTROL_TREBLE_DECREMENT 0x0155
// Application Launcher
#define CONSUMER_CONTROL_CONFIGURATION 0x0183
#define CONSUMER_CONTROL_EMAIL_READER 0x018A
#define CONSUMER_CONTROL_CALCULATOR 0x0192
#define CONSUMER_CONTROL_LOCAL_BROWSER 0x0194
// Browser/Explorer Specific
#define CONSUMER_CONTROL_SEARCH 0x0221
#define CONSUMER_CONTROL_HOME 0x0223
#define CONSUMER_CONTROL_BACK 0x0224
#define CONSUMER_CONTROL_FORWARD 0x0225
#define CONSUMER_CONTROL_BR_STOP 0x0226
#define CONSUMER_CONTROL_REFRESH 0x0227
#define CONSUMER_CONTROL_BOOKMARKS 0x022A
*/
//-----------------------------------------------------------//
CtrlEnc encoder(3, 4, onTurnleft, onTurnRight);
void setup() {
pinMode(2, INPUT_PULLUP);
ConsumerControl.begin();
USB.begin();
}
void loop() {
encoder.process();
// Serial.println(digitalRead(2));
if (digitalRead(2) == LOW) {
// Serial.println("if statement");
ConsumerControl.press(CONSUMER_CONTROL_PLAY_PAUSE);
ConsumerControl.release();
while (digitalRead(2) == LOW) {
// Serial.println("in while loop");
delay(300);
}
}
}
#endif /* ARDUINO_USB_MODE */
At first the knob is in vertical mode. In vertical mode spinning the knob moves the page up and down. Clicking the knob changes it to horizontal mode. In horizontal mode spinning the knob moves it left and right. Clicking changes it back to vertical mode.
#if ARDUINO_USB_MODE
#warning This sketch should be used when USB is in OTG mode
void setup() {}
void loop() {}
#else
#include "USB.h"
#include "USBHIDMouse.h"
#include <CtrlEnc.h>
USBHIDMouse Mouse;
bool movestate = 0;
//0 equals up-down 1 equals left-right
// Define an onTurnleft handler.
void onTurnleft() {
if(movestate == 0){
Mouse.move(0, 0, 1, 0);
}
else{
Mouse.move(0, 0, 0, -1);
}
}
// Define an onTurnRight handler.
void onTurnRight() {
if(movestate == 0){
Mouse.move(0, 0, -1, 0);
}
else{
Mouse.move(0, 0, 0, 1);
}
}
CtrlEnc encoder(3, 4, onTurnleft, onTurnRight);
void setup() {
// put your setup code here, to run once:
Mouse.begin();
USB.begin();
pinMode(2, INPUT_PULLUP);
}
void loop() {
// put your main code here, to run repeatedly:
encoder.process();
if (digitalRead(2) == LOW) {
// Serial.println("if statement");
if(movestate == 1){
movestate = 0;
}
else{
movestate = 1;
}
while (digitalRead(2) == LOW) {
// Serial.println("in while loop");
delay(300);
}
}
}
#endif /* ARDUINO_USB_MODE */
Enjoy your media knob and customize it to you liking!
Model based off of Container - Screw Cap, 4 Sizes, All Purpose - Tin, Box, Can by guppyk
inspired by https://www.printables.com/model/887330-usb-media-dial by https://www.printables.com/@Adafruit
The author remixed this model.
i have shortened the container. edited the inside. punched holes through the parts. turned it into a media dial. used it as an electronics case.