Hey Y'all! I'm currently trying to create a midi keyboard using the USB-MIDI Library. Right now, I have seven buttons going into different digital ports on a Leonardo. The goal is that when I press the button, it will play that note. I'm close, but I am running into an issue.
When I press a button, it does play that note. However, it then will start cycling through the scale without the other buttons being pressed. Does anyone have an idea of what may be causing this? This is the code I have right now:
#include <USB-MIDI.h>
USBMIDI_CREATE_DEFAULT_INSTANCE();
int C = 2;
int D = 3;
int E = 4;
int F = 5;
int G = 6;
int A = 7;
int B = 8;
void setup() {
// put your setup code here, to run once:
pinMode (2, INPUT);
pinMode (3, INPUT);
pinMode (4, INPUT);
pinMode (5, INPUT);
pinMode (6, INPUT);
pinMode (7, INPUT);
pinMode (8, INPUT);
}
void loop() {
// put your main code here, to run repeatedly:
//C
if (C, HIGH) {
MIDI.sendNoteOn(60, 100, 1);
delay(1000);
}
else {
MIDI.sendNoteOff(60, 0, 1);
}
//D
if (D, HIGH) {
MIDI.sendNoteOn(62, 100, 1);
delay(1000);
}
else {
MIDI.sendNoteOff(62, 0, 1);
}
//E
if (E, HIGH) {
MIDI.sendNoteOn(64, 100, 1);
delay(1000);
}
else {
MIDI.sendNoteOff(64, 0, 1);
}
//F
if (F, HIGH) {
MIDI.sendNoteOn(65, 100, 1);
delay(1000);
}
else {
MIDI.sendNoteOff(65, 0, 1);
}
//G
if (G, HIGH) {
MIDI.sendNoteOn(67, 100, 1);
delay(1000);
}
else {
MIDI.sendNoteOff(67, 0, 1);
}
//A
if (A, HIGH) {
MIDI.sendNoteOn(69, 100, 1);
delay(1000);
}
else {
MIDI.sendNoteOff(69, 0, 1);
}
//B
if (B, HIGH) {
MIDI.sendNoteOn(71, 100, 1);
delay(1000);
}
else {
MIDI.sendNoteOff(71, 0, 1);
}
}