I guess I am not sure how to do that. Tomorrow I am going to simplify my code to have just one button until I get this working properly, and then add the other buttons back after I am successful. In the meantime, I have tried creating a variable that will hold the last value recorded by the digitalRead and then use it to compare the states required in the if statements, but I am not quite making the jump in logic necessary. You can see two of my attempts below, marked by comments. I tried a couple of other things but forget what they were exactly but they produced no MIDI message.
void loop(){
// read the state of the pushbutton value:
stopState = digitalRead(buttonStop);
goState = digitalRead(buttonGo);
lastState = digitalRead(buttonLast);
nextState = digitalRead(buttonNext);
stopwas = stopState;
gowas = goState;
lastwas = lastState;
nextwas = nextState;
// 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 (stopwas != stopState) { // here I just tried to succeed by comparing the difference in variables
MIDI.sendNoteOn(1,127,5); // this MIDI message never fires under these conditions.
Bounce bounceStop = Bounce(buttonStop,5);
}
if (gowas == LOW && goState == HIGH) { // another way of comparing the variables
MIDI.sendNoteOn(2,127,5); // again, this MIDI message never fires under these conditions.
Bounce bounceGo = Bounce(buttonGo,5);
}
if (lastwas == LOW && lastState == HIGH) {
MIDI.sendNoteOn(3,127,5);
Bounce bounceLast = Bounce(buttonLast,5);
}
if (nextwas == LOW && nextState == HIGH) {
MIDI.sendNoteOn(4,127,5);
Bounce bounceNext = Bounce(buttonNext,5);
}
}
Note: I have changed the title of the thread to 'Send Once' rather than 'Run Once' because, of course, I want the sketch to continue running, but only send the MIDI command once when a button is pushed.