Background:
The controller uses the Arduino microcontroller with the HIDUINO firmware flash so it can communicate directly over the USB rather than through MIDI ports. I'm using the MIDILibrary set which allows actual MIDI I/O communications.
The Problem:
What's happening is that when I push a button the program should send one simple MIDI NoteOn out to the computer and when I release it should send one MIDI NoteOff message to the computer. What is actually happening is that for the duration I have the button pressed it loops and sends the NoteOn message repeatedly and when I release it, it sends the NoteOff message repeatedly. I can't seem to think of the logic statement I need in order to send only one message at a time.
Here is code I've been working with:
I have a feeling the answer is extremely simple but for some reason I can't think of it.#include <MIDI.h> //include the MidiLibrary
//Set constant pin number to note correlations
const int C3 = 2;
//Set button state to note correlations
int C3s = 0;
void setup(){
MIDI.begin(MIDI_CHANNEL_OMNI);
//To begin debug uncomment next line
//Serial.begin(9600);
//Set all pin modes to input
pinMode(C3, INPUT);
}
void loop(){
C3s = digitalRead(C3);
if(C3s == HIGH){
for(int x=0; x<1; x++){
MIDI.sendNoteOn(48, 100, 1);
//Serial.write("hueheuhue");
}
}
else{
for(int x=0; x<1; x++){
//Serial.write("nonono");
MIDI.sendNoteOff(48, 100, 1);
}
}
}