// Hardware: Teensy 2.0, footswitch (momentary, not latching), some wires
// MIDI hardware: 220 ohm resistor, MIDI port, MIDI cable
// You don't need MIDI input hardware (anything connected to pin 7 and before that)
// because it is not implemented in this code
// Connections: connect one pin of every footswitches to pin numbers below, and other pins to ground,
// and create connections for MIDI hardware
#define pin1 0 // you can edit pin numbers here
#define pin2 1
#define pin3 2
#define pin4 3
#define pin5 4
#define pin6 5
#define pin7 6
#define pin8 9
// pins 7 and 8 are used by MIDI library for Teensy 2.0, don't use them for footswitches
#define bounceDuration 10 // increase this value if each footswitch press creates more than 1 patch/bank change
#include <Bounce.h> // include Bounce library (http://www.pjrc.com/teensy/td_libs_Bounce.html)
#include <MIDI.h> // include MIDI library (http://www.pjrc.com/teensy/td_libs_MIDI.html)
Bounce footSwitch1 = Bounce(pin1, bounceDuration); // create Bounce instances for each footswitch pin
Bounce footSwitch2 = Bounce(pin2, bounceDuration);
Bounce footSwitch3 = Bounce(pin3, bounceDuration);
Bounce footSwitch4 = Bounce(pin4, bounceDuration);
Bounce footSwitch5 = Bounce(pin5, bounceDuration);
Bounce footSwitch6 = Bounce(pin6, bounceDuration);
Bounce footSwitch7 = Bounce(pin7, bounceDuration);
Bounce footSwitch8 = Bounce(pin8, bounceDuration);
MIDI_CREATE_DEFAULT_INSTANCE(); // don't know what this is but comment it out if you are not using Teensyduino v1.37 or later
byte control; // declare some variables
byte value;
byte channel = 1; // MIDI channel is set to 1
void setup() {
pinMode(pin1, INPUT_PULLUP); // configure footswitch pins as inputs with pullup resistors
pinMode(pin2, INPUT_PULLUP);
pinMode(pin3, INPUT_PULLUP);
pinMode(pin4, INPUT_PULLUP);
pinMode(pin5, INPUT_PULLUP);
pinMode(pin6, INPUT_PULLUP);
pinMode(pin7, INPUT_PULLUP);
pinMode(pin8, INPUT_PULLUP);
MIDI.begin(MIDI_CHANNEL_OMNI); // initialize MIDI library and serial port
pinMode(11, OUTPUT); // configure LED pin as output for the LED to light up
digitalWrite(11, HIGH); // turn on LED
}
void loop() {
footSwitch1.update(); // update footswitch status (read pins)
footSwitch2.update();
footSwitch3.update();
footSwitch4.update();
footSwitch5.update();
footSwitch6.update();
footSwitch7.update();
footSwitch8.update();
if(footSwitch1.fallingEdge()) { // if footswitch is pressed
control = 64; // MIDI CC 64, change this as per your needs
value = 0; // MIDI CC value, change this as per your needs
MIDI.sendControlChange(control, value, channel); // send MIDI data
}
if(footSwitch2.fallingEdge()) { // process repeats but for another footswitch
control = 65;
value = 0;
MIDI.sendControlChange(control, value, channel);
}
if(footSwitch3.fallingEdge()) {
control = 66;
value = 0;
MIDI.sendControlChange(control, value, channel);
}
if(footSwitch4.fallingEdge()) {
control = 67;
value = 0;
MIDI.sendControlChange(control, value, channel);
}
if(footSwitch5.fallingEdge()) {
control = 68;
value = 0;
MIDI.sendControlChange(control, value, channel);
}
if(footSwitch6.fallingEdge()) {
control = 69;
value = 0;
MIDI.sendControlChange(control, value, channel);
}
if(footSwitch7.fallingEdge()) {
control = 70;
value = 0;
MIDI.sendControlChange(control, value, channel);
}
if(footSwitch8.fallingEdge()) {
control = 71;
value = 0;
MIDI.sendControlChange(control, value, channel);
}
}