Quantcast
Viewing all articles
Browse latest Browse all 11

Comment on how to get more arduino analog inputs by Trent

Hi Andrew, I build a controller with 32 pots connected to 4 multiplexers. I was wondering if you know how to properly transform these signals into a MIDI message. At the moment I can see all the pot values on the serial monitor, so I know they are properly connected. When I try to connect my controller through a midi device and into a DAW such as ableton or renoise, it responds as if I am turning every single knob at once without having touched them.

If you could give me some advice that would be amazing. Thanks!

const int Apin = 2;
const int Bpin = 3;
const int Cpin = 4;
const int trigPin = 5;
const int echoPin = 6;
byte potVal;
byte lastVal[32]; // store the latest value here if it’s different
byte MIDIBuf[3];
unsigned long duration;
int controllerNumber = 0;
#define CONTROLLER_CHANGE_STATUS 0xB0

void sendMIDI(int ctlNum, int value);

void setup(void)
{
digitalWrite(trigPin, LOW);

pinMode(Apin, OUTPUT);
pinMode(Bpin, OUTPUT);
pinMode(Cpin, OUTPUT);
pinMode(echoPin, INPUT);
pinMode(trigPin, OUTPUT);

Serial.begin(9600); // MIDI
}

void loop()
{
controllerNumber = 0;

digitalWrite(trigPin, HIGH); // start trig pulse
delay(1);//for (int i = 0; i < 20; ++i);
digitalWrite(trigPin, LOW); // end trig pulse
duration = pulseIn(echoPin, HIGH); // read width of echo pulse

MIDIBuf[0] = CONTROLLER_CHANGE_STATUS;
MIDIBuf[1] = controllerNumber;
MIDIBuf[2] = duration;
Serial.write(MIDIBuf, 3);

for (int i = 0 ; i < 8; ++i)
{
digitalWrite(Apin, (i & 1));
digitalWrite(Bpin, (i & 2));
digitalWrite(Cpin, (i & 4));

for (int analogPin = 0; analogPin >3)&0x7F; // force 7-bit
controllerNumber++;
if (lastVal[controllerNumber] != potVal)
Serial.println(analogRead(0));
delay(100);
{ // only send if changed
lastVal[controllerNumber] = potVal;
MIDIBuf[0] = CONTROLLER_CHANGE_STATUS;
MIDIBuf[1] = controllerNumber;
MIDIBuf[2] = potVal;
Serial.write(MIDIBuf, 3);
}
}
}
}


Viewing all articles
Browse latest Browse all 11

Trending Articles