Library to read rawdata from an FSR

Dependents:   K64F-RTOS-MQTT-Example

Fork of FSR by Chenkai Shao

FSR.cpp

Committer:
ram54288
Date:
2017-05-02
Revision:
6:bf85a85d7808
Parent:
2:3a5f5cc5b35c

File content as of revision 6:bf85a85d7808:

#include "FSR.h"
#include "mbed.h"

FSR::FSR(PinName pin, float resistance) : _ain(pin), _r(resistance)
{
}

float FSR::readRaw()
{
    float read = _ain;
    return read;
}

float* FSR::readFSRResistance()
{
    float read = _ain;
    //float* obj=new float;
    //obj=(_r * 1 / read - _r);
    //return obj;
    float t=(_r * 1 / read - _r);
    return &t;
}

float FSR::readWeight()
{
    float read = _ain;
    float rfsr = _r * 1 / read - _r;
    float slope = (4 - 2) / (log10(6.2) - log10(0.25));
    float a = log10(rfsr);
    if (a < log10(6.2))
    {
        return pow(10, ((log10(6.2) - a) * slope + 2));
    }
    else
    {
        return 0;
    }
}