Created
October 14, 2017 07:53
-
-
Save amcjen/0da4f505cb24b101e9112fc59ad061e0 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 | |
// quality mechanical pushbuttons | |
void setup() { | |
pinMode(1, INPUT_PULLUP); | |
pinMode(2, INPUT_PULLUP); | |
} | |
void loop() { | |
button1.update(); | |
button2.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 | |
} | |
// 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 | |
} | |
// 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