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.
MB1210.h
- Committer:
- Blaze513
- Date:
- 2010-08-26
- Revision:
- 3:05183e50a923
- Parent:
- 2:997b4057c879
- Child:
- 4:a615b75d4126
File content as of revision 3:05183e50a923:
//mbed Microcontroller Library //Max Botix Ultrasonic Range Finder MB1210 Interface //Copyright 2010 //Thomas Hamilton #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; unsigned short Range; 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 DiscardSerialBuffer(); //the serial port has a buffer and only the oldest data is read from it; //the buffer has limited space and, when full, the newest data is discarded; //this method allows the user to empty the buffer of old data so new data is used 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