The MIDI Box

This is simple arduino based midi controller with four potentiometers, four tactile switches and a LED with three colours. It is powered by a USB connection and is sending data through a MIDI connector.

Every tactile switch respond with a certain colour on the LED. The tactile switches is based on a resistor ladder design.

Schematic:

MIDI Box Schematic

MIDI Box Schematic

Pictures:

dav

dav

Code:

const int potOnePin = A1;
const int potTwoPin = A2;
const int potThreePin = A3;
const int potFourPin = A4;

int potOneVal = 0;
int potTwoVal = 0;
int potThreeVal = 0;
int potFourVal = 0;

int lastPotOneVal = 0;
int lastPotTwoVal = 0;
int lastPotThreeVal = 0;
int lastPotFourVal = 0;

int button1 = 0;
int button2 = 0;
int button3 = 0;
int button4 = 0;

int hiHat = 42;
void setup() {
// put your setup code here, to run once:
Serial.begin(31250);

for(int pinNumber = 9; pinNumber<12; pinNumber++){
pinMode(pinNumber,OUTPUT);
}

}

void loop() {
// put your main code here, to run repeatedly:

int keyVal = analogRead(A0);

potOneVal = analogRead(potOnePin)/7;
if (potOneVal != lastPotOneVal){
MIDImessage(176,1,potOneVal);
}
lastPotOneVal = potOneVal;

potTwoVal = analogRead(potTwoPin)/7;
if (potTwoVal != lastPotTwoVal){
MIDImessage(176,2,potTwoVal);
}
lastPotTwoVal = potTwoVal;

potThreeVal = analogRead(potThreePin)/7;
if (potThreeVal != lastPotThreeVal){
MIDImessage(176,3,potThreeVal);
}
lastPotThreeVal = potThreeVal;

potFourVal = analogRead(potFourPin)/7;
if (potFourVal != lastPotFourVal){
MIDImessage(176,4,potFourVal);
}
lastPotFourVal = potFourVal;

if(keyVal >= 1019 && keyVal <= 1023){
if(button1 == 0){
MIDImessage(144,36,100);
digitalWrite(9,LOW);
digitalWrite(10,HIGH);
digitalWrite(11,LOW);
button1 = 1;
delay(10);
}
}

else{
if(button1 = 1){
MIDImessage(144,36,0);
digitalWrite(9,LOW);
digitalWrite(10,LOW);
digitalWrite(11,LOW);
}
button1 = 0;
}

if(keyVal >= 990 && keyVal <= 1010){
if(button2 == 0){
MIDImessage(144,38,100);
digitalWrite(9,HIGH);
digitalWrite(10,LOW);
digitalWrite(11,LOW);
button2 = 1;
delay(10);
}
}

else{
if(button2 = 1){
MIDImessage(144,38,0);
digitalWrite(9,LOW);
digitalWrite(10,LOW);
digitalWrite(11,LOW);
}
button2 = 0;
}

if(keyVal >= 505 && keyVal <= 515){
if(button3 == 0){
MIDImessage(144,hiHat,100);
digitalWrite(9,LOW);
digitalWrite(10,LOW);
digitalWrite(11,HIGH);
button3 = 1;
delay(10);
}
}

else{
if(button3 = 1){
MIDImessage(144,hiHat,0);
digitalWrite(9,LOW);
digitalWrite(10,LOW);
digitalWrite(11,LOW);
}
button3 = 0;
}

if(keyVal >= 3 && keyVal <= 15){
if(button4 == 0){
hiHat = 46;
digitalWrite(9,HIGH);
digitalWrite(10,HIGH);
digitalWrite(11,HIGH);
button4 = 1;
delay(10);
}
}

else{
if(button4 = 1){
digitalWrite(9,LOW);
digitalWrite(10,LOW);
digitalWrite(11,LOW);
hiHat = 42;
}
button4 = 0;
}

delay(10);
}

void MIDImessage(int command, int MIDInote, int MIDIvelocity) {
Serial.write(command);//send note on or note off command
Serial.write(MIDInote);//send pitch data
Serial.write(MIDIvelocity);//send velocity data
}