Hello,
I'm working on a project, that should use incoming different specific "note on" - messages to shift out to 74HC registers. "Note off" - messages are irrelevant.
That works fine with the recommended "usbMIDI.setHandleNoteOn(OnNoteOn);" in the setup and the "void OnNoteOn(byte channel, byte note, byte velocity)"
But I need a time distance to do two more things (two shiftregister changes) after the incoming specific "note on". I don't want to use the "delay();" - function, because I have to read other incoming messages. Now I'm thinking the "void OnNoteOn(.......)" runs only once after each "note on" - message. Thats why I can't use a variable that stores the "millis()"-function to do a second and a third task after a while in this void like this:
My first question is: can I use a "return" - command from inside the "void OnNoteOn(byte channel, byte ...)" to the void loop to do the time distance and the next related tasks? I don't think so, but I have not much informatic knowledge - just learning by doing.
If the answer is "no", my second question: Is it possible to use the "void OnNoteOn(byte ...)" as "unsigned long OnNoteOn(...)" with a "return Tnote35on;" - command, to realize my intention???
I've tried this. Not yet successful. That's why I read the "Using USB MIDI" - page again and now I'm thinking about the "usbMidi.get..." - commands. I tried "usbMIDI.getNoteOn" after "usbMIDI.read();" and get this:
I clearly need a better understanding, how to use the "usbMIDI.get..." - command. What is needed for its use (which other commands around, implementations in the scope or at other places in the programm)? The 4th question - probably the most significant one.
Thanks for your help and kind regards,
artU
I'm working on a project, that should use incoming different specific "note on" - messages to shift out to 74HC registers. "Note off" - messages are irrelevant.
That works fine with the recommended "usbMIDI.setHandleNoteOn(OnNoteOn);" in the setup and the "void OnNoteOn(byte channel, byte note, byte velocity)"
But I need a time distance to do two more things (two shiftregister changes) after the incoming specific "note on". I don't want to use the "delay();" - function, because I have to read other incoming messages. Now I'm thinking the "void OnNoteOn(.......)" runs only once after each "note on" - message. Thats why I can't use a variable that stores the "millis()"-function to do a second and a third task after a while in this void like this:
Code:
void OnNoteOn(byte channel, byte note, byte velocity) {
unsigned long T = millis(); // T = time = now
// **************** B0 midi 35 ************************
// magnet forward
if (note == 35) { // = B0 - 61,735 Hz
digitalWrite(ledPin, HIGH); // LED ON
magnets[0] = 1; // "magnets[]" is an array with 16 elements
magnets[1] = 0;
Tnote35on = T; // time when note on was played ("Tnote35on" is declared as unsigned long)
shiftPlay(); // shift out to the two 74HC959 registers
}
// I think the next task and the following can't be done
// magnet back
if (T >= Tnote35on + Tforw) { // "Tforw" is declared as const int to make a time distance
digitalWrite(ledPin, LOW); // Led Off
magnets[0] = 0;
magnets[1] = 1;
shiftPlay();
}
// magnet off
if (T >= Tnote35on + Tforw + Tback) { // "Tback" is declared as const int
magnets[0] = 0;
magnets[1] = 0;
shiftPlay();
}
My first question is: can I use a "return" - command from inside the "void OnNoteOn(byte channel, byte ...)" to the void loop to do the time distance and the next related tasks? I don't think so, but I have not much informatic knowledge - just learning by doing.
If the answer is "no", my second question: Is it possible to use the "void OnNoteOn(byte ...)" as "unsigned long OnNoteOn(...)" with a "return Tnote35on;" - command, to realize my intention???
I've tried this. Not yet successful. That's why I read the "Using USB MIDI" - page again and now I'm thinking about the "usbMidi.get..." - commands. I tried "usbMIDI.getNoteOn" after "usbMIDI.read();" and get this:
'class usb_midi_class' has no member named 'getNoteOn'
I clearly need a better understanding, how to use the "usbMIDI.get..." - command. What is needed for its use (which other commands around, implementations in the scope or at other places in the programm)? The 4th question - probably the most significant one.
Thanks for your help and kind regards,
artU