Works with the parallax ping sensor. Uses a timer and interrupts to get the time and calculate the distance

Dependents:   Wifly_TCPEchoServer_Sensors ROBOT_v01 ROBOT_v02 mbed_blinky ... more

Embed: (wiki syntax)

« Back to documentation index

Ping Class Reference

Ping Class Reference

Ping class, based on an InterruptIn pin, and a timer works with the parallax Ping))) sensor (www.parallax.com) More...

#include <Ping.h>

Public Member Functions

 Ping (PinName PING_PIN)
 Create a Ping object connected to the specified InterruptIn pin.
void Send (void)
 Sends a Ping.
void Set_Speed_of_Sound (int SoS_ms)
 Set the speed of sound, default 33 cm/ms.
int Read_cm (void)
 Read the result in centimeters.

Detailed Description

Ping class, based on an InterruptIn pin, and a timer works with the parallax Ping))) sensor (www.parallax.com)

Example:

 // Continuously send pings and read the sensor
 #include "mbed.h"
 #include "Ping.h"
 
 Ping Pinger(p21);
 
 int main() {
     int range;
 
     while(1) {
  
        Pinger.Send();    
        wait_ms(30);
        range = Pinger.Read_cm();
     }
 }

Definition at line 50 of file Ping.h.


Constructor & Destructor Documentation

Ping ( PinName  PING_PIN )

Create a Ping object connected to the specified InterruptIn pin.

Parameters:
PING_PINInterruptIn pin to connect to

Definition at line 5 of file Ping.cpp.


Member Function Documentation

int Read_cm ( void   )

Read the result in centimeters.

Parameters:
none

Definition at line 47 of file Ping.cpp.

void Send ( void   )

Sends a Ping.

Parameters:
none

Definition at line 30 of file Ping.cpp.

void Set_Speed_of_Sound ( int  SoS_ms )

Set the speed of sound, default 33 cm/ms.

Parameters:
Speedof sound in centimeters per milliseconds

Definition at line 42 of file Ping.cpp.