Hi, I've been building a MIDI controller with a Mega 2560. I have all of my analogue controls working nicely but now am having trouble getting my digital push buttons to behave correctly. For some reason it sends repeated note-off messages to ableton constantly until the button is pressed and then stops sending at all until the button is released when it starts sending note-off again. I have tried quite a few ways to stop this happeneing but none have seemed to work.
Here is my code: -
#include <MIDI.h>
#include <midi_Defs.h>
#include <midi_Message.h>
#include <midi_Namespace.h>
#include <midi_Settings.h>
MIDI_CREATE_DEFAULT_INSTANCE();
const int buttonPin = 3; // the pin that the pushbutton is attached to
int buttonState = 0; // current state of the button
int lastButtonState = 0; // previous state of the button
void setup() {
// initialize the button pin as an input:
pinMode(buttonPin, INPUT);
// begin MIDI communication:
MIDI.begin(4);
}
void loop() {
// read the pushbutton input pin:
buttonState = digitalRead(buttonPin);
// compare the buttonState to its previous state:
if (buttonState != lastButtonState) {
if (buttonState == HIGH) {
MIDI.sendNoteOn(67, 127, 1);
lastButtonState = buttonState;
}
else if (buttonState != lastButtonState) {
if (buttonState == LOW);
MIDI.sendNoteOff(67, 0, 1);
lastButtonState = buttonState;
}
}
}
As you can see I have used if statements to specify when messages should be sent but I'm obviously missing something.
Thanks in advance for any help