Pages: [1]   Go Down
Author Topic: Midi Sustain pedal  (Read 1712 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 3
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hi, I'm a complete novice to working with Arduino, but I'd like to be able to create something extremely useful for me. I want to be able to control the sustain of a MicroKorg XL with a standard sustain pedal. The MicroKorg doesn't have a sustain pedal input, but I was wondering if I could convert the signal from the 1/4" output of a sustain pedal into MIDI data using an Arduino. How would I go about doing this?
Logged

Global Moderator
Netherlands
Offline Offline
Shannon Member
*****
Karma: 212
Posts: 13531
In theory there is no difference between theory and practice, however in practice there are many...
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset


I recently bought a Teensy2.0 which is Arduino alike. It has a nice midi library - http://www.pjrc.com/teensy/td_midi.html -
Did only other USB tests but it looks promising.



Logged

Rob Tillaart

Nederlandse sectie - http://arduino.cc/forum/index.php/board,77.0.html -
(Please do not PM for private consultancy)

Offline Offline
Newbie
*
Karma: 0
Posts: 3
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

So I'm having a lot of trouble with the programming side of things, and I'm not sure I have my output wired correctly, but it's wired according to http://arduino.cc/en/Tutorial/Midi. I attached a picture of what my whole bread board looks like. and my code so far looks like this:
Code:
#include <MIDI.h>
/*
  Sustain pedal
 Reads a digital input on pin 4, chooses between sustain and sostenuto
 Reads a digital input on pin 2, outputs to midi information
 */

// declare inputs.
int toggleSwitch = 4;
int togglePedal = 2;
int midiOut = 1;

// the setup routine runs once when you press reset:
void setup() {
  // initialize midi
  MIDI.begin(1);
  // make the switch pins inputs:
  pinMode(toggleSwitch, INPUT);
  pinMode(togglePedal, INPUT);
  pinMode(midiOut, OUTPUT);
}

// the loop routine runs over and over again forever:
void loop() {
  // read the input pins:
  int switchState = digitalRead(toggleSwitch);
  int pedalState = digitalRead(togglePedal);
 
  // output out the state of the pedal:
  if (pedalState == 0 && switchState == 0) //sustain off
  {MIDI.sendControlChange(64,0,1);}
 
  if (pedalState == 1 && switchState == 0) //sustain on
  MIDI.sendControlChange(64,127,1);}
 
  if (pedalState == 0 && switchState == 1) //sostenuto off
  {MIDI.sendControlChange(66,0,1);}
 
  if (pedalState == 1 && switchState == 1) //sostenuto on
  {MIDI.sendControlChange(66,127,1);}
 
  delay(1);        // delay in between reads for stability
}

I had it working when I outputted it to the serial monitor to debug, but I have no clue how to use the midi.


* Midi sustain_bb.jpg (522.49 KB, 1743x1062 - viewed 44 times.)
Logged

Offline Offline
Edison Member
*
Karma: 43
Posts: 1556
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Your code will keep sending a MIDI message as long as the pedal is held down but for a sustain pedal you only need to send a message when the pedal goes down or up. A convenient way to handle this is to read the pedal using an interrupt which is set to trigger on a pedal CHANGE.
Try my code below.
[edit]I've now tested it and the code works on my SY77 if I send Note On/Off or a Program Change message but Control Change doesn't do anything which is presumably a problem with the SY77 not the code.

Pete

Code:
#include <MIDI.h>

/*
 Sustain pedal
 Uses an interrupt to monitor the sustain pedal on pin 2
 and outputs a MIDI Control Change message on pin 1
 Reads a digital input on pin 4, chooses between sustain and sostenuto
*/
 
 
// declare pins.
int toggleSwitch = 4;
int midiOut = 1;
// The pedal MUST be on Arduino pin 2
int togglePedal = 2;

// All this does is set a flag on a pedal transition.
// The loop function looks for the flag.
volatile int transition = 0;
void pedal_transition(void)
{
  transition = 1;
}

void setup(void)
{
  // This will call pedal_transition if the pedal goes up or down
  attachInterrupt(0,pedal_transition,CHANGE);
  pinMode(toggleSwitch, INPUT);
  pinMode(togglePedal, INPUT);
  pinMode(midiOut, OUTPUT);
  MIDI.begin(1);
}

// the code will set cc_pedal to 64 (sustain) or 66 (sostenuto)
// depending on the status of the toggleSwitch
int cc_pedal = 0;

void loop(void)
{
  // There's nothing to do if the transition flag is not set
  if(!transition)return;
  transition = 0;
  if(digitalRead(toggleSwitch)) cc_pedal = 66;
  else cc_pedal = 64;
  // If togglePedal is now high, the pedal is now UP
  // otherwise it is now DOWN
  if(digitalRead(togglePedal)) {
    MIDI.sendControlChange(cc_pedal,0,1);
  } else {
    MIDI.sendControlChange(cc_pedal,127,1);
  }
}
« Last Edit: February 04, 2013, 06:08:04 pm by el_supremo » Logged

Where are the Nick Gammons of yesteryear?

Offline Offline
Newbie
*
Karma: 0
Posts: 3
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Yeah, it was not working for me. Perhaps I have to get the microkorg working on the other end.
Logged

Pages: [1]   Go Up
Jump to: