Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Diff: FSR.cpp
- Revision:
- 0:d24a38523990
- Child:
- 1:6b702226a5d3
diff -r 000000000000 -r d24a38523990 FSR.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/FSR.cpp Wed Oct 21 21:14:06 2015 +0000 @@ -0,0 +1,34 @@ +#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; + return _r * 3.3 / read - _r; +} + +float FSR::readWeight() +{ + float read = _ain; + float rfsr = _r * 3.3 / 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; + } +} \ No newline at end of file