You are on page 1of 3

Description

Reads a pulse (either HIGH or LOW) on a pin. For example, if value is HIGH,
pulseIn() waits for the pin to go HIGH, starts timing, then waits for the pin to go
LOW and stops timing. Returns the length of the pulse in microseconds or 0 if
no complete pulse was received within the timeout.

The timing of this function has been determined empirically and will probably
show errors in shorter pulses. Works on pulses from 10 microseconds to 3
minutes in length. Please also note that if the pin is already high when the
function is called, it will wait for the pin to go LOW and then HIGH before it
starts counting. This routine can be used only if interrupts are activated.
Furthermore the highest resolution is obtained with short intervals.

Syntax

pulseIn(pin, value)
pulseIn(pin, value, timeout)

Parameters

pin: the number of the pin on which you want to read the pulse. (int)
value: type of pulse to read: either HIGH or LOW. (int)

timeout (optional): the number of microseconds to wait for the pulse to be


completed: the function returns 0 if no complete pulse was received within the
timeout. Default is one second (unsigned long).

Returns
the length of the pulse (in microseconds) or 0 if no pulse is completed before
the timeout (unsigned long)

Example
int pin = 7;
unsigned long duration;
void setup()
{
pinMode(pin, INPUT);
}
void loop()
{
duration = pulseIn(pin, HIGH)
}

ESPAOl
Lee un pulso (alto o bajo) en un pin. Por ejemplo, si el valor es alto, pulseIn ()
espera a que el pasador sea alta, se inicia el tiempo, espera a que el pasador
para ir LOW y para el cronmetro. Devuelve la longitud del impulso en
microsegundos o 0 si no hay pulso completa fue recibida dentro del tiempo de
espera.

El momento de esta funcin se ha determinado empricamente y


probablemente mostrar errores en pulsos ms cortos. Funciona en pulsos de
10 microsegundos a 3 minutos de duracin. Tenga en cuenta tambin que si el
pasador ya es alto cuando la funcin es llamada, se espera que el pasador a
nivel bajo y luego ALTA antes de que empiece a contar. Esta rutina se puede
utilizar slo si se activan las interrupciones. Adems, la resolucin ms alta se
obtiene con intervalos cortos.

Sintaxis

pulseIn (pin, valor)


pulseIn (pin, valor, tiempo de espera)

parmetros

pin: el nmero del pin en el que desea leer el pulso. (Int)

Valor: tipo de impulso para que diga: ya sea alta o baja. (Int)

Tiempo de espera (opcional): el nmero de microsegundos que esperar a que


el pulso va a realizar: la funcin devuelve 0 si no hay pulso completa se recibe
dentro del tiempo de espera. El valor predeterminado es un segundo (largo sin
signo).

Devoluciones

la longitud del pulso (en microsegundos) o 0 si no hay pulso se completa antes


de que el tiempo de espera (unsigned long)

You might also like