Lauren Alexander / FSRCookieJar

Fork of FSR by Chenkai Shao

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers FSR.cpp Source File

FSR.cpp

00001 #include "FSR.h"
00002 #include "mbed.h"
00003 
00004 FSR::FSR(PinName pin, float resistance) : _ain(pin), _r(resistance)
00005 {
00006 }
00007 
00008 float FSR::readRaw()
00009 {
00010     float read = _ain;
00011     return read;
00012 }
00013 
00014 float FSR::readFSRResistance()
00015 {
00016     float read = _ain;
00017     return _r * 1 / read - _r;
00018 }
00019 
00020 float FSR::readWeight()
00021 {
00022     float read = _ain;
00023     float rfsr = _r * 1 / read - _r;
00024     float slope = (4 - 2) / (log10(6.2) - log10(0.25));
00025     float a = log10(rfsr);
00026     return pow(10, ((log10(6.2) - a) * slope + 2));
00027     
00028     //if (a < log10(6.2))
00029 //    {
00030 //        return pow(10, ((log10(6.2) - a) * slope + 2));
00031 //    }
00032 //    else
00033 //    {
00034 //        return 0;
00035 //    }
00036 }