Hardware Reference
In-Depth Information
is closed, and a logical 0 (LOW) if the door is opened. How long was the door
opened for? The Arduino can tell you.
pulseIn()
pulseIn() will tell you the length of a pulse. It requires a pin as a parameter and
the type of pulse to read. When programmed, the Arduino waits for a signal
on the selected pin. For example, you can tell the Arduino to wait for a pin to
go HIGH. When it does, it starts a counter. When the signal returns to LOW, it
stops the counter, and returns the number of microseconds. If no signal change
is received within a set time, the function gives up and returns 0.
unsigned long length pulseIn(pin, value)
unsigned long length pulseIn(pin, value, time-out)
The pin parameter is the pin number to listen on, as an int value. The value
parameter is the type of signal to wait for: either HIGH or LOW . The optional
timeout parameter tells the Arduino how long to wait for a signal. It is an
unsigned long and represents the amount of microseconds to wait. If omitted,
it waits for 1 second before timing out.
pulseIn() is accurate within 10 microseconds when the time-out is up to
3 minutes long. Pulses longer than 3 minutes may be calculated inaccurately.
Also, responding to interrupts can give inaccurate results because the internal
timers are not updated during interrupt handling.
Time Functions
Timing is important in electronics projects. Electronics are not instantaneous,
and most sensor components require some time before they can be accessed. A
typical one-wire humidity sensor requires 100 ms of time between the command
to acquire a reading and returning the result. Querying the component before
it has had adequate time to complete its task could result in malformed data or
cause the component to send a previous result. In either case, your sketch might
not work as intended. Fortunately, Arduinos can patiently wait for a specii ed
amount of time, by calling delay() .
Another time function on Arduinos is the ability to get the time that the
current sketch has been running. When an Arduino is powered on (or reset),
two counters begins counting: the number of microseconds that the system has
been running and the number of milliseconds.
delay()
delay() tells the microcontroller to wait for a specii ed number of milliseconds
before resuming the sketch. This can be used to tell the microcontroller to wait
 
Search WWH ::




Custom Search