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: MB1210.h
- Revision:
- 0:3d969e0b4ca0
- Child:
- 1:b533b95e807a
diff -r 000000000000 -r 3d969e0b4ca0 MB1210.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/MB1210.h Sun Aug 22 21:18:20 2010 +0000 @@ -0,0 +1,65 @@ +#ifndef MB1210Library +#define MB1210Library + +#include "mbed.h" +#include "PwmIn.h" + +class MB1210 +{ + private: + PwmIn* PwmInput; + AnalogIn* AnalogInput; + DigitalOut* SerialOutput; + Serial* SerialInput; + + char OperatingMode; + float UnitFactor; + float PwmScalingFactor; + float AnalogScalingFactor; + char Workspace[4]; + + public: + MB1210(PinName pw, PinName an, PinName tx, PinName rx); + //pulse width modulation input, analog input, serial output, serial input; + //specify NC if pin is not used + ~MB1210(); + //deallocates PwmInput, AnalogInput, SerialOutput, and SerailInput + void SoundVelocity(float MetersPerSecond); + //if, for some reason, you need to correct the speed of sound + //for Pwm modes, enter the new value here in meters per second; + //default is 340.29 m/s + //Note: most accurate mode + void Voltage(float Volts); + //sets expected operating voltage for Analog modes; + //user responsibility to ensure operating voltage between 3.3 V and 5 V; + //default is 3.3 V + void Unit(float UnitsPerMeter); + //argument sets the putput units through multiplication; + //default is cm + void Mode(char Selection); + //argument sets operating mode; + //0 to 2 for synchronous modes, 4 to 6 for asynchronous modes; + //0 and 4 for pwm, 1 and 5 for analog, 2 and 6 for serial; + //default is 0 + void RequestSyncRead(); + //this tells the device to prepare a synchronous range reading; + //must be called at least 99 ms before the reading is needed; + //changes asynchronous mode to synchronous equivalent + void DiscardBuffer(); + //empties the buffer on the serial port to sync the next reading + float Read(); + //get a reading from the device in the set mode; + //RequestSyncRead() must be called at least 99 ms + //before this method can be called in a synchronous mode; + //may be called at any time during asynchronous mode; + void Read(char* Buffer); + //overloaded to take advantage of Serial ASCII string output; + //Buffer must be 3 bytes; 3 digit ASCII number + //measures range in cm regardless of selected unit; + //uses serial input method regardless of selected mode. + operator float(); + //shorthand for taking a range reading; + //ex: "float reading = MB1210Object;" +}; + +#endif \ No newline at end of file