Hello,
Recently I had a idea to make my own cheap simple volume mixer for my computer, mainly for when im inside fullscreen applications and cannot tab out to turn something down, for example music. So I ordered the Arduno uno and a kit to go along with it including a potentiometer. I have done Java coding before so i thought i would start with that, I have now got the potentiometer transmitting through com port and java receiving it and changing the volume and it all seems to be working, However for some reason the first 50% of the volume moves slowly and from 50% + it moves really fast, see the gif below. And half way on the potentiometer is not even 25% of the audio so is there away to calibrate the potentiometer or set-up the mid point? or is it possible that its something to do with my code?
Code I use for Java:
String inputLine=input.readLine();
int volume = (Integer.parseInt(inputLine));
//if(volume > 1023 || volume < 150) return;
float volnew = (float) ((volume/2.55)/100);
double roundOff = Math.round(volnew * 100.0) / 100.0;
System.out.println(inputLine+" "+roundOff);
Audio.setMasterOutputVolume((float)roundOff);
The smoothing code i use from arduino:
// These constants won't change:
const int sensorPin = A0; // pin that the sensor is attached to
const int ledPin = 3; // pin that the LED is attached to
// variables:
int sensorValue = 0; // the sensor value
int sensorMin = 150; // minimum sensor value
int sensorMax = 1023; // maximum sensor value
void setup() {
Serial.begin(9600);
}
void loop() {
// read the sensor:
sensorValue = analogRead(sensorPin);
// apply the calibration to the sensor reading
sensorValue = map(sensorValue, sensorMin, sensorMax, 0, 255);
// in case the sensor value is outside the range seen during calibration
sensorValue = constrain(sensorValue, 0, 255);
// fade the LED using the calibrated value:
analogWrite(ledPin, sensorValue);
Serial.println(sensorValue);
delay(60); // delay in between reads for stability
}
Thanks in advance,
Joe