Dann müsste es folgendermaßen aussehen:
/* Variablen */
byte volume, lastVolume, balance, lastBalance;
byte channel = 1; // Hier Kanal festlegen (1 bis 16)
int threshold = 2;
/* Pinbelegung */
const int volumePot[6] = { A0 , A1, A2, A3, A4, A5}; // Poti für die Lautstärke
const int balancePot = A6; // Poti für die Balance
void setup() {
Serial.begin(38400);
}
void loop(){
/* Lies und sende Lautstärke */
volume = knobFunction(volumePot);
if(volume != lastVolume) {
lastVolume = volume;
//Serial.print("volume: ");
//Serial.println(volume);
Serial.write(175 + channel); // Sende 'control change' auf Kanal 'channel'
Serial.write(7); // ändere Lautstärke auf...
Serial.write(volume); // den Wert der Variablen 'volume'
}
/* Lies und sende Balance */
balance = knobFunction(balancePot);
if(balance != lastBalance) {
lastBalance = balance;
//Serial.print("balance: ");
//Serial.println(balance);
Serial.write(175 + channel); // Sende 'control change' auf Kanal 'channel'
Serial.write(8); // ändere Balance auf...
Serial.write(balance); // den Wert der Variablen 'balance'
}
}
/* Funktionen */
int knobFunction(const int pin)
{
static int prevRead[6] = {0, 0, 0, 0, 0, 0};
int output = analogRead(pin)/8;
if (abs(output - prevRead[0]) >= threshold)
{prevRead[pin] = output;}
else
{output = prevRead[pin];}
return output;
}
Kanns jetzt gerade nicht ausprobieren, aber so sollte es doch gehen?