Interface class for the Max Botix ultrasonic range finder model 1210. It includes input methods for PWM, Analog, and Serial. A PwmIn class was created to allow the PWM input to be read. Now includes automatic range update via interrupts.
Diff: PwmIn/PwmIn.cpp
- Revision:
- 0:3d969e0b4ca0
- Child:
- 2:997b4057c879
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/PwmIn/PwmIn.cpp Sun Aug 22 21:18:20 2010 +0000 @@ -0,0 +1,54 @@ +#include "PwmIn.h" + +PwmIn::PwmIn(PinName pwi) : InterruptIn(pwi), PeriodMeasurement(0), PulseWidthMeasurement(1) +{ + rise(this, &PwmIn::PulseStart); + fall(this, &PwmIn::PulseStop); + start(); +} + +float PwmIn::read() +{ + return (float)PulseWidthMeasurement / PeriodMeasurement; +} + +float PwmIn::period() +{ + return (float)PeriodMeasurement / 1000000; +} + +int PwmIn::period_ms() +{ + return PeriodMeasurement / 1000; +} + +int PwmIn::period_us() +{ + return PeriodMeasurement; +} + +float PwmIn::pulsewidth() +{ + return (float)PulseWidthMeasurement / 1000000; +} + +int PwmIn::pulsewidth_ms() +{ + return PulseWidthMeasurement / 1000; +} + +int PwmIn::pulsewidth_us() +{ + return PulseWidthMeasurement; +} + +void PwmIn::PulseStart() +{ + PeriodMeasurement = read_us(); + reset(); +} + +void PwmIn::PulseStop() +{ + PulseWidthMeasurement = read_us(); +} \ No newline at end of file