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

#include <GP2Y0A21.hpp>

Inheritance diagram for GP2Y0A21:
Inheritance graph
Collaboration diagram for GP2Y0A21:
Collaboration graph

Public Member Functions

 GP2Y0A21 (Runtime &runtime, uint8_t pin)
 Constructs a GP2Y0A21 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 GP2Y0A21 infrared sensor. It can measure distances between 12 and 78 centimeters.

Definition at line 11 of file GP2Y0A21.hpp.

Constructor & Destructor Documentation

◆ GP2Y0A21()

GP2Y0A21::GP2Y0A21 ( Runtime runtime,
uint8_t  pin 
)

Constructs a GP2Y0A21 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;
GP2Y0A21 infraredSensor(arduinoRuntime, IR_PIN);

Definition at line 9 of file GP2Y0A21.cpp.

Member Function Documentation

◆ getDistance()

unsigned int GP2Y0A21::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 GP2Y0A21.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
GP2Y0A21
Definition: GP2Y0A21.hpp:11