Forum Rule: Always post complete source code & details to reproduce any issue!
Results 1 to 4 of 4

Thread: ISR to map MIDI notes to output pins?

  1. #1
    Junior Member
    Join Date
    Oct 2021

    ISR to map MIDI notes to output pins?

    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 regularly from loop() for usbMIDI to actually read incoming data and run the handler functions as messages arrive."

    I suspect I need to run inside a loop inside my ISR but I cannot find direction on how to do so. Any help would be appreciated. Best regards.

  2. #2
    Join Date
    Feb 2020
    Dublin, Ireland
    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.

  3. #3
    Senior Member
    Join Date
    May 2017

    I even would not use an ISR for this. Teensy is fast enough for doing this within loop(). Use flags and timers to control.

  4. #4
    Senior Member
    Join Date
    Jul 2020
    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.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts