# How to get the time of an executed line of codes ?

hello guys,
i am working with a switch hall effect, in my script i put a counter to count everytime the switch has changed status, so i need please to know how to get the time that it took between a changed state and another?
here is my script :

``````const int hallPin = 2;     // the number of the hall effect sensor pin
const int ledPin =  13;     // the number of the LED pin
boolean lastHallState = HIGH; // pulled up with a resistor
boolean currentHallState = HIGH;
boolean ledOn = false;

// variables will change:
int hallState = 0;      // number of rounds

void setup() {
Serial.begin(9600);
// initialize the LED pin as an output:
pinMode(ledPin, OUTPUT);
// initialize the hall effect sensor pin as an input:
pinMode(hallPin, INPUT);
}

//Halldebounce function
boolean debounceHall(boolean last)
{
if(last != current)
{
delay(5);
}
return current;
}

void loop(){
currentHallState = debounceHall(lastHallState);
if(lastHallState == HIGH && currentHallState == LOW)
{
hallState++; // rounds++

}

lastHallState = currentHallState;
Serial.println(hallState);

}
``````

There is a pulseIn() function to measure pulses. Would that help?

If not, you can record the time of change with micros() and subtract to get duration.

johnwasser:
There is a pulseIn() function to measure pulses. Would that help?

If not, you can record the time of change with micros() and subtract to get duration.

ok this would help thanks a lot , i need to know please how to convert it into seconds ? is there any function that can do that ? or i must calculate it the classical way ?

i need to know please how to convert it into seconds ?

The number of microseconds in a second IS a constant.

firashelou:
i need to know please how to convert it into seconds ? is there any function that can do that ? or i must calculate it the classical way ?

You want a function to divide something by 1000000?

As opposed to the "classical way"?

``````foo = bar / 1000000;
``````

ok thanks guys