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.
Fork of IEEE_14_Freescale by
Diff: hcsr04.h
- Revision:
 - 15:b10859606504
 - Parent:
 - 14:a30aa3b29a2e
 - Child:
 - 31:4ef53fbd6759
 
--- a/hcsr04.h	Fri Mar 07 21:49:22 2014 +0000
+++ b/hcsr04.h	Tue Mar 11 19:58:31 2014 +0000
@@ -3,12 +3,11 @@
 //  ECE 510 Embedded Systems, Roy Kravitz
 //
 // HCSR04 ultrasonic sensor class using interrupts and allowing multiple instances.
-// You can use the same trigger pin for multiple instances, the echo is received and 
-// measurement calculated based on the echo input alone (when the echo signal goes high
-// the timer is started, when the echo signal goes low the timer value in microseconds
-// is saved as the length, and the timer is stopped and reset.  Length calculation is done
-// when the length is requested (either inches or centimeters) using the appropriate
-// function. 
+// You can use the same trigger pin for multiple instances; the echo is received and 
+// measurement calculated based on the echo input alone. (when the echo signal goes high,
+// the timer is started. When the echo signal goes low, the timer value in microseconds
+// is saved as the length, and the timer is stopped and reset) Length calculation is done
+// when the length is requested (either inches or centimeters). 
 
 #ifndef MBED_HCSR04_H
 #define MBED_HCSR04_H
@@ -23,8 +22,8 @@
 class hcsr04 {
 
 private:
-    InterruptIn *_echo_int;                        // pin to receive echo signal
-    DigitalOut trigger_out;                    // pin to send the trigger signal
+    InterruptIn *_echo_int;                        // pin to receive echo signal; input
+    DigitalOut trigger_out;                    // pin to send the trigger signal; output
     Timer timer;                            // timer to track length of pulse
     float value;                            // to store the last pulse length        
 
@@ -32,9 +31,9 @@
     bool measuring;                         // true while the echo signal is high (measurement in progress)
     hcsr04(PinName trigger, PinName echo) : trigger_out(trigger) { // _pass the names to the pin configuration                                                   
         //trigger_out = new DigitalOut( trigger );
-        _echo_int = new InterruptIn( echo );
-        _echo_int->rise(this, &hcsr04::timer_start);
-        _echo_int->fall(this, &hcsr04::calc_measurement);
+        _echo_int = new InterruptIn( echo );                // interrupts
+        _echo_int->rise(this, &hcsr04::timer_start);        // when trigger is sent
+        _echo_int->fall(this, &hcsr04::calc_measurement);   // when echo is received
         measuring = false;
     }
 
@@ -65,8 +64,9 @@
         return value / CM_DIVISOR;
     }
         
-    /* void pulse(void) {  // Rohan's code
-        trigger();
+    /* void hscr04_main(void) {  // Rohan's code
+        //trigger();
+        // delay
         while(measuring == false);
         // interrupts call timer_start() and calc_measurement()
     }
    