Code to calculate time in between two events

lets say the MCU uses millis()

.

unsigned long startcountthingy= 0;
unsigned long endcountthingy=0;

voided ThingyDetectorFunction()
{

if DetectorThingyOneGetStartSignal
{
startcountthingy=millis();
endcountthingy=0;
}

if  DetectorThingyTwoGetEndSignal
{

endcountthingy=millis()

unsigned long HowLongThingyDetected = startcountthingy - endcountthingy;

}
}

or something like that

2 Likes