LED dims when MOSFET switching at a higher speed
You haven't shown us enough of your code, but presumably this fragment is embedded in a loop of some sort, perhaps even an Arduino-specific loop() function.

What this means is that your "off" time is not equal to your "on" time. The "on" time is simply the 10 &micro;s delay, but the "off" time is the 10 &micro;s delay plus the loop overhead &mdash; which might include the overhead of exiting the loop() function and then re-entering again.

As you decrease the nominal delay value, that loop overhead becomes a greater fraction of the total period, skewing the duty cycle and therefore the LED brightness.

This will be obvious if you simply look at the output pin with an oscilloscope.



Looking at the "full code" in your edit, there are many ways it could be optimized. I would try something like this:

#include &lt;SPI.h&gt;
#include &lt;SD.h&gt;
File dataFile;
int myData_read;

void setup() {
  pinMode(12, OUTPUT);
  Serial.begin(210000);

  if (!SD.begin(10)) {
    Serial.println("Card failed, or not present");
    return;
  }
  Serial.println("card initialized.");
  dataFile = SD.open("DATALOG.dat");
  myData_read = dataFile.read();
  //Serial.println(myData_read);
  dataFile.close();
}

void loop() {
  for (int i=0; i &lt; 8; i++) {
    if (myData_read &amp; (1&lt;&lt;i)) {
      PIOD-&gt;PIO_SODR = 1&lt;&lt;8; //HIGH on pin 12
      //digitalWrite(12, HIGH);
    } else {
      PIOD-&gt;PIO_CODR = 1&lt;&lt;8; //LOW on pin 12
      //digitalWrite(12,LOW);
    }
    delayMicroseconds(5);
  }
}


There's no reason to read the file over and over again in the loop, and the&gt;&gt; i in theif statement is completely superfluous.