ProtoTracer  1.0
Real-time 3D rendering and animation engine
Loading...
Searching...
No Matches
SHARPGP2Y Class Reference

A class for managing the SHARP GP2Y distance sensor. More...

#include <SHARPGP2Y.h>

Collaboration diagram for SHARPGP2Y:

Public Member Functions

 SHARPGP2Y (uint8_t pin)
 Constructs a SHARPGP2Y instance with the specified pin.
 
float GetDistance ()
 Retrieves the current distance measurement.
 
float Update ()
 Updates the distance measurement by reading the sensor.
 

Private Member Functions

float ReadingToDistance (uint8_t reading)
 Converts a raw sensor reading to a distance value.
 

Private Attributes

RunningAverageFilter< 25 > rAF = RunningAverageFilter<25>(0.1f)
 Running average filter for smoothing sensor readings.
 
float distance = 0.0f
 Current distance measurement.
 
uint8_t pin
 Analog pin connected to the sensor.
 

Detailed Description

A class for managing the SHARP GP2Y distance sensor.

The SHARPGP2Y class provides methods for reading distance measurements from the sensor and applying filtering for noise reduction.

Definition at line 24 of file SHARPGP2Y.h.

Constructor & Destructor Documentation

◆ SHARPGP2Y()

SHARPGP2Y ( uint8_t  pin)

Constructs a SHARPGP2Y instance with the specified pin.

Parameters
pinThe analog pin connected to the SHARP GP2Y sensor.

Definition at line 3 of file SHARPGP2Y.cpp.

References pin.

Member Function Documentation

◆ GetDistance()

float GetDistance ( )

Retrieves the current distance measurement.

Returns
The current distance as a float.

Definition at line 16 of file SHARPGP2Y.cpp.

References distance.

◆ ReadingToDistance()

float ReadingToDistance ( uint8_t  reading)
private

Converts a raw sensor reading to a distance value.

Parameters
readingThe raw analog reading from the sensor.
Returns
The calculated distance in appropriate units (e.g., cm).

Definition at line 7 of file SHARPGP2Y.cpp.

Referenced by Update().

◆ Update()

float Update ( )

Updates the distance measurement by reading the sensor.

Returns
The updated distance as a float.

Definition at line 20 of file SHARPGP2Y.cpp.

References distance, RunningAverageFilter< memory >::Filter(), pin, rAF, and ReadingToDistance().

Referenced by GammaAnimation::Update().

Member Data Documentation

◆ distance

float distance = 0.0f
private

Current distance measurement.

Definition at line 27 of file SHARPGP2Y.h.

Referenced by GetDistance(), and Update().

◆ pin

uint8_t pin
private

Analog pin connected to the sensor.

Definition at line 28 of file SHARPGP2Y.h.

Referenced by SHARPGP2Y(), and Update().

◆ rAF

RunningAverageFilter<25> rAF = RunningAverageFilter<25>(0.1f)
private

Running average filter for smoothing sensor readings.

Definition at line 26 of file SHARPGP2Y.h.

Referenced by Update().


The documentation for this class was generated from the following files: