Test code using 9600 baud:
int ledPin = 13;
//variables to keep track of time of injection code////
unsigned long time1 = 0;
unsigned long time2 = 0;
void setup()
{
pinMode(ledPin, OUTPUT);
digitalWrite(ledPin, LOW);
Serial.begin(9600);
}
void loop()
{
digitalWrite(ledPin, HIGH);
time1 = micros();
Serial.print("light the LED for all to see! ");
Serial.println(time1);
Serial.print("Turn off the LED it does not need to be ");
digitalWrite(ledPin, LOW);
time2 = micros();
Serial.println(time2);
Serial.print("total time = ");
Serial.print(time2 - time1);
Serial.println("micros");
delay(5000);
}
Typical output in micros():
light the LED for all to see! 35358256
Turn off the LED it does not need to be 35373908
total time = 15652micros
Using 115200 baud:
light the LED for all to see! 35029036
Turn off the LED it does not need to be 35030356
total time = 1320micros
Removing all but total time print, code:
int ledPin = 13;
//variables to keep track of time of injection code////
unsigned long time1 = 0;
unsigned long time2 = 0;
void setup()
{
pinMode(ledPin, OUTPUT);
digitalWrite(ledPin, LOW);
Serial.begin(115200);
}
void loop()
{
digitalWrite(ledPin, HIGH);
time1 = micros();
digitalWrite(ledPin, LOW);
time2 = micros();
Serial.print("micros = ");
Serial.println(time2 - time1);
delay(5000);
}
results:
micros = 12
micros = 12
micros = 8
micros = 8
micros = 8