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.

Dependencies:   mbed

Committer:
Blaze513
Date:
Thu Aug 26 18:25:19 2010 +0000
Revision:
3:05183e50a923
Parent:
2:997b4057c879
Child:
4:a615b75d4126

        

Who changed what in which revision?

UserRevisionLine numberNew contents of line
Blaze513 2:997b4057c879 1 //mbed Microcontroller Library
Blaze513 2:997b4057c879 2 //Max Botix Ultrasonic Range Finder MB1210 Interface
Blaze513 2:997b4057c879 3 //Copyright 2010
Blaze513 2:997b4057c879 4 //Thomas Hamilton
Blaze513 2:997b4057c879 5
Blaze513 0:3d969e0b4ca0 6 #ifndef MB1210Library
Blaze513 0:3d969e0b4ca0 7 #define MB1210Library
Blaze513 0:3d969e0b4ca0 8
Blaze513 0:3d969e0b4ca0 9 #include "mbed.h"
Blaze513 0:3d969e0b4ca0 10 #include "PwmIn.h"
Blaze513 0:3d969e0b4ca0 11
Blaze513 0:3d969e0b4ca0 12 class MB1210
Blaze513 0:3d969e0b4ca0 13 {
Blaze513 0:3d969e0b4ca0 14 private:
Blaze513 0:3d969e0b4ca0 15 PwmIn* PwmInput;
Blaze513 0:3d969e0b4ca0 16 AnalogIn* AnalogInput;
Blaze513 0:3d969e0b4ca0 17 DigitalOut* SerialOutput;
Blaze513 0:3d969e0b4ca0 18 Serial* SerialInput;
Blaze513 2:997b4057c879 19
Blaze513 0:3d969e0b4ca0 20 char OperatingMode;
Blaze513 0:3d969e0b4ca0 21 float UnitFactor;
Blaze513 0:3d969e0b4ca0 22 float PwmScalingFactor;
Blaze513 0:3d969e0b4ca0 23 float AnalogScalingFactor;
Blaze513 1:b533b95e807a 24 unsigned short Range;
Blaze513 2:997b4057c879 25
Blaze513 0:3d969e0b4ca0 26 public:
Blaze513 0:3d969e0b4ca0 27 MB1210(PinName pw, PinName an, PinName tx, PinName rx);
Blaze513 0:3d969e0b4ca0 28 //pulse width modulation input, analog input, serial output, serial input;
Blaze513 0:3d969e0b4ca0 29 //specify NC if pin is not used
Blaze513 0:3d969e0b4ca0 30 ~MB1210();
Blaze513 0:3d969e0b4ca0 31 //deallocates PwmInput, AnalogInput, SerialOutput, and SerailInput
Blaze513 0:3d969e0b4ca0 32 void SoundVelocity(float MetersPerSecond);
Blaze513 0:3d969e0b4ca0 33 //if, for some reason, you need to correct the speed of sound
Blaze513 0:3d969e0b4ca0 34 //for Pwm modes, enter the new value here in meters per second;
Blaze513 0:3d969e0b4ca0 35 //default is 340.29 m/s
Blaze513 0:3d969e0b4ca0 36 //Note: most accurate mode
Blaze513 0:3d969e0b4ca0 37 void Voltage(float Volts);
Blaze513 0:3d969e0b4ca0 38 //sets expected operating voltage for Analog modes;
Blaze513 0:3d969e0b4ca0 39 //user responsibility to ensure operating voltage between 3.3 V and 5 V;
Blaze513 0:3d969e0b4ca0 40 //default is 3.3 V
Blaze513 0:3d969e0b4ca0 41 void Unit(float UnitsPerMeter);
Blaze513 0:3d969e0b4ca0 42 //argument sets the putput units through multiplication;
Blaze513 0:3d969e0b4ca0 43 //default is cm
Blaze513 0:3d969e0b4ca0 44 void Mode(char Selection);
Blaze513 0:3d969e0b4ca0 45 //argument sets operating mode;
Blaze513 0:3d969e0b4ca0 46 //0 to 2 for synchronous modes, 4 to 6 for asynchronous modes;
Blaze513 0:3d969e0b4ca0 47 //0 and 4 for pwm, 1 and 5 for analog, 2 and 6 for serial;
Blaze513 0:3d969e0b4ca0 48 //default is 0
Blaze513 0:3d969e0b4ca0 49 void RequestSyncRead();
Blaze513 0:3d969e0b4ca0 50 //this tells the device to prepare a synchronous range reading;
Blaze513 0:3d969e0b4ca0 51 //must be called at least 99 ms before the reading is needed;
Blaze513 0:3d969e0b4ca0 52 //changes asynchronous mode to synchronous equivalent
Blaze513 3:05183e50a923 53 void DiscardSerialBuffer();
Blaze513 3:05183e50a923 54 //the serial port has a buffer and only the oldest data is read from it;
Blaze513 3:05183e50a923 55 //the buffer has limited space and, when full, the newest data is discarded;
Blaze513 3:05183e50a923 56 //this method allows the user to empty the buffer of old data so new data is used
Blaze513 0:3d969e0b4ca0 57 float Read();
Blaze513 0:3d969e0b4ca0 58 //get a reading from the device in the set mode;
Blaze513 0:3d969e0b4ca0 59 //RequestSyncRead() must be called at least 99 ms
Blaze513 0:3d969e0b4ca0 60 //before this method can be called in a synchronous mode;
Blaze513 0:3d969e0b4ca0 61 //may be called at any time during asynchronous mode;
Blaze513 0:3d969e0b4ca0 62 void Read(char* Buffer);
Blaze513 0:3d969e0b4ca0 63 //overloaded to take advantage of Serial ASCII string output;
Blaze513 0:3d969e0b4ca0 64 //Buffer must be 3 bytes; 3 digit ASCII number
Blaze513 0:3d969e0b4ca0 65 //measures range in cm regardless of selected unit;
Blaze513 0:3d969e0b4ca0 66 //uses serial input method regardless of selected mode.
Blaze513 0:3d969e0b4ca0 67 operator float();
Blaze513 0:3d969e0b4ca0 68 //shorthand for taking a range reading;
Blaze513 0:3d969e0b4ca0 69 //ex: "float reading = MB1210Object;"
Blaze513 0:3d969e0b4ca0 70 };
Blaze513 0:3d969e0b4ca0 71
Blaze513 0:3d969e0b4ca0 72 #endif