Go Down

Topic: Midi Sustain pedal (Read 2224 times) previous topic - next topic

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?

robtillaart


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.



Rob Tillaart

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

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: [Select]
#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.

el_supremo

#3
Feb 04, 2013, 06:27 pm Last Edit: Feb 05, 2013, 12:08 am by el_supremo Reason: 1
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: [Select]
#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);
 }
}

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

Go Up
 


Please enter a valid email to subscribe

Confirm your email address

We need to confirm your email address.
To complete the subscription, please click the link in the email we just sent you.

Thank you for subscribing!

Arduino
via Egeo 16
Torino, 10131
Italy