Created
July 10, 2017 18:54
-
-
Save jrmedd/672d39fc22aef8d36468aced78f26c82 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 <Bounce2.h> | |
#include "MIDIUSB.h" | |
int numButtons = 8; | |
int lowButton = 2; | |
int buttonPin = 3; | |
Bounce bouncer[8] = { | |
Bounce(2, 5), | |
Bounce(3, 5), | |
Bounce(4, 5), | |
Bounce(5, 5), | |
Bounce(6, 5), | |
Bounce(7, 5), | |
Bounce(8, 5), | |
Bounce(9, 5), | |
Bounce(10, 5) | |
}; | |
void setup() { | |
for (int i = 0; i < numButtons; i ++) { | |
pinMode(i+lowButton, INPUT); | |
digitalWrite(i+lowButton, HIGH); | |
} | |
} | |
void loop() { | |
for(int i = 0; i < numButtons; i ++) { | |
bouncer[i].update(); | |
if (bouncer[i].fell()) { | |
noteOn(0, 60+i, 127); | |
MidiUSB.flush(); | |
} | |
else if (bouncer[i].rose()) { | |
noteOff(0, 60+i, 127); | |
MidiUSB.flush(); | |
} | |
} | |
} | |
void noteOn(byte channel, byte pitch, byte velocity) { | |
midiEventPacket_t noteOn = {0x09, 0x90 | channel, pitch, velocity}; | |
MidiUSB.sendMIDI(noteOn); | |
} | |
void noteOff(byte channel, byte pitch, byte velocity) { | |
midiEventPacket_t noteOff = {0x08, 0x80 | channel, pitch, velocity}; | |
MidiUSB.sendMIDI(noteOff); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment