// If you are new to this thread, it might save you time to skip to a point of some changes: [Reply #8 Send once [Uno + Sparkfun MIDI Breakout] - #9 by system - Project Guidance - Arduino Forum](http://Reply #8 Send once [Uno + Sparkfun MIDI Breakout] - #9 by system - Project Guidance - Arduino Forum)
I am developing an Arduino MIDI controller for theatrical playback software: a set of pushbuttons that send a MIDI command to an audio playback application. Stop, Go, Previous-cue-in-list, and Next-cue-in-list are the desired commands, which take the form of Note On messages in the playback application.
I have made extensive use of the MIDI, Debounce, and Pushbutton tutorials.
The problem at hand is that I only want the MIDI Note On sent a single time with each button push. As I have it programmed now, it is being read by MIDI Monitor for the entire duration that the button is pressed. Any thoughts?
#include <MIDI.h>
#include <Bounce.h>
// set the pins:
const int buttonStop = 2;
const int buttonGo = 3;
const int buttonLast = 4;
const int buttonNext = 5;
// variables for reading the pushbutton status:
int stopState = 0;
int goState = 0;
int lastState = 0;
int nextState = 0;
// debounce the pushbuttons at 5ms:
Bounce bounceStop = Bounce(buttonStop,5);
Bounce bounceGo = Bounce(buttonGo,5);
Bounce bounceLast = Bounce(buttonLast,5);
Bounce bounceNext = Bounce(buttonNext,5);
void setup() {
// start MIDI with input channel set to 4
MIDI.begin(4);
// initialize the pushbutton pin as an input:
pinMode(buttonStop, INPUT);
pinMode(buttonGo, INPUT);
pinMode(buttonLast, INPUT);
pinMode(buttonNext, INPUT);
}
void loop(){
// read the state of the pushbutton value:
stopState = digitalRead(buttonStop);
goState = digitalRead(buttonGo);
lastState = digitalRead(buttonLast);
nextState = digitalRead(buttonNext);
// update the debouncer:
bounceStop.update ( );
bounceGo.update ( );
bounceLast.update ( );
bounceNext.update ( );
// get the update value:
int valueStop = bounceStop.read();
int valueGo = bounceGo.read();
int valueLast = bounceLast.read();
int valueNext = bounceNext.read();
// if a button is pressed, send a MIDI message:
if (stopState == HIGH) {
MIDI.sendNoteOn(1,127,5);
}
if (goState == HIGH) {
MIDI.sendNoteOn(2,127,5);
}
if (lastState == HIGH) {
MIDI.sendNoteOn(3,127,5);
}
if (nextState == HIGH) {
MIDI.sendNoteOn(4,127,5);
}
}
I have tried removing all the debounce programming from my sketch. No change.
I have tried increasing my debounce interval to as much as 1 second. No change.
I have tried setting the button status back to 0 after the NoteOn, like this:
if (stopState == HIGH) {
MIDI.sendNoteOn(1,127,5);
stopState = 0;
}
I have tried the code with the 'if' statements changed to 'switch/case' e.g. in the place of:
if (stopState == HIGH) {
MIDI.sendNoteOn(1,127,5);
}
I tried:
switch (stopState) {
case HIGH:
MIDI.sendNoteOn(1,127,5);
break;
}
Thanks in advance for anything you might offer.