User Manual

This function returns the length in system ticks (units of 0.4 µs) of the last complete high pulse received
on the specified pulse input channel. It gives you (interrupt-safe) access to the lastHighPulse member
of the ISR-maintained PulseInputStruct for the specified channel. A high pulse is one that starts with a
channel transition from low to high and ends with a channel transition from high to low. Note that if the
last high “pulse” was longer than 28.6 minutes, the value returned by this function will have overflowed
and the result will be incorrect. You should disregard the first high pulse after the pulse input line has
been in a steady-high state for more than 28. minutes.
static unsigned long OrangutanPulseIn::getLastLowPulse(unsigned char channel)
unsigned long get_last_low_pulse(unsigned char channel)
This function returns the length in system ticks (units of 0.4 µs) of the last complete low pulse received
on the specified pulse input channel. It gives you (interrupt-safe) access to the lastLowPulse member
of the ISR-maintained PulseInputStruct for the specified channel. A low pulse is one that starts with a
channel transition from high to low and ends with a channel transition from low to high. Note that if the
last low “pulse” was longer than 28.6 minutes, the value returned by this function will have overflowed
and the result will be incorrect. You should disregard the first low pulse after the pulse input line has been
in a steady-low state for more than 28. minutes.
static void OrangutanPulseIn::getCurrentState(unsigned char channel, unsigned long* pulse_width,
unsigned char* state)
void get_current_pulse_state(unsigned char channel, unsigned long* pulse_width, unsigned char*
state)
This function gives you information about what is currently happening on the specified pulse input
channel by using the argument pulse_width to return the number of system ticks that have elapsed since
the last complete pulse ended (in units of 0.4 µs) and by using the argument state to return whether the
voltage on the input channel is currently HIGH (1) or LOW (0). The pulse_width and state arguments are
pointers to integer types whose values are respectively set (in an ISR-safe way) based on the lastPCTime
and inputState members of the ISR-maintained PulseInputStruct for the specified channel. Specifically,
*pulse_width is set to: get_ticks()-pulseInfo[channel].lastPCTime
Example
unsigned long pulse_width;
unsigned char state;
// get info for pulse input channel channel 0:
get_current_pulse_state(0, &pulse_width, &state);
if (pulse_width > 250000 && state == HIGH)
{
// if more than 100 ms have passed since last pulse ended
// and the pulse input channel is currently high
doSomething();
}
unsigned long pulse_width;
unsigned char state;
// get info for pulse input channel channel 0:
OrangutanPulseIn::getCurrentState(0, &pulse_width, &state);
if (pulse_width > 250000 && state == HIGH)
{
// if more than 100 ms have passed since last pulse ended
// and the pulse input channel is currently high
doSomething();
}
unsigned long OrangutanPulseIn::toMicroseconds(unsigned long pulse_width)
unsigned long pulse_to_microseconds(unsigned long pulse_width)
Pololu AVR Library Command Reference © 2001–2015 Pololu Corporation
8. Orangutan Pulse/PWM Inputs Page 34 of 65