Sharp GP2 familly distance sensor library

Dependents:   FRC_2018 0hackton_08_06_18 0hackton_08_06_18_publish Kenya_2019 ... more

GP2A.cpp

Committer:
haarkon
Date:
2018-05-18
Revision:
0:17de10d278c2
Child:
2:5e591a5b8edd

File content as of revision 0:17de10d278c2:

#include "GP2A.h"

GP2A::GP2A(PinName vmes, float dMin, float dMax, float slope) : _sensor(vmes)
{
    m_dMin = dMin;
    m_dMax = dMax;
    m_slope = slope;
}

float GP2A::getDistance (void)
{
    float vDist = _sensor.read()* 3.3;
    float distance = m_slope/vDist;
    if (distance > m_dMax) return m_dMax;
    if (distance < m_dMin) return m_dMin;
    return distance;
}

float GP2A::getVoltage (void)
{
    return _sensor.read()* 3.3;
}