- Eventide Audio

Home Forums Products Stompboxes H9 Midi Controller – DIY Reply To: H9 Midi Controller – DIY

#141318
dmessick
Participant

Below is the code and wiring diagram I used to program a different MIDI CC message for each switch. All you have to do is upload this code to the Teensy LC microcontroller. I used this site as a reference for how to do that, it’s about as easy as updating software on your phone. Use the arduino software to install the code below on the chip via a USB cable. Then wire up the switches, MIDI jack, and power supply.

 

The way the code works is the chip is always checking for the buttons to be pressed. When a button is pressed, it sends a MIDI message to the H9. The H9 Control app is where you tell the H9 what you want each MIDI message to do. For example, the switches programmed below send the following MIDI messages: c0, c1, c2, and c3. On the H9 control app, I’ve told the H9 I want c0 to bank down, c1 to toggle the tuner, c2 for tap tempo, and c3 for the performance switch. You can also program switches to activate specific presets, similar to the strymon “favorite” switch. These messages are sent as PC instead of CC, a simple change to the code. Most of everything I learned for this was from this page.

 

Code:

#include <Bounce.h> // necessary for button press noise

 

#include <MIDI.h> //Midi library

 

 

//Serial port 1 for MIDI connector

#define HWSERIAL Serial1

 

// midi channel 1 for H9

const int channel = 1;

 

// cc values

int cc_off = 1;

int cc_on = 127;

 

// map buttons to cc and pc, define as integers

int cc0 = 0;

int cc1 = 1;

int cc2 = 2;

int cc3 = 3;

 

//pc isn’t used in this code but can sub for cc if desired.

int pc1 = 0;

int pc2 = 1;

int pc3 = 2;

 

 

Bounce button1 = Bounce(2, 10);

Bounce button2 = Bounce(5, 10);

Bounce button3 = Bounce(6, 10);

Bounce button4 = Bounce(8, 10);

 

 

 

void setup()

{

 

//buttons are connected to pins 2, 5, 6 and 8 on Teensy

pinMode(2, INPUT_PULLUP);

pinMode(5, INPUT_PULLUP);

pinMode(6, INPUT_PULLUP);

pinMode(8, INPUT_PULLUP);

 

//MIDI uses serial 31250

Serial.begin(31250);

MIDI.begin();

 

}

 

 

void loop()

{

//check for buttons to be pressed

button1.update();

button2.update();

button3.update();

button4.update();

 

// if button 1 is pressed, send cc0

if (button1.fallingEdge())

{

MIDI.sendControlChange(cc0, cc_on, channel);

}

 

 

//if button 2 is pressed, send cc1

if (button2.fallingEdge())

{

MIDI.sendControlChange(cc1, cc_on, channel);

}

 

 

//if button 3 is pressed, send cc2

if (button3.fallingEdge())

{

MIDI.sendControlChange(cc2, cc_on, channel);

}

 

//if button 4 is pressed, send cc3

if (button4.fallingEdge())

{

MIDI.sendControlChange(cc3, cc_on, channel);

}

 

}