ISR to map MIDI notes to output pins?

Status
Not open for further replies.

mikemontauk

Active member
Hello, I am using the Teensy (LC) to illuminate LEDs based on the MIDI note-on received. I manually assigned 5 notes (e.g. 60, 61, 62, 63, 64) to 5 LEDs. It's working nicely; when I press one of the 5 assigned notes on my keyboard the correct/corresponding LEDs illuminate.

Next, I want to create an ISR so that when a push-button is pressed, the program 'learns' the next 5 MIDI notes received (stores and maps them to outputs).

High-level description of desired process and steps:
a) push-button pressed;
b) wait for 5 MIDI notes received, e.g.: 56, 57, 70, 79, 90; then
c) map 56, 57, 70, 79, 90 to specified 5 outputs
d) result - MIDI note-on messages 56, 57, 70, 79, 90 will trigger the LEDs.

I have tried implementing a 'for' loop in an ISR to record the next 5 midi note-on messages in an array but I can't figure out how to 'wait' for 5 MIDI notes. (My loop terminates before 5 notes can be pressed and the array ends up being 5 of the same note.) I think this is because "you must call usbMIDI.read() regularly from loop() for usbMIDI to actually read incoming data and run the handler functions as messages arrive."

I suspect I need to run usbMIDI.read() inside a loop inside my ISR but I cannot find direction on how to do so. Any help would be appreciated. Best regards.
 
Hi,
An interrupt service routine should only react to the single event that triggers it - it should never wait for another event. It should also run as quickly as possible.
If you post your current code, someone may suggest a way to modify it to do what you want.
 
Hi,

I even would not use an ISR for this. Teensy is fast enough for doing this within loop(). Use flags and timers to control.
 
This is a job for a state machine. Any multistage interaction with input or output would usually require
a state machine to track state without locking out other features.
 
Status
Not open for further replies.
Back
Top