Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
MB1210.h
00001 //mbed Microcontroller Library 00002 //Max Botix Ultrasonic Range Finder MB1210 Interface 00003 //Copyright 2010 00004 //Thomas Hamilton 00005 00006 #ifndef MB1210Library 00007 #define MB1210Library 00008 00009 #include "mbed.h" 00010 #include "PwmIn.h" 00011 00012 class MB1210 00013 { 00014 private: 00015 PwmIn* PwmInput; 00016 AnalogIn* AnalogInput; 00017 DigitalOut* SerialOutput; 00018 Serial* SerialInput; 00019 00020 char OperatingMode; 00021 float UnitFactor; 00022 float PwmScalingFactor; 00023 float AnalogScalingFactor; 00024 float Range; 00025 float* InterruptBuffer; 00026 00027 void Interrupt(); 00028 00029 public: 00030 MB1210(PinName pw, PinName an, PinName tx, PinName rx); 00031 //pulse width modulation input, analog input, serial output, serial input; 00032 //specify NC if pin is not used; 00033 //if the pulse width pin is used, interrupts will perform a 00034 //few microseconds of calculations every time a reading is taken 00035 ~MB1210(); 00036 //deallocates PwmInput, AnalogInput, SerialOutput, and SerailInput 00037 void SoundVelocity(float MetersPerSecond); 00038 //if, for some reason, you need to correct the speed of sound 00039 //for Pwm modes, enter the new value here in meters per second; 00040 //default is 340.29 m/s 00041 //Note: most accurate mode 00042 void Voltage(float Volts); 00043 //sets expected operating voltage for Analog modes; 00044 //user responsibility to ensure operating voltage between 3.3 V and 5 V; 00045 //default is 3.3 V 00046 void Unit(float UnitsPerMeter); 00047 //argument sets the putput units through multiplication; 00048 //default is cm 00049 void Mode(char Selection); 00050 //argument sets operating mode; 00051 //set flag 0x08 to 0 for polled modes, or 1 for interrupt modes; 00052 //set flag 0x04 to 0 for synchronous modes, or 1 for asynchronous modes; 00053 //set flags 0x03 to 0 for pwm, 1 for analog, or 2 for serial; 00054 //asynchronous modes generate pulse width interrupts, prepare an 00055 //analog reading, and send a 5 byte serial reading every 99 ms; 00056 //interrupt modes automatically read the range into the buffer provided 00057 //by AttachInterruptBuffer with the selected input method every 99 ms 00058 //if in an asynchronous mode, or 99 ms after RequestSyncRead is called; 00059 //the rx pin must be connected to use an interrupt mode; 00060 //the tx pin must be connected to use a synchronous mode; 00061 //default is 0 00062 void AttachInterruptBuffer(float* Buffer); 00063 //if interrupts are used, user must provide address to write result to 00064 void RequestSyncRead(); 00065 //this tells the device to prepare a synchronous range reading; 00066 //must be called at least 99 ms before the reading is needed; 00067 //changes asynchronous mode to synchronous equivalent 00068 void DiscardSerialBuffer(); 00069 //the serial port has a buffer and only the oldest data is read from it; 00070 //the buffer has limited space and, when full, the newest data is discarded; 00071 //this method allows the user to empty the buffer of old data so new data is used 00072 float Read(); 00073 //get a reading from the device in the set mode; 00074 //RequestSyncRead() must be called at least 99 ms 00075 //before this method can be called in a synchronous mode; 00076 //may be called at any time during asynchronous mode; 00077 operator float(); 00078 //shorthand for taking a range reading; 00079 //ex: "float reading = MB1210Object;" 00080 }; 00081 00082 #endif
Generated on Thu Jul 14 2022 10:11:24 by
1.7.2