digitalelements
Active member
Hi,
I'm trying to create a momentary button that will alternate/toggle between two fixed MIDI messages in code.
I'm using the Bounce Library and would like to use either Falling or Rising edge to trigger this alternating behavior.
The code i've got is just sending a continuous stream of alternating note numbers. My programming knowledge is
pretty limited but trying to learn along the way. Any suggestion or guidance is greatly appreciated.
I'm trying to create a momentary button that will alternate/toggle between two fixed MIDI messages in code.
I'm using the Bounce Library and would like to use either Falling or Rising edge to trigger this alternating behavior.
The code i've got is just sending a continuous stream of alternating note numbers. My programming knowledge is
pretty limited but trying to learn along the way. Any suggestion or guidance is greatly appreciated.
Code:
// Button Toggle In Code
#include <Bounce.h>
const int channel = 1;
int StateOne = HIGH;
int StateTwo = HIGH;
int toggleState = HIGH;
Bounce button0 = Bounce(0, 10);
void setup() {
pinMode(0, INPUT_PULLUP);
}
void loop() {
button0.update();
if(button0.fallingEdge() != StateTwo && StateOne == 1 && toggleState == 0) {
usbMIDI.sendNoteOn(60, 99, channel);
toggleState = 1;
}
else if(button0.fallingEdge() != StateTwo && StateOne == 1 && toggleState == 1); {
usbMIDI.sendNoteOn(61, 99, channel);
toggleState = 0;
}
while (usbMIDI.read()) {
}
}