Arnov Sharma
Published © LGPL

HID Volume Knob with Pro Micro

Just another Pro micro Volume Knob Setup with POTENTIOMETER

BeginnerFull instructions provided6 minutes16,046

Things used in this project

Story

Read more

Schematics

sch

Code

HID Volume Knob

C/C++
#include <HID-Project.h>                    //include HID_Project library
#include <HID-Settings.h>

#define REVERSED false                      //if your controller is reversed change it to true

int val = 0;
int previousval = 0;
int val2 = 0;

void setup() {
  Consumer.begin();                         //initialize computer connection
  delay(1000);                              //wait for computer to connect
  for(int a = 0; a < 52; a++) {
    Consumer.write(MEDIA_VOLUME_DOWN);      //set the volume to 0
    delay(2);
  }
}

void loop() {
  val = analogRead(A0);                      //read potentiometer value
  val = map(val, 0, 1023, 0, 101);          //map it to 102 steps
  if(REVERSED) {
    val = 101 - val;
  }
  if(abs(val - previousval) > 1) {          //check if potentiometer value has changed
    previousval = val;
    val /= 2;                               //divide it by 2 to get 51 steps
    while(val2 < val) {
      Consumer.write(MEDIA_VOLUME_UP);      //turn volume up to appropiate level
      val2++;
      delay(2);
    }
    while(val2 > val) {
      Consumer.write(MEDIA_VOLUME_DOWN);    //turn volume down to appropiate level
      val2--;
      delay(2);
    }
  }
  delay(301);                               //wait at least 300ms between changing volume levels
}                                           //if it will change faster Windows can sometimes 
                                            //increase or decrease volume by 10 steps at once

Credits

Arnov Sharma

Arnov Sharma

310 projects • 307 followers
Just your average MAKER

Comments