digitalelements
Active member
Hi There,
I hoping for some suggestions and guidance in coding. I have two momentary buttons that when pressed, send out their MIDI note on messages.
I'd like to change the MIDI note message of one button while another butting is being held down. I've tried for several hours to come up with this code
on my own through research and trial and error. Unfortunately I'm stuck. any info would be greatly appreciated. The code I've been tinkering with is below.
Thank you !
I hoping for some suggestions and guidance in coding. I have two momentary buttons that when pressed, send out their MIDI note on messages.
I'd like to change the MIDI note message of one button while another butting is being held down. I've tried for several hours to come up with this code
on my own through research and trial and error. Unfortunately I'm stuck. any info would be greatly appreciated. The code I've been tinkering with is below.
Thank you !
Code:
// Button Mode Switching
#include <Bounce.h>
const int channel = 1;
byte pgcNum = 0;
Bounce button0 = Bounce(0, 5);
Bounce button1 = Bounce(1, 5);
void setup() {
pinMode(13, OUTPUT);
pinMode(0, INPUT_PULLUP);
pinMode(1, INPUT_PULLUP);
}
void loop() {
int ledPin = 13;
int btn0State = button0.fallingEdge();
int btn1State = button1.fallingEdge();
button0.update();
button1.update();
if(btn0State == HIGH) { usbMIDI.sendNoteOn(60, 99, channel);
digitalWrite(ledPin,HIGH);
delay(10);
digitalWrite(ledPin,LOW);
}
if(btn1State == HIGH) { usbMIDI.sendNoteOn(62, 99, channel);
digitalWrite(ledPin,HIGH);
delay(10);
digitalWrite(ledPin,LOW);
}
while (usbMIDI.read()) {
// ignore incoming messages
}
}