Mike Spadaru / physcom
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 in order to measure the distance to an object that is in front of the ultrasound sensor.
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 "physcom.h"

 using namespace physcom;
 
 Ping Pinger(p21);
 
 int main() {
     int range;
 
     while(1) {
  
        Pinger.Send();    
        wait_ms(30);
        range = Pinger.Read_cm();
     }
 }

Definition at line 55 of file ping.h.


Constructor & Destructor Documentation

Ping ( PinName  PING_PIN )

Create a Ping object connected to the specified InterruptIn pin.

Parameters:
PING_PINMbed Pin connected to the ultrasound sensor. Can be any Digital Input Pin. Example: p21

Definition at line 6 of file ping.cpp.


Member Function Documentation

int Read_cm ( void   )

Read the result in centimeters.

Parameters:
none
Returns:
distance in centimeters

Definition at line 48 of file ping.cpp.

void Send ( void   )

Sends a ping in order to measure the distance to an object that is in front of the ultrasound sensor.

This distance can be read using the Read_cm function.

Definition at line 31 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 43 of file ping.cpp.