EV3RT CXX API Reference [English]
An RTOS-based development platform for LEGO Mindstorms EV3.
UltrasonicSensor Class Reference

Class UltrasonicSensor. API for working with ultrasonic sensor. More...

#include <ev3cxx_ultrasonic_sensor.h>

Inheritance diagram for UltrasonicSensor:
Sensor

Public Member Functions

 UltrasonicSensor (SensorPort port)
 Constructor of class UltrasonicSensor. More...
 
int centimeters ()
 Get distance in centimeters. More...
 
int millimeters ()
 Get millimeters in centimeters. More...
 
int inches ()
 Get measure distance in inches. More...
 
int inchesLine ()
 Get measure distance in line (1/12 inch). More...
 
bool_t listen ()
 Listen and return true if catch ultrasonic signal. More...
 

Additional Inherited Members

- Protected Member Functions inherited from Sensor
 Sensor (SensorPort port, sensor_type_t type)
 Constructor of class Sensor. More...
 
virtual ~Sensor ()
 Destructor of class Sensor.
 
sensor_port_t getPort ()
 Get sensor port set in constructor. More...
 
sensor_type_t getType ()
 Get actual sensor type. More...
 
- Protected Attributes inherited from Sensor
sensor_port_t m_port
 
sensor_type_t m_type
 

Detailed Description

Class UltrasonicSensor. API for working with ultrasonic sensor.

Definition at line 20 of file ev3cxx_ultrasonic_sensor.h.

Constructor & Destructor Documentation

◆ UltrasonicSensor()

UltrasonicSensor ( SensorPort  port)
inline

Constructor of class UltrasonicSensor.

Parameters
portPort index (1-4).

Definition at line 28 of file ev3cxx_ultrasonic_sensor.h.

References UltrasonicSensor::centimeters().

28  : Sensor(port, ULTRASONIC_SENSOR) {
29  centimeters(); // By read one value immediate activate the sensor
30  }
Sensor(SensorPort port, sensor_type_t type)
Constructor of class Sensor.
Definition: ev3cxx_sensor.h:38
int centimeters()
Get distance in centimeters.

Member Function Documentation

◆ centimeters()

int centimeters ( )
inline

Get distance in centimeters.

Returns
Distance in cm. Range: 3 - 255 (too near/far => 255)

Definition at line 37 of file ev3cxx_ultrasonic_sensor.h.

Referenced by UltrasonicSensor::UltrasonicSensor().

37  {
38  return ev3_ultrasonic_sensor_get_distance(m_port);
39  }

◆ inches()

int inches ( )
inline

Get measure distance in inches.

Returns
Distance in in. Range: 1 - 100 (too near/far => 100)

Definition at line 55 of file ev3cxx_ultrasonic_sensor.h.

55  {
56  return ev3_ultrasonic_sensor_get_raw_data(m_port, US_DIST_IMPERIAL) / 10;
57  }

◆ inchesLine()

int inchesLine ( )
inline

Get measure distance in line (1/12 inch).

Returns
Distance in ln. Range: 13 - 1200 (too near/far => 1200)

Definition at line 64 of file ev3cxx_ultrasonic_sensor.h.

64  {
65  return (ev3_ultrasonic_sensor_get_raw_data(m_port, US_DIST_IMPERIAL) * 12) / 10;
66  }

◆ listen()

bool_t listen ( )
inline

Listen and return true if catch ultrasonic signal.

Returns
Return true if ultrasonic signal get, else false.

Definition at line 74 of file ev3cxx_ultrasonic_sensor.h.

74  {
75  return ev3_ultrasonic_sensor_listen(m_port);
76  }

◆ millimeters()

int millimeters ( )
inline

Get millimeters in centimeters.

Returns
Distance in mm. Range: 30 - 2550 (too near/far => 2550)

Definition at line 46 of file ev3cxx_ultrasonic_sensor.h.

46  {
47  return ev3_ultrasonic_sensor_get_raw_data(m_port, US_DIST_METRIC);
48  }