Etienne Desportes
Created April 5, 2015 © Beerware

Ableton Live MIDI Controller

Plug & Play MIDI Controller on Arduino MEGA

IntermediateFull instructions provided30,258
Ableton Live MIDI Controller

Things used in this project

Hardware components

Black Knob - 15x19mm - 0.25" shaft
×4
Rotary Potentiometer - 10k Ohm, Linear
×4
Button Pad 2x2 - Breakout PCB
×2
Button Pad 2x2 - LED Compatible
×2
Slide Potentiometer Knob
×2
Slide Pot - X-Large - 10k Linear Taper
×2
Arduino Mega 2560
Arduino Mega 2560
×1
5mm Leds White
×8
Pull-down resistor 10k
×8
Led resistors ≈ 220 Ohm
×8

Story

Read more

Schematics

midi_controller.jpg

Code

Untitled file

C/C++
#include <MIDI.h>  // INlcude MIDI library

const int buttonPin = 2;  // the number of the Button pin
const int buttonPin2 = 3;
const int buttonPin3 = 4; 
const int buttonPin4 = 5;
const int buttonPin5 = 6; 
const int buttonPin6 = 7;
const int buttonPin7 = 8; 
const int buttonPin8 = 9;
// the number of the pushbutton pin
const int ledPin =  11;      // the number of the LED pin
const int ledPin2 =  12;
const int ledPin3 =  13;     
const int ledPin4 =  14;
const int ledPin5 =  15;    
const int ledPin6 =  16;
const int ledPin7 =  17;     
const int ledPin8 =  18;

// variables will change:
boolean currentState = LOW;//stroage for current button state
boolean lastState = LOW;//storage for last button state
boolean currentState2 = LOW;
boolean lastState2 = LOW;
boolean currentState3 = LOW;
boolean lastState3 = LOW;
boolean currentState4 = LOW;
boolean lastState4 = LOW;
boolean currentState5 = LOW;
boolean lastState5 = LOW;
boolean currentState6 = LOW;
boolean lastState6 = LOW;
boolean currentState7 = LOW;
boolean lastState7 = LOW;
boolean currentState8 = LOW;
boolean lastState8 = LOW;

void setup() {
  
  Serial.begin(31250);  // default midi speed rate
  
  // initialize the LED pin as an output:
  pinMode(ledPin, OUTPUT);      
  // initialize the pushbutton pin as an input:
  pinMode(buttonPin, INPUT); 
  
  pinMode(ledPin2, OUTPUT);      
  pinMode(buttonPin2, INPUT);
  
   pinMode(ledPin3, OUTPUT);      
  pinMode(buttonPin3, INPUT); 
  
  pinMode(ledPin4, OUTPUT);      
  pinMode(buttonPin4, INPUT);  
  
   pinMode(ledPin5, OUTPUT);      
  pinMode(buttonPin5, INPUT); 
  
  pinMode(ledPin6, OUTPUT);      
  pinMode(buttonPin6, INPUT); 
  
   pinMode(ledPin7, OUTPUT);      
  pinMode(buttonPin7, INPUT); 
  
  pinMode(ledPin8, OUTPUT);      :
  pinMode(buttonPin8, INPUT);  
  
 MIDI.begin(); 
}
  int iAn0Val, iAn1Val, iAn2Val, iAn3Val, iAn4Val, iAn5Val;

void loop(){
  
  // read the state of the pushbutton value:

  currentState = digitalRead(buttonPin);
  // check if the pushbutton is pressed.
  
  // if it is, the buttonState is HIGH:
  if (currentState == LOW && lastState == HIGH) { 
    
    digitalWrite(ledPin,HIGH); 
      
      MIDI.sendNoteOff(42,0,1);
    // turn LED off   
     
  } 
  
  else if (currentState == HIGH && lastState == LOW) { 
    digitalWrite(ledPin, LOW); 
    MIDI.sendNoteOn(42,127,1);
    // turn LED on
    delay(20);
    MIDI.sendNoteOff(42,0,1);
    // turn LED off 
  }
  
  lastState = currentState;            
  
    currentState2 = digitalRead(buttonPin2);

  if (currentState2 == LOW && lastState2 == HIGH) {
    digitalWrite(ledPin2,HIGH);  
     MIDI.sendNoteOff(39,0,1);
  } 
  else if (currentState2 == HIGH && lastState2 == LOW) {
   digitalWrite(ledPin2, LOW); 
   MIDI.sendNoteOn(39,127,1);
   delay(20);
      MIDI.sendNoteOff(39,0,1);
     }  
     lastState2 = currentState2;      
     
         currentState3 = digitalRead(buttonPin3);

  if (currentState3 == LOW && lastState3 == HIGH) {
    digitalWrite(ledPin3,HIGH);  
      MIDI.sendNoteOff(40,0,1);
  } 
  else if (currentState3 == HIGH && lastState3 == LOW) {
    
    digitalWrite(ledPin3, LOW); 
    MIDI.sendNoteOn(40,127,1);
    delay(20);
      MIDI.sendNoteOff(40,0,1);
     }  
     lastState3 = currentState3;
     
         currentState4 = digitalRead(buttonPin4);

  if (currentState4 == LOW && lastState4 == HIGH) {
    
    digitalWrite(ledPin4,HIGH);  
      
      MIDI.sendNoteOff(41,0,1);
    
  } 
  else if (currentState4 == HIGH && lastState4 == LOW) {
    
     digitalWrite(ledPin4, LOW); 
    MIDI.sendNoteOn(41,127,1);
     
   delay(20);
      MIDI.sendNoteOff(41,0,1);
     }  
     lastState4 = currentState4;
     
         currentState5 = digitalRead(buttonPin5);

  if (currentState5 == LOW && lastState5 == HIGH) {
    
    digitalWrite(ledPin5,HIGH);  
      
      MIDI.sendNoteOff(38,0,1);
    
  } 
  else if (currentState5 == HIGH && lastState5 == LOW) {
    
     digitalWrite(ledPin5, LOW); 
    MIDI.sendNoteOn(38,127,1);
     
   delay(20);
      MIDI.sendNoteOff(38,0,1);
     }  
     lastState5 = currentState5;
     
         currentState6 = digitalRead(buttonPin6);

  if (currentState6 == LOW && lastState6 == HIGH) {
    
    digitalWrite(ledPin6,HIGH);  
      
      MIDI.sendNoteOff(43,0,1);
    
  } 
  else if (currentState6 == HIGH && lastState6 == LOW) {
    
     digitalWrite(ledPin6, LOW); 
    MIDI.sendNoteOn(43,127,1);

   delay(20);
      MIDI.sendNoteOff(43,0,1);
     }  
     lastState6 = currentState6;
     
         currentState7 = digitalRead(buttonPin7);

  if (currentState7 == LOW && lastState7 == HIGH) {
    
    digitalWrite(ledPin7,HIGH);  
      
      MIDI.sendNoteOff(37,0,1);
    
  } 
  else if (currentState7 == HIGH && lastState7 == LOW) {
    
     digitalWrite(ledPin7, LOW); 
    MIDI.sendNoteOn(37,127,1);

   delay(20);
      MIDI.sendNoteOff(37,0,1);
     }  
     lastState7 = currentState7;
     
         currentState8 = digitalRead(buttonPin8);

  if (currentState8 == LOW && lastState8 == HIGH) {
    
    digitalWrite(ledPin8,HIGH);  
      
      MIDI.sendNoteOff(44,0,1);
    
  } 
  else if (currentState8 == HIGH && lastState8 == LOW) {
    
     digitalWrite(ledPin8, LOW); 
    MIDI.sendNoteOn(44,127,1);

   delay(20);
      MIDI.sendNoteOff(44,0,1);
     }  
     lastState8 = currentState8;
     
      int iAn0ValPrev = iAn0Val; // previous value
   iAn0Val = analogRead(A0)/8; // Divide by 8 to get range of 0-127 for midi
   analogPinMidiTX(1,iAn0Val,iAn0ValPrev); //TX value 
   
   int iAn1ValPrev = iAn1Val; 
   iAn1Val = analogRead(A1)/8;
   analogPinMidiTX(2,iAn1Val,iAn1ValPrev); 
   
   int iAn2ValPrev = iAn2Val; 
   iAn2Val = analogRead(A2)/8;
   analogPinMidiTX(3,iAn2Val,iAn2ValPrev);
   
   int iAn3ValPrev = iAn3Val; 
   iAn3Val = analogRead(A3)/8;
   analogPinMidiTX(4,iAn3Val,iAn3ValPrev); 
   
   int iAn4ValPrev = iAn4Val; 
   iAn4Val = analogRead(A4)/8;
   analogPinMidiTX(5,iAn4Val,iAn4ValPrev); 
   
   int iAn5ValPrev = iAn5Val; 
   iAn5Val = analogRead(A5)/8;
   analogPinMidiTX(6,iAn5Val,iAn5ValPrev); 
  
}

void analogPinMidiTX(int iChan, int iVal, int iValPrev)
{  
  // TX Value only if it has changed
  if(iValPrev != iVal)
  {
    MidiTX(176,iChan,iVal); // 176 = CC command, 1 = Which Control, val = value read from Potentionmeter
  }
}

void MidiTX(unsigned char MESSAGE, unsigned char CONTROL, unsigned char VALUE) //Valeur en Midi Command
{
   Serial.write(MESSAGE);
   Serial.write(CONTROL);
   Serial.write(VALUE);
}

Credits

Etienne Desportes

Etienne Desportes

2 projects • 18 followers

Comments