The prototype of my USB MIDI pedal is now complete. What you see below is prototyped on breadboard using the TEENSY development board, running software which I wrote in C/C++. It has 4 fully programmable pedal switches (either toggle or momentary), and an LED which flashes in time with the midi clock. This clock LED is to enable me to record loops without the need for headphones (I have not actually tried doing this). The next stage will be to solder it up on veroboard and build the housing. The enclosure has arrived, just need to do some drilling!
Once this is finished I’ll have more control over my live performance. My previous MIDI pedal was not programmable, and therefore I was somewhat restricted. With this I’ll be able to have more control over my live looping.
Here’s the source code for those interested.
#include #define MIDI_CHANNEL 1 #define MIDI_CLOCK 248 #define MIDI_START 250 #define MIDI_CONTINUE 251 #define MIDI_STOP 252 #define PULSES_PER_QUARTER 24 #define NUM_PEDAL_SWITCHES 4 #define MIDI_CLOCK_LED 4 #define BOUNCE_TIME 10 int midi_counter(0); struct PEDAL_SWITCH { int m_pedal_pin; int m_led_pin; int m_midi_cc; bool m_is_toggle; bool m_active; Bounce m_bounce; PEDAL_SWITCH( int pedal_pin, int led_pin, int midi_cc, bool is_toggle ) : m_pedal_pin( pedal_pin ), m_led_pin( led_pin ), m_midi_cc( midi_cc ), m_is_toggle( is_toggle ), m_active( false ), m_bounce( pedal_pin, BOUNCE_TIME ) { } }; PEDAL_SWITCH pedals[ NUM_PEDAL_SWITCHES ] = { PEDAL_SWITCH( 0, 5, 16, true ), PEDAL_SWITCH( 1, 6, 17, true ), PEDAL_SWITCH( 2, 7, 18, true ), PEDAL_SWITCH( 3, 8, 19, false ) }; void setup() { pinMode( MIDI_CLOCK_LED, OUTPUT ); for( int i = 0; i < NUM_PEDAL_SWITCHES; ++i ) { const PEDAL_SWITCH& pedal = pedals[i]; pinMode( pedal.m_pedal_pin, INPUT_PULLUP ); pinMode( pedal.m_led_pin, OUTPUT ); } usbMIDI.setHandleRealTimeSystem( midi_real_time_event ); midi_counter = 0; } void midi_real_time_event( byte data ) { switch( data ) { case MIDI_CLOCK: { ++midi_counter; if( midi_counter == PULSES_PER_QUARTER ) { midi_counter = 0; digitalWrite( MIDI_CLOCK_LED, HIGH ); } else if( midi_counter == PULSES_PER_QUARTER / 2 ) { digitalWrite( MIDI_CLOCK_LED, LOW ); } break; } case MIDI_START: case MIDI_CONTINUE: { midi_counter = 0; digitalWrite( MIDI_CLOCK_LED, HIGH ); break; } case MIDI_STOP: { digitalWrite( MIDI_CLOCK_LED, LOW ); break; } } } void loop() { usbMIDI.read(); for( int i = 0; i < NUM_PEDAL_SWITCHES; ++i ) { PEDAL_SWITCH& pedal = pedals[i]; pedal.m_bounce.update(); if( pedal.m_bounce.fallingEdge() ) { /*Serial.print("pedal down "); Serial.print(i); Serial.print("n");*/ if( pedal.m_is_toggle ) { pedal.m_active = !pedal.m_active; } else { pedal.m_active = true; } usbMIDI.sendControlChange( pedal.m_midi_cc, 127, MIDI_CHANNEL ); } else if( pedal.m_bounce.risingEdge() ) { /*Serial.print("pedal up "); Serial.print(i); Serial.print("n");*/ if( !pedal.m_is_toggle ) { pedal.m_active = false; usbMIDI.sendControlChange( pedal.m_midi_cc, 0, MIDI_CHANNEL ); } } if( pedal.m_active ) { digitalWrite( pedal.m_led_pin, HIGH ); } else { digitalWrite( pedal.m_led_pin, LOW ); } } }
Leave a Reply