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@0:3d969e0b4ca0, 2010-08-22 (annotated)
- Committer:
- Blaze513
- Date:
- Sun Aug 22 21:18:20 2010 +0000
- Revision:
- 0:3d969e0b4ca0
- Child:
- 1:b533b95e807a
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
Blaze513 | 0:3d969e0b4ca0 | 1 | #ifndef MB1210Library |
Blaze513 | 0:3d969e0b4ca0 | 2 | #define MB1210Library |
Blaze513 | 0:3d969e0b4ca0 | 3 | |
Blaze513 | 0:3d969e0b4ca0 | 4 | #include "mbed.h" |
Blaze513 | 0:3d969e0b4ca0 | 5 | #include "PwmIn.h" |
Blaze513 | 0:3d969e0b4ca0 | 6 | |
Blaze513 | 0:3d969e0b4ca0 | 7 | class MB1210 |
Blaze513 | 0:3d969e0b4ca0 | 8 | { |
Blaze513 | 0:3d969e0b4ca0 | 9 | private: |
Blaze513 | 0:3d969e0b4ca0 | 10 | PwmIn* PwmInput; |
Blaze513 | 0:3d969e0b4ca0 | 11 | AnalogIn* AnalogInput; |
Blaze513 | 0:3d969e0b4ca0 | 12 | DigitalOut* SerialOutput; |
Blaze513 | 0:3d969e0b4ca0 | 13 | Serial* SerialInput; |
Blaze513 | 0:3d969e0b4ca0 | 14 | |
Blaze513 | 0:3d969e0b4ca0 | 15 | char OperatingMode; |
Blaze513 | 0:3d969e0b4ca0 | 16 | float UnitFactor; |
Blaze513 | 0:3d969e0b4ca0 | 17 | float PwmScalingFactor; |
Blaze513 | 0:3d969e0b4ca0 | 18 | float AnalogScalingFactor; |
Blaze513 | 0:3d969e0b4ca0 | 19 | char Workspace[4]; |
Blaze513 | 0:3d969e0b4ca0 | 20 | |
Blaze513 | 0:3d969e0b4ca0 | 21 | public: |
Blaze513 | 0:3d969e0b4ca0 | 22 | MB1210(PinName pw, PinName an, PinName tx, PinName rx); |
Blaze513 | 0:3d969e0b4ca0 | 23 | //pulse width modulation input, analog input, serial output, serial input; |
Blaze513 | 0:3d969e0b4ca0 | 24 | //specify NC if pin is not used |
Blaze513 | 0:3d969e0b4ca0 | 25 | ~MB1210(); |
Blaze513 | 0:3d969e0b4ca0 | 26 | //deallocates PwmInput, AnalogInput, SerialOutput, and SerailInput |
Blaze513 | 0:3d969e0b4ca0 | 27 | void SoundVelocity(float MetersPerSecond); |
Blaze513 | 0:3d969e0b4ca0 | 28 | //if, for some reason, you need to correct the speed of sound |
Blaze513 | 0:3d969e0b4ca0 | 29 | //for Pwm modes, enter the new value here in meters per second; |
Blaze513 | 0:3d969e0b4ca0 | 30 | //default is 340.29 m/s |
Blaze513 | 0:3d969e0b4ca0 | 31 | //Note: most accurate mode |
Blaze513 | 0:3d969e0b4ca0 | 32 | void Voltage(float Volts); |
Blaze513 | 0:3d969e0b4ca0 | 33 | //sets expected operating voltage for Analog modes; |
Blaze513 | 0:3d969e0b4ca0 | 34 | //user responsibility to ensure operating voltage between 3.3 V and 5 V; |
Blaze513 | 0:3d969e0b4ca0 | 35 | //default is 3.3 V |
Blaze513 | 0:3d969e0b4ca0 | 36 | void Unit(float UnitsPerMeter); |
Blaze513 | 0:3d969e0b4ca0 | 37 | //argument sets the putput units through multiplication; |
Blaze513 | 0:3d969e0b4ca0 | 38 | //default is cm |
Blaze513 | 0:3d969e0b4ca0 | 39 | void Mode(char Selection); |
Blaze513 | 0:3d969e0b4ca0 | 40 | //argument sets operating mode; |
Blaze513 | 0:3d969e0b4ca0 | 41 | //0 to 2 for synchronous modes, 4 to 6 for asynchronous modes; |
Blaze513 | 0:3d969e0b4ca0 | 42 | //0 and 4 for pwm, 1 and 5 for analog, 2 and 6 for serial; |
Blaze513 | 0:3d969e0b4ca0 | 43 | //default is 0 |
Blaze513 | 0:3d969e0b4ca0 | 44 | void RequestSyncRead(); |
Blaze513 | 0:3d969e0b4ca0 | 45 | //this tells the device to prepare a synchronous range reading; |
Blaze513 | 0:3d969e0b4ca0 | 46 | //must be called at least 99 ms before the reading is needed; |
Blaze513 | 0:3d969e0b4ca0 | 47 | //changes asynchronous mode to synchronous equivalent |
Blaze513 | 0:3d969e0b4ca0 | 48 | void DiscardBuffer(); |
Blaze513 | 0:3d969e0b4ca0 | 49 | //empties the buffer on the serial port to sync the next reading |
Blaze513 | 0:3d969e0b4ca0 | 50 | float Read(); |
Blaze513 | 0:3d969e0b4ca0 | 51 | //get a reading from the device in the set mode; |
Blaze513 | 0:3d969e0b4ca0 | 52 | //RequestSyncRead() must be called at least 99 ms |
Blaze513 | 0:3d969e0b4ca0 | 53 | //before this method can be called in a synchronous mode; |
Blaze513 | 0:3d969e0b4ca0 | 54 | //may be called at any time during asynchronous mode; |
Blaze513 | 0:3d969e0b4ca0 | 55 | void Read(char* Buffer); |
Blaze513 | 0:3d969e0b4ca0 | 56 | //overloaded to take advantage of Serial ASCII string output; |
Blaze513 | 0:3d969e0b4ca0 | 57 | //Buffer must be 3 bytes; 3 digit ASCII number |
Blaze513 | 0:3d969e0b4ca0 | 58 | //measures range in cm regardless of selected unit; |
Blaze513 | 0:3d969e0b4ca0 | 59 | //uses serial input method regardless of selected mode. |
Blaze513 | 0:3d969e0b4ca0 | 60 | operator float(); |
Blaze513 | 0:3d969e0b4ca0 | 61 | //shorthand for taking a range reading; |
Blaze513 | 0:3d969e0b4ca0 | 62 | //ex: "float reading = MB1210Object;" |
Blaze513 | 0:3d969e0b4ca0 | 63 | }; |
Blaze513 | 0:3d969e0b4ca0 | 64 | |
Blaze513 | 0:3d969e0b4ca0 | 65 | #endif |