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

Files at this revision

API Documentation at this revision

Comitter:
Blaze513
Date:
Thu Aug 26 18:25:19 2010 +0000
Parent:
2:997b4057c879
Child:
4:a615b75d4126
Commit message:

Changed in this revision

MB1210.cpp Show annotated file Show diff for this revision Revisions of this file
MB1210.h Show annotated file Show diff for this revision Revisions of this file
PwmIn/PwmIn.cpp Show annotated file Show diff for this revision Revisions of this file
--- a/MB1210.cpp	Mon Aug 23 07:11:10 2010 +0000
+++ b/MB1210.cpp	Thu Aug 26 18:25:19 2010 +0000
@@ -85,6 +85,15 @@
 }
     //hold pin high for at least 20 us to request a synchronous range reading
 
+void MB1210::DiscardSerialBuffer()
+{
+    while (SerialInput->readable())
+    {
+        SerialInput->getc();
+    }
+}
+    //read characters from the buffer until it is empty
+
 float MB1210::Read()
 {
     switch (OperatingMode)
@@ -127,7 +136,7 @@
     }
 }
     //OperatingMode switches to desired output method;
-    //once gathered, the result is scaled according to voltage, the speed of sound, and desired unit
+    //the result is scaled according to voltage, the speed of sound, and desired unit
 void MB1210::Read(char* Buffer)
 {
     if (SerialInput)
--- a/MB1210.h	Mon Aug 23 07:11:10 2010 +0000
+++ b/MB1210.h	Thu Aug 26 18:25:19 2010 +0000
@@ -50,8 +50,10 @@
             //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
+        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
--- a/PwmIn/PwmIn.cpp	Mon Aug 23 07:11:10 2010 +0000
+++ b/PwmIn/PwmIn.cpp	Thu Aug 26 18:25:19 2010 +0000
@@ -7,9 +7,10 @@
 
 PwmIn::PwmIn(PinName pwi) : InterruptIn(pwi), PeriodMeasurement(0), PulseWidthMeasurement(1)
 {
-        rise(this, &PwmIn::PulseStart);
-        fall(this, &PwmIn::PulseStop);
-        start();
+    mode(PullDown);
+    rise(this, &PwmIn::PulseStart);
+    fall(this, &PwmIn::PulseStop);
+    start();
 }
 
 float PwmIn::read()