Smartcar Shield
Public Member Functions | List of all members
GP2D120 Class Reference

#include <GP2D120.hpp>

Inheritance diagram for GP2D120:
Inheritance graph
Collaboration diagram for GP2D120:
Collaboration graph

Public Member Functions

 GP2D120 (Runtime &runtime, uint8_t pin)
 Constructs a GP2D120 sensor. More...
 
unsigned int getDistance () override
 Gets the distance measured by the sensor in centimeters. More...
 
- Public Member Functions inherited from InfraredAnalogSensor
 InfraredAnalogSensor (Runtime &runtime)
 
unsigned int getMedianDistance (uint8_t iterations=smartcarlib::constants::analogInfraredSensor::kDefaultIterations) override
 Gets the median distance from the specified number of measurements. More...
 
- Public Member Functions inherited from DistanceSensor
virtual ~DistanceSensor ()=default
 

Detailed Description

Programmatically represents a SHARP GP2D120 infrared sensor. It can measure distances between 5 and 25 centimeters.

Definition at line 11 of file GP2D120.hpp.

Constructor & Destructor Documentation

◆ GP2D120()

GP2D120::GP2D120 ( Runtime runtime,
uint8_t  pin 
)

Constructs a GP2D120 sensor.

Parameters
runtimeThe runtime environment you want to run the class for
pinThe analog pin receiving sensor signals

Example:

ArduinoRuntime arduinoRuntime;
const unsigned short IR_PIN = A1;
GP2D120 infraredSensor(arduinoRuntime, IR_PIN);

Definition at line 9 of file GP2D120.cpp.

Member Function Documentation

◆ getDistance()

unsigned int GP2D120::getDistance ( )
overridevirtual

Gets the distance measured by the sensor in centimeters.

Calling this might trigger a new measurement by the sensor.

Returns
0 if an error has occured, otherwise the measured distance in centimeters

Example:

unsigned int distance = sensor.getDistance();

Implements DistanceSensor.

Definition at line 16 of file GP2D120.cpp.

Here is the call graph for this function:

The documentation for this class was generated from the following files:
ArduinoRuntime
Definition: ArduinoRuntime.hpp:11
GP2D120
Definition: GP2D120.hpp:11