EV3RT CXX API Reference [English]
An RTOS-based development platform for LEGO Mindstorms EV3.
ev3cxx_ultrasonic_sensor.h
Go to the documentation of this file.
1 
7 #pragma once
8 
9 #include <stdio.h>
10 
11 #include "ev3api.h"
12 #include "ev3cxx_sensor.h"
13 
14 namespace ev3cxx {
15 
20 class UltrasonicSensor : public Sensor
21 {
22 public:
28  UltrasonicSensor(SensorPort port) : Sensor(port, ULTRASONIC_SENSOR) {
29  centimeters(); // By read one value immediate activate the sensor
30  }
31 
37  int centimeters() {
38  return ev3_ultrasonic_sensor_get_distance(m_port);
39  }
40 
46  int millimeters() {
47  return ev3_ultrasonic_sensor_get_raw_data(m_port, US_DIST_METRIC);
48  }
49 
55  int inches() {
56  return ev3_ultrasonic_sensor_get_raw_data(m_port, US_DIST_IMPERIAL) / 10;
57  }
58 
64  int inchesLine() {
65  return (ev3_ultrasonic_sensor_get_raw_data(m_port, US_DIST_IMPERIAL) * 12) / 10;
66  }
67 
68 
74  bool_t listen() {
75  return ev3_ultrasonic_sensor_listen(m_port);
76  }
77 
78 }; // class UltrasonicSensor
79 
80 
81 } // namespace ev3cxx
82 
Definition: ev3cxx.h:35
bool_t listen()
Listen and return true if catch ultrasonic signal.
Class Sensor. API for working with sensor.
Definition: ev3cxx_sensor.h:30
int millimeters()
Get millimeters in centimeters.
int inches()
Get measure distance in inches.
Class UltrasonicSensor. API for working with ultrasonic sensor.
int inchesLine()
Get measure distance in line (1/12 inch).
UltrasonicSensor(SensorPort port)
Constructor of class UltrasonicSensor.
EV3RT CPP API for sensor.
SensorPort
Enum with index of sensor port.
Definition: ev3cxx_sensor.h:19
int centimeters()
Get distance in centimeters.