Ram Gandikota / FSR

Dependents:   K64F-RTOS-MQTT-Example

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     //float* obj=new float;
00018     //obj=(_r * 1 / read - _r);
00019     //return obj;
00020     float t=(_r * 1 / read - _r);
00021     return &t;
00022 }
00023 
00024 float FSR::readWeight()
00025 {
00026     float read = _ain;
00027     float rfsr = _r * 1 / read - _r;
00028     float slope = (4 - 2) / (log10(6.2) - log10(0.25));
00029     float a = log10(rfsr);
00030     if (a < log10(6.2))
00031     {
00032         return pow(10, ((log10(6.2) - a) * slope + 2));
00033     }
00034     else
00035     {
00036         return 0;
00037     }
00038 }