2

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
asked Apr 24, 2017 at 0:45
4
  • the change of the array is shown in the MyHandleNoteOff and MyHandleNoteOn functions. Commented Apr 24, 2017 at 10:46
  • You don't need to call getData1() because the MyHandle function already get this in their parameters. You are probably not using volatile. Commented Apr 24, 2017 at 10:57
  • so i should use pitch instead of data1 ? Commented Apr 24, 2017 at 11:34
  • @CL. making that change had no effect.i think the while loop is blocking.dose it look like the while is the issue? Commented Apr 24, 2017 at 11:48

0

Know someone who can answer? Share a link to this question via email, Twitter, or Facebook.

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.