millis() returns an unsigned long, an int would overflow within a minute....
unsigned long measureTime(uint8_t pinA, uint8_t pinB)
{
while (digitalRead(pinA) == LOW) ;
unsigned long first = millis();
while (digitalRead(pinB) == LOW);
unsigned long timetaken = millis()-first;
}
Another approach would be IRQ based, leaves room for the Arduino to do something while waiting....
volatile unsigned long first = 0;
volatile unsigend long second = 0;
void IRQA()
{
first = millis();
}
void IRQB()
{
second = millis();
}
void resetTime()
{
first = second = 0;
}
unsigned long lapTime()
{
return millis() - first;
}
unsigned long finalTime()
{
if (second > 0) return second - first;
return 0;
}
or use -
http://www.arduino.cc/playground/Code/StopWatchClass -
volatile unsigned StopWatch MySW;
void IRQA()
{
MySW.start();
}
void IRQB()
{
MySW.stop();
}
my 2 cents
Rob