Driver for HC-SR04 connected to a Microbit

Files at this revision

API Documentation at this revision

Comitter:
isaeldiaz@developer.mbed.org
Date:
Tue Oct 04 21:21:19 2016 +0200
Parent:
17:a82fb8fc4ca3
Commit message:
small adjustments to library, the echo function does not attach to the InterruptIn class, not sure why

Changed in this revision

MicrobitUltrasound.cpp Show annotated file Show diff for this revision Revisions of this file
MicrobitUltrasound.h Show annotated file Show diff for this revision Revisions of this file
--- a/MicrobitUltrasound.cpp	Fri Sep 16 22:30:47 2016 +0200
+++ b/MicrobitUltrasound.cpp	Tue Oct 04 21:21:19 2016 +0200
@@ -57,7 +57,7 @@
 
   echo.mode(echoPinMode);
   echo.rise(this, &MicrobitUltrasound::onEchoRise);
-  echo.rise(this, &MicrobitUltrasound::onEchoFall);
+  echo.fall(this, &MicrobitUltrasound::onEchoFall);
 }
 
   /**
@@ -82,9 +82,9 @@
   this->triggerDuration_us = MICROBIT_ULTRASOUND_TRIGGER_DURATION_DEFAULT_US;
   this->triggerActiveValue = TRIGGER_ACTIVE_VALUE;
 
-  echo.mode((PinMode)MICROBIT_ULTRASOUND_PULLMODE_DEFAULT);
+  //echo.mode((PinMode)MICROBIT_ULTRASOUND_PULLMODE_DEFAULT);
   echo.rise(this, &MicrobitUltrasound::onEchoRise);
-  echo.rise(this, &MicrobitUltrasound::onEchoFall);
+  echo.fall(this, &MicrobitUltrasound::onEchoFall);
 }
 
 /**
@@ -96,6 +96,14 @@
 }
 
 /**
+ * Set Echo PinMode
+ */
+void MicrobitUltrasound::setEchoPinMode(PinMode echoPinMode)
+{
+  echo.mode(echoPinMode);
+}
+
+/**
  * This member function manages the calculation of the timestamp of a pulse detected
  * on the echo pin.
  *
--- a/MicrobitUltrasound.h	Fri Sep 16 22:30:47 2016 +0200
+++ b/MicrobitUltrasound.h	Tue Oct 04 21:21:19 2016 +0200
@@ -100,7 +100,7 @@
    * MicrobitUltrasound uSoundSensor(MICROBIT_PIN_P1, 100, true, MICROBIT_PIN_P2, PullUp);
    * @endcode
    */
-  MicrobitUltrasound(PinName triggerPinName, int _triggerPeriod_ms, bool _triggerActiveValue, 
+  MicrobitUltrasound(PinName triggerPinName, int _triggerPeriod_ms, bool _triggerActiveValue,
       PinName echoPinName, PinMode echoPinMode, uint16_t id = MICROBIT_ID_ULTRASOUND);
 
   /**
@@ -117,13 +117,17 @@
    */
   MicrobitUltrasound(PinName triggerPinName, PinName echoPinName, uint16_t id = MICROBIT_ID_ULTRASOUND);
 
-
   /**
    * Destructor for MicrobitUltrasound, where we deregister this instance from the array of fiber components.
    */
   ~MicrobitUltrasound();
 
   /**
+   * Set Echo PinMode
+   */
+  void setEchoPinMode(PinMode echoPinMode);
+
+  /**
    * Set the sample rate at which the micro:bit triggers sensor (in ms).
    *
    * The default sample period is 1 second.