I am trying to pass the input[]
, data1(pitch)
from a Midi controller to the waitForButton
function. When a key is pressed it sends data1(pitch)
into the array input[]
, and when the key is up the array value goes to zero. But the input isn't being passed to the function as I am pressing the keys on the Midi controller. What am I missing?
void MyHandleNoteOn(byte channel, byte pitch, byte velocity) {
data1 = MIDI.getData1();
if (data1==48) { //C3
Status[0][0]=1;
noteOn(0,data1,100);
input[0]=data1;
}
}
void MyHandleNoteOff(byte channel, byte pitch, byte velocity) {
data1 = MIDI.getData1();
if (data1==48) { //C3
Status[0][0]=0;
noteOff(0,data1,100);
input[0]=0;
}
}
void readsequnce() {
bool mademistake = false;
int key;
for (int index = 0; index < largestindex & mademistake == false; index++) {
key = waitForButton(5000);
if(key ==-1 || key != note[index]) {
mademistake = true;
state = 2;
}
}
}
int waitForButton(int laps) {
int keyPressed= -1;
int check;
boolean keyBackUp = false;
currentMillis = millis();
// The number of ms since the program started running
previousMillis = currentMillis;
// Records the point when we start spinning the loop.
// Keep spinning the loop until "delay" seconds have passed.
while (currentMillis - previousMillis < laps & keyBackUp == false) {
lcd.setCursor(16, 2);
lcd.print(String(keyPressed));
// Read the button and record when it has been pushed down.
for (int i = 0; i < 25 & keyBackUp == false; i++) {
if (input[i] != 0) {
keyPressed = input[i];
// Show the LED pushed.
noteOn(0, keyPressed, 100);
// digitalWrite(leds[pin], HIGH);
// It is possible the button is still being pushed.
// This loop spins until the button is let up.
while (currentMillis - previousMillis < laps & keyBackUp == false) {
check = input[i];
if (check == 0) {
keyBackUp = true;
}
currentMillis = millis();
}
// Turn the LED pushed off.
noteOff(0, keyPressed, 0);
// digitalWrite(leds[pin], LOW);
// See if they took to long.
if (currentMillis - previousMillis > laps) {
keyPressed = -1;
// They took to long to let the button up so they lose.
}
}
}
currentMillis = millis();
}
return keyPressed;
}
dda
1,5951 gold badge12 silver badges17 bronze badges
default
getData1()
because theMyHandle
function already get this in their parameters. You are probably not using volatile.