Hi there!
I am trying to build a USB MIDI controller with a Pro Micro and four touch sensors.
Here is whats wrong:
I have the touch sensors sending ON notes when I press them but my problem is that it is constantly sending OFF notes, which doesn't give a very good sound and means the four notes I am using on my softsynth don't work when I press them on my computer. you'll see why in my code:
#include "Midi_Functions.h"
const int but1 = 2;
const int but2 = 3;
const int but3 = 4;
const int but4 = 5;
void setup() {
pinMode(but1, INPUT_PULLUP);
pinMode(but2, INPUT_PULLUP);
pinMode(but3, INPUT_PULLUP);
pinMode(but4, INPUT_PULLUP);
}
void loop() {
MIDIbutton(but1, 36, 64);
MIDIbutton(but2, 37, 64);
MIDIbutton(but3, 38, 64);
MIDIbutton(but4, 39, 64);
}
And the MIDI_Functions.h file:
#include "MIDIUSB.h"
//MIDI Notes
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);
}
//Buttons
bool triggerState = false;
void MIDIbutton(int Pin, int Note, int Velocity){
if (!triggerState && digitalRead(Pin) == HIGH) {
triggerState = true;
noteOn(0, Note, Velocity);
MidiUSB.flush();
} else {
noteOff(0, Note, 0);
}
if (triggerState && digitalRead(Pin)) {
triggerState = false;
}
}
I am not sure how to send a MIDI OFF note only once after the touch sensor is released, and help would be appreciated.