Author Topic: Need a Tip: Volume Controll with a normal Potentiometer  (Read 1146 times)

karatorion

  • Newbie
  • *
  • Posts: 1
Need a Tip: Volume Controll with a normal Potentiometer
« on: April 08, 2018, 05:43:17 am »
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-volume-knob/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]
#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.
        }
}

Larsonut

  • Newbie
  • *
  • Posts: 2
Re: Need a Tip: Volume Controll with a normal Potentiometer
« Reply #1 on: April 18, 2018, 02:18:52 am »
I need the same advice. I really want to know. Thank you for your advice


casino

« Last Edit: June 20, 2018, 01:32:01 am by Larsonut »

dl4ou

  • Newbie
  • *
  • Posts: 15
Re: Need a Tip: Volume Controll with a normal Potentiometer
« Reply #2 on: April 19, 2018, 10:55:30 am »
You are aware, that you have to wait 90 s after program start?

htniemann

  • Newbie
  • *
  • Posts: 1
Re: Need a Tip: Volume Controll with a normal Potentiometer
« Reply #3 on: May 12, 2018, 03:40:35 am »
I am currently doing it this way (slightly edited because I need input P0 to press the space bar, so it might not compile immeditately :-)
Code: [Select]
#include "DigiKeyboard.h"

int analog;

int lastanalog;
int delta = 8;

void setup() {
  // don't need to set anything up to use DigiKeyboard

  pinMode(2, INPUT); //  Analogkanal 1

  lastanalog = analogRead(1); //Read P2
}


void loop() {
  DigiKeyboard.update();
 
  analog = analogRead(1); //Read P2
  if (analog > lastanalog + delta) {
    //DigiKeyboard.sendKeyStroke(38);// Ziffer 9
    DigiKeyboard.sendKeyStroke(129);// Vol-
   
    lastanalog += delta;
  }
  if (analog < lastanalog - delta) {
    //DigiKeyboard.sendKeyStroke(39);// Ziffer 0
    DigiKeyboard.sendKeyStroke(128);// Vol+
    lastanalog -= delta;
  }
}
This translates a change in the analog voltage on P2 which is analog(1)  into a series of key presses.
I have a 20k pot between pin2 and ground (with "0 ohms"! meaning "volume up" -- this is the pot I needed to interface with),
paralleled with a 6.8nF cacpacitor to smoothen things, and  8.2k pullup from pin2 to 5V.

A full turn of the pot sends 36 keystrokes with this delta value.

This works fine with my Linux PC, but unfortunately it is not recognised as a keyboard on my Windows XP laptop that I wanted to use it with.
Does anybody have an idea what to do?
« Last Edit: May 12, 2018, 03:47:20 am by htniemann »

MrCookie

  • Newbie
  • *
  • Posts: 21
Re: Need a Tip: Volume Controll with a normal Potentiometer
« Reply #4 on: June 05, 2018, 12:12:05 am »
From what I've read, 174 for volume down, and 175 for volume up; in windows. Your code is using 129 for volume down, and 128 for volume up. Might want to try that?