#include "MIDIUSB.h"
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);
}
int flag = 0;
void setup() {
Serial.begin(115200);
pinMode(5, INPUT);
}
void controlChange(byte channel, byte control, byte value) {
midiEventPacket_t event = {0x0B, 0xB0 | channel, control, value};
MidiUSB.sendMIDI(event);
}
void loop() {
int test = digitalRead(5);
while (test == 1 && flag == 0) {
noteOn(0, 48, 64); // Channel 0, middle C, normal velocity
MidiUSB.flush();
delay(5);
flag = 1;
}
while (test == 0 && flag == 1){
noteOff(0, 48, 64); // Channel 0, middle C, normal velocity
MidiUSB.flush();
delay(5);
flag = 0;
}
if (test == 0){flag = 0;}
// controlChange(0, 10, 65); // Set the value of controller 10 on channel 0 to 65
}