Led blink help please.!

Hello.
I made this code.
I need led blink

Its not problem to have , led high or low but led no blink! I dont know why!

void loop()
{
  unsigned long t1;

  Usb.Task();
  t1 = micros();
  if( Usb.getUsbTaskState() == USB_STATE_RUNNING )
  {
    MIDI_poll();
  }
  //delay(1ms)
  doDelay(t1, micros(), 1000);
} 


void MIDI_poll()
{
    byte outBuf[ 3 ];
    uint8_t size;
    do {
        if( (size=Midi.RecvData(outBuf)) > 0 ){
            Serial1.write(outBuf, size);

            if((outBuf[0] & 0xf0) == 0xb0){ 
                if(outBuf[1] == 34 && outBuf[2] == 0x00){ // Record
                    Serial1.write(nrpnReco, sizeof(nrpnReco)); // send to do MIDI

                    digitalWrite(led, HIGH);   // turn the LED on (HIGH is the voltage level)
                    delay(1000);               // wait for a second
                    digitalWrite(led, LOW);    // turn the LED off by making the voltage LOW
                    delay(1000);               // wait for a second
}
                }
               
            }
        }
    }while(size>0);
}

Thank you

As I see it in your code, you have one "}" too many at the end of your do-while loop.

void MIDI_poll()
{
  byte outBuf[ 3 ];
  uint8_t size;
  do
  {
    if ( (size = Midi.RecvData(outBuf)) > 0 )
    {
      Serial1.write(outBuf, size);
      if ((outBuf[0] & 0xf0) == 0xb0)
      {
        if (outBuf[1] == 34 && outBuf[2] == 0x00)
        { // Record
          Serial1.write(nrpnReco, sizeof(nrpnReco)); // send to do MIDI
          digitalWrite(led, HIGH);   // turn the LED on (HIGH is the voltage level)
          delay(1000);               // wait for a second
          digitalWrite(led, LOW);    // turn the LED off by making the voltage LOW
          delay(1000);               // wait for a second
        } // end of if outbuf [01] bracket
      } // end of if outbuf [0] bracket
    } // end of if size bracket
  } //end of do bracket
  while (size > 0);
} // end of function void MIDI_poll() bracket

Sorry my bad copy of code .Bracket are not problem.

Problem is Midi_poll() function is inside void loop(), only like function not directly.Is it true?
Why ,when is delay out of void loop, does not repeat ?

/*
 *******************************************************************************
 * USB-MIDI to Legacy Serial MIDI converter
 * Copyright 2012-2014 Yuuichi Akagawa
 *
 * Idea from LPK25 USB-MIDI to Serial MIDI converter
 *   by Collin Cunningham - makezine.com, narbotic.com
 *
 * for use with USB Host Shield 2.0 from Circuitsathome.com
 * https://github.com/felis/USB_Host_Shield_2.0
 *******************************************************************************
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>
 *******************************************************************************
 */

#include <Usb.h>
#include <usbh_midi.h>

#ifdef USBCON
#define _MIDI_SERIAL_PORT Serial1
#else
#define _MIDI_SERIAL_PORT Serial
#endif
//////////////////////////
// MIDI Pin assign
// 2 : GND
// 4 : +5V(Vcc) with 220ohm
// 5 : TX
//////////////////////////

const int led = 13
USB  Usb;
USBH_MIDI  Midi(&Usb);

void MIDI_poll();
void doDelay(unsigned long t1, unsigned long t2, unsigned long delayTime);

void setup()
{
  Serial1.begin(31250);
  pinMode(13, OUTPUT);

  //Workaround for non UHS2.0 Shield 
  pinMode(7,OUTPUT);
  digitalWrite(7,HIGH);

  if (Usb.Init() == -1) {
    while(1); //halt
  }//if (Usb.Init() == -1...
  delay( 200 );
}

void loop()
{
  unsigned long t1;

  Usb.Task();
  t1 = micros();
  if( Usb.getUsbTaskState() == USB_STATE_RUNNING )
  {
    MIDI_poll();
  }
  //delay(1ms)
  doDelay(t1, micros(), 1000);
}



byte nrpnReco[] = {0xB0,0x63,0x7D,0xB0,0x62,0x58,0xB0,0x06,0x00,0xB0,0x26,0x01};

// Poll USB MIDI Controler and send to serial MIDI
void MIDI_poll()
{
    byte outBuf[ 3 ];
    uint8_t size;

    do {
      if( (size=Midi.RecvData(outBuf)) > 0 ){
         if((outBuf[0] & 0xf0) == 0xb0){ // byl prijat CC
                if(outBuf[1] == 34 && outBuf[2] == 0x00){ // Record
                    Serial1.write(nrpnReco, sizeof(nrpnReco)); 
                }
         }
        Serial1.write(outBuf, size);
        Serial1.write(nrpnReco, sizeof(nrpnReco));
        
        digitalWrite(led, HIGH);   // turn the LED on (HIGH is the voltage level)
        delay(1000);               // wait for a second
        digitalWrite(led, LOW);    // turn the LED off by making the voltage LOW
        delay(1000);   
        
      }
    }while(size>0);
}

// Delay time (max 16383 us)
void doDelay(unsigned long t1, unsigned long t2, unsigned long delayTime)
{
    unsigned long t3;

    if( t1 > t2 ){
      t3 = (4294967295 - t1 + t2);
    }else{
      t3 = t2 - t1;
    }

    if( t3 < delayTime ){
      delayMicroseconds(delayTime - t3);
    }
}

You are declaring your functions :

void MIDI_poll();
void doDelay(unsigned long t1, unsigned long t2, unsigned long delayTime);

As I understand it, the compiler does not need a declaration on functions.
my guess is, that this even upsets the compiler, giving you problems.

You just write your functions, as you have already done later down in your code, after the loop section.

You have a global variable declaration im the middle of your code.
byte nrpnReco =

This is NOT wrong, but it is surprising, as one expects to find variable declarations on top of the code :slight_smile:

MIDI_poll(); must be in void loop() , otherwise it does not work.

void loop()
{
   
  unsigned long t1;

  Usb.Task();
  t1 = micros();
  if( Usb.getUsbTaskState() == USB_STATE_RUNNING )
  {
     
    
   MIDI_poll();
    
  }
  //delay(1ms)
  doDelay(t1, micros(), 1000);


}

Now I wrote

                if(outBuf[1] == 50 && outBuf[2] == 0x7f){      
                digitalWrite(ledPin ,HIGH);              
                     delay(1000);              // wait for a second
                digitalWrite(ledPin, LOW);    // turn the LED off by making the voltage LOW
                   delay(1000);  }

and led blink only on then off.
Not repeate.