Created
October 14, 2017 07:52
-
-
Save amcjen/7555ab9cb62c550f3d1ef42afa121d70 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <Bounce.h> // Bounce library makes button change detection easy | |
const int channel = 1; | |
Bounce button1 = Bounce(1, 5); // 5 = 5 ms debounce time | |
Bounce button2 = Bounce(2, 5); // which is appropriate for good | |
Bounce button3 = Bounce(3, 5); // quality mechanical pushbuttons | |
void setup() { | |
pinMode(1, INPUT_PULLUP); | |
pinMode(2, INPUT_PULLUP); | |
pinMode(3, INPUT_PULLUP); | |
} | |
void loop() { | |
button1.update(); | |
button2.update(); | |
button3.update(); | |
// Note On messages when each button is pressed | |
if (button1.fallingEdge()) { | |
usbMIDI.sendNoteOn(60, 99, channel); // 60 = C4 | |
} | |
if (button2.fallingEdge()) { | |
usbMIDI.sendNoteOn(61, 99, channel); // 61 = C#4 | |
} | |
if (button3.fallingEdge()) { | |
usbMIDI.sendNoteOn(62, 99, channel); // 62 = D4 | |
} | |
// Note Off messages when each button is released | |
if (button1.risingEdge()) { | |
usbMIDI.sendNoteOff(60, 0, channel); // 60 = C4 | |
} | |
if (button2.risingEdge()) { | |
usbMIDI.sendNoteOff(61, 0, channel); // 61 = C#4 | |
} | |
if (button3.risingEdge()) { | |
usbMIDI.sendNoteOff(62, 0, channel); // 62 = D4 | |
} | |
// MIDI Controllers should discard incoming MIDI messages. | |
while (usbMIDI.read()) { | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment