Need a Tip: Volume Controll with a normal Potentiometer

This is a special forum devoted to educators using Adafruit and Arduino products for teaching.

Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.
Locked
User avatar
karatorion
 
Posts: 1
Joined: Sun Apr 08, 2018 7:45 am

Need a Tip: Volume Controll with a normal Potentiometer

Post by karatorion »

Hi, I am working on a volume controll potentiometer for a Windows 10 computer.
I am not a Pro. I started with this projekt 12 days ago and I am nearly new to this languge.
Somehow this Code does not work out the way I want to and the the other projekts are not realy helping because they are normaly using a rotary potentiometer. I am using a normal potentiometer.
https://learn.adafruit.com/trinket-usb- ... b/overview: with a rotary Poti

Specefications:
  • Digispark ATtyni 85
  • TrinketHidCombo.h
  • Windows 10
The problems are
  • The initial MMKey Volume_Down does not work. The computervolume didnt changed.
  • If I rotate the poti, there is no change in my computervolume
  • If I try to use the serrial monitor for the poti, there is an error that the board is not available at COM1
I am trying to solve this problems for a week now and I got no real solutions. Maybe the solution is related to "#include <DigiKeyboard.h>". I am happy about every answer!

Code: Select all

#include "TrinketHidCombo.h"

#define PIN_POTI_VOLUME 3  //set the Poti_Input to pin 3, because there is an inbuild 1.5 kOhm resistance to prevent a shortcut when the Poti has 0 resistance.
int volume = 0; //Defines the initial Volume-Int to 0 

void setup()
{
        pinMode(PIN_POTI_VOLUME, INPUT);
        
        delay (90000); //Delay until Computer is started
        
        TrinketHidCombo.pressMultimediaKey(MMKEY_VOL_DOWN); //Press the Vol_Down Key 100 times, that Volume is 0
}
void loop()
{       
        int sensorValue = analogRead(3); //Read the position of the Potentiometer
        int realvolume = map(sensorValue, -1, 1023, 0 ,100); //Maps die position between 0 and 100
        
        if (volume != realvolume) { 
              int difference = volume - realvolume;
              
              if (difference < 0) {
                    TrinketHidCombo.pressMultimediaKey(MMKEY_VOL_UP); // Send keypress
                    volume += 1; //Add 1 to the Int volume until its even with the realvolume
              }	
              else {
                    TrinketHidCombo.pressMultimediaKey(MMKEY_VOL_DOWN);
                    volume -= 1; //Subtrakt 1 from the Int volume until its even with the realvolume
              }
        }
        
        else {
        delay (100); //delay in case of volume and realvolume are even. 
        }
}

Locked
Please be positive and constructive with your questions and comments.

Return to “For Educators”