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 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
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.
}
}