Accurate Arduino timing code

Code below will accurate blink an led on 13 at Hertz, accurate to 1 microsecond (+ for Xtal drift)

digitalWrite(13,temp_flash);
   
  time_delay_usec_elapsed = micros() - time_delay_usec_start;
  if(time_delay_usec_elapsed > 1000000)
  {
    Serial.write("Got here/n");
      time_delay_usec_start = micros();
     
      if(temp_flash == 1)
      {
        digitalWrite(13,0);
        temp_flash = 0;
      }
      else
      {
          digitalWrite(13,1);
          temp_flash = 1;
      }
     
  }
Save Now

Comments