4ピン用ピング

Dependents:   CatPot_SensorRight CatPotI2CSlavetest CatPotI2CSlavetest CatPot_SensorRight_F ... more

Fork of Ping by Joel Rosiene

Files at this revision

API Documentation at this revision

Comitter:
ryuna
Date:
Sat Dec 06 07:40:50 2014 +0000
Parent:
1:6996f66161d7
Commit message:
using catpot . rakuraku;

Changed in this revision

Ping.cpp Show annotated file Show diff for this revision Revisions of this file
Ping.h Show annotated file Show diff for this revision Revisions of this file
diff -r 6996f66161d7 -r 6be59631152a Ping.cpp
--- a/Ping.cpp	Sat Mar 12 22:32:06 2011 +0000
+++ b/Ping.cpp	Sat Dec 06 07:40:50 2014 +0000
@@ -2,9 +2,9 @@
 
 #include "mbed.h"
 
-Ping::Ping(PinName PING_PIN)
-        : _event(PING_PIN)
-        , _cmd(PING_PIN)
+Ping::Ping(PinName Trig_PIN, PinName Echo_PIN)
+        : _event(Echo_PIN)
+        , _trig(Trig_PIN),_echo(Echo_PIN)
         , _timer()
         {
             _event.rise(this,&Ping::_Starts);
@@ -30,13 +30,11 @@
 void Ping::Send()
 {
      
-     _cmd.output();
-     _cmd.write(0);  // see the ping documentation http://www.parallax.com/Portals/0/Downloads/docs/prod/acc/28015-PING-v1.6.pdf
+     _trig.write(0);  // see the ping documentation http://www.parallax.com/Portals/0/Downloads/docs/prod/acc/28015-PING-v1.6.pdf
      wait_us(3);
-     _cmd.write(1);
+     _trig.write(1);
      wait_us(3);
-     _cmd.write(0);
-     _cmd.input();
+     _trig.write(0);
      
 }
 void Ping::Set_Speed_of_Sound(int SoS_ms )
@@ -48,7 +46,7 @@
 // -1 means not valid.
 {
     if(_Valid && ~_Busy) 
-        return ((_Time*_SPEED_OF_SOUND_CM)/1000);
+        return ((_Time*_SPEED_OF_SOUND_CM)/1000/2);
     else 
         return -1;
 }
\ No newline at end of file
diff -r 6996f66161d7 -r 6be59631152a Ping.h
--- a/Ping.h	Sat Mar 12 22:32:06 2011 +0000
+++ b/Ping.h	Sat Dec 06 07:40:50 2014 +0000
@@ -53,7 +53,7 @@
     *
     * @param PING_PIN InterruptIn pin to connect to 
     */
-    Ping(PinName PING_PIN);
+    Ping(PinName Trig_PIN,PinName Echo_PIN);
     
      /** Sends a Ping 
       *
@@ -76,7 +76,8 @@
   protected:
     
     InterruptIn     _event;
-    DigitalInOut    _cmd;
+    DigitalOut      _trig;
+    DigitalIn       _echo;
     Timer           _timer;
 
     bool _Valid;