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

Thread: A better LED circuit for MIDI activity indicator

  1. #1
    Senior Member
    Join Date
    Jun 2013
    Posts
    346

    A better LED circuit for MIDI activity indicator

    I have a MIDI out port with an LED and 220 ohm resistor connected between pins four and five to serve as a MIDI activity indicator. The trouble is that MIDI messages are so short, that the LED is barely visible. Is there some other circuit I could make with a transistor or some other component to make the LED light for longer? I have no free iO pins, so that is not an option.

    Regards,
    Rob

  2. #2
    Senior Member
    Join Date
    Jun 2013
    Posts
    346
    Looks like a 555 timer might do the trick.

  3. #3
    Senior Member
    Join Date
    Apr 2020
    Location
    DFW area in Texas
    Posts
    128
    Quote Originally Posted by yeahtuna View Post
    I have a MIDI out port with an LED and 220 ohm resistor connected between pins four and five to serve as a MIDI activity indicator. The trouble is that MIDI messages are so short, that the LED is barely visible. Is there some other circuit I could make with a transistor or some other component to make the LED light for longer? I have no free iO pins, so that is not an option.

    Regards,
    Rob
    yeahtuna:

    I needed this exact same thing in my TeensyMIDIPolySynth project. I ended up using a (boolean-like) variable to control driving the LED.

    Code:
    int midi_note_activity_state = false;
    I also defined another variable that is used in the timing of illuminating & extinguishing the LED (& the defined duration):

    Code:
    // keep track of how long to light the MIDI activity LED
    #define ACTIVITY_LED_DURATION_MILLIS 5
    unsigned long led_time;
    Here's an example of when the "boolean" variable is set:

    Code:
    // MIDI message callback - note on
    void handleNoteOn(byte channel, byte pitch, byte velocity)
    {
       midi_note_activity_state = true;
    
       . . .
    }  // handleNoteOn()
    And, inside of the loop() function, here's the code that actually illuminates the LED for the defined period:

    Code:
          if (midi_note_activity_state == true)
          {
             digitalWrite(MIDI_NOTE_ACTIVITY_LED_PIN, HIGH);
          }
    
          led_time = millis();
          midi_note_activity_state = false;
    
          while ((midi_note_activity_state == false) && ((millis() - led_time) < ACTIVITY_LED_DURATION_MILLIS)) {};
    
          digitalWrite(MIDI_NOTE_ACTIVITY_LED_PIN, LOW);
    All of this together causes the LED to turn on when activated & to normally stay on for the defined duration. If another call sets the "boolean" while the LED is illuminated, The LED will flicker quickly (with each subsequent call) & stay on for the defined duration of the last activity.

    I have another set of variables for the "midi_control_activity_state" that are used to drive another LED for control messages, but did not include that additional functionality here in an attempt to minimize complexity/confusion. These two together provide a nice real-time indication of my incoming MIDI messages.

    Hope that helps . . .

    Good luck & have fun !!

    Mark J Culross
    KD5RXT

  4. #4
    Senior Member
    Join Date
    Jun 2013
    Posts
    346
    Thanks, Mark. Unfortunately, as stated in the first post, I have no free iO pins.

  5. #5
    Senior Member
    Join Date
    Apr 2020
    Location
    DFW area in Texas
    Posts
    128
    Quote Originally Posted by yeahtuna View Post
    Thanks, Mark. Unfortunately, as stated in the first post, I have no free iO pins.
    yeahtuna:

    So sorry, I definitely should have read your post more closely !! Can you take some of the I/O currently in use & combine thru a 74HC4067 16-to-1 analog MUX (for input sampling) or a 74HC595 (for output driving) to free up some pins ?? Otherwise, the 555 approach sounds like it would work.

    Good luck & have fun !!

    Mark J Culross
    KD5RXT

  6. #6

  7. #7
    Senior Member
    Join Date
    Jun 2013
    Posts
    346
    I changed my led from green to orange and that has made a world of difference. No need for anything fancier.

Posting Permissions

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