4ピン用ピング
Dependents: CatPot_SensorRight CatPotI2CSlavetest CatPotI2CSlavetest CatPot_SensorRight_F ... more
Fork of Ping by
Diff: Ping.cpp
- Revision:
- 2:6be59631152a
- Parent:
- 0:1e4b66122368
--- 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