Merry Xmas And Happy New Year


Wishing everyone a merry christmas and a happy new year. Looking forwards to 2013 and t... 

Website fixes and Updates


There have been quite a few fixes and optimisations of the website this month More con... 

First Arduino MIDI controller made


Here is a picture of my first Arduino based MIDI controller / step sequencer made by me... 

Latest updates and News for 2012


After family sicknesses and the lurking spectre of Cancer much of my time has been take... 



by Alexander Burke

Published: 23-03-2012 09:19:33

First Arduino MIDI controller made

Here is a picture of my first Arduino based MIDI controller / step sequencer made by me to test the platform, my programming skills and my rather crap soldering.

Arduino MIDI step sequencer

Its not much to begin with, just two micro buttons that start/stop sequencer or speed up the tempo. There is a potentiometer that changes the MIDI program ie sound of instrument. Currently the whole thing is just outputting via a MIDI socket to a USB to MIDI cable bought of ebay for a couple of quid.

Is nice to programme something that I can manipulate in the real world rather than programming onscreen interfaces and is fairly satisfying I must say.

Take a look at its awesomeness(!)

Its programmed with interrupts so that when the sequence is playing it can still handle the button pushes. I've used the MEGA2560 so interrupts 0 and 1 are located on pins 2 and 3 on the board, obviously if you use a different board check which interrupts happen on which pins and adjust code accordingly.

The sequence inside the main loop isnt the best in the world and is only meant to be a test with delays to figure out the button events in relation to the chip loop() code. It could be done way more flexibly with an array etc amongst other things.

Code: Select all
  MIDI Controller/Sequence Player **test**
  First Attempt at midi controller with 2 buttons pot and interrupts 
  Button 1 - start/stop play
  Button 2 - tempo
  Pot    1 - Program Change 0-127
  Alex Burke - Mar 2012
// define PINS
#define CNT_PIN_A 2 // button 1
#define CNT_PIN_B 3 // button 2
#define CNT_POT_A A0 // potentiometer 1
#define LED_PIN 13  // for midi out status

// MIDI defines
#define CHN 0x00  // midi channel
#define PROG 0x00 // init program
#define VELOCITY 0x78 // velocity 120

// define others
#define DELAY 100 // note length
#define DEBOUNCE 10 // bounce on buttons
#define BOUNCE 3  // bounce on pot

int _P_READ_A = 0; // pot A read
int _P_PREV_A = 0; // previous pot read

volatile boolean PLAY = false; // state
volatile int curProg = PROG; // current programme
volatile int curDelay = DELAY; // delay state

// ------------ ACTUAL RUNNING DATA --------------
void setup() {
  pinMode(CNT_PIN_A, INPUT);
  pinMode(CNT_PIN_B, INPUT);
  pinMode(LED_PIN, OUTPUT); 
  attachInterrupt(0, Play, HIGH);
  attachInterrupt(1, chgDelay, HIGH);

void loop() {
  _P_READ_A = analogRead(CNT_POT_A);
  // debounce READ from pot
  if (!(_P_READ_A>(_P_PREV_A+BOUNCE))&&!(_P_READ_A<(_P_PREV_A-BOUNCE))){ _P_READ_A = _P_PREV_A; }
  if (_P_READ_A!=_P_PREV_A){
    // programme change 
    int temp = 127 - round(_P_READ_A/8); // buffer so dont send same value
    if (curProg!=temp){
      curProg = temp;
      progChange(CHN,curProg); // do command
  else if (PLAY){
     // the song simple ascending thing
    noteOn(CHN, 0x23, VELOCITY);
    noteOn(CHN, 0x23, 0x00);   
    noteOn(CHN, 0x25, VELOCITY);
    noteOn(CHN, 0x25, 0x00);   
    noteOn(CHN, 0x26, VELOCITY);
    noteOn(CHN, 0x26, 0x00);   
    noteOn(CHN, 0x29, VELOCITY);
    noteOn(CHN, 0x29, 0x00);   
  _P_PREV_A = _P_READ_A;

// -------------- MIDI FUNCTIONS ---------------

void noteOn(byte channel, byte note, byte velocity) {
  midiMsg( (0x90 | channel), note, velocity);
// note on 0x90
void noteOff(byte channel, byte note, byte velocity) { 
  midiMsg( (0x80 | channel), note, velocity);
// note off 0x80
void progChange(byte channel, byte prog) { 
  midiMsg( (0xC0 | channel), prog, 0);
// prog change 0xC0

void midiMsg(byte cmd, byte data1, byte data2) {

// --------------- Interrupts ---------------

// interrupt button 1 state
void Play() {
   delay(DEBOUNCE); //Wait a bit
   if(digitalRead(CNT_PIN_A) == HIGH){
     digitalWrite(LED_PIN, PLAY);  
// interrupt button 2 state
void chgDelay(){
   delay(DEBOUNCE); //Wait a bit
   if(digitalRead(CNT_PIN_B) == HIGH){
     if (curDelay<40){curDelay=DELAY;}

The code for the arduino can be downloaded from here: get code

Article(s) : <<54321