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.
Fork of FSR by
FSR.cpp@6:71a6328709ea, 2017-05-03 (annotated)
- Committer:
- jd0205
- Date:
- Wed May 03 21:01:09 2017 +0000
- Revision:
- 6:71a6328709ea
- Parent:
- 2:3a5f5cc5b35c
Just personal changes
Who changed what in which revision?
| User | Revision | Line number | New contents of line |
|---|---|---|---|
| cshao06 | 0:d24a38523990 | 1 | #include "FSR.h" |
| cshao06 | 0:d24a38523990 | 2 | #include "mbed.h" |
| cshao06 | 0:d24a38523990 | 3 | |
| cshao06 | 0:d24a38523990 | 4 | FSR::FSR(PinName pin, float resistance) : _ain(pin), _r(resistance) |
| cshao06 | 0:d24a38523990 | 5 | { |
| cshao06 | 0:d24a38523990 | 6 | } |
| cshao06 | 0:d24a38523990 | 7 | |
| cshao06 | 0:d24a38523990 | 8 | float FSR::readRaw() |
| cshao06 | 0:d24a38523990 | 9 | { |
| cshao06 | 0:d24a38523990 | 10 | float read = _ain; |
| cshao06 | 0:d24a38523990 | 11 | return read; |
| cshao06 | 0:d24a38523990 | 12 | } |
| cshao06 | 0:d24a38523990 | 13 | |
| cshao06 | 0:d24a38523990 | 14 | float FSR::readFSRResistance() |
| cshao06 | 0:d24a38523990 | 15 | { |
| cshao06 | 0:d24a38523990 | 16 | float read = _ain; |
| jd0205 | 6:71a6328709ea | 17 | return _r * (1 - read) / read; |
| cshao06 | 0:d24a38523990 | 18 | } |
| cshao06 | 0:d24a38523990 | 19 | |
| cshao06 | 0:d24a38523990 | 20 | float FSR::readWeight() |
| cshao06 | 0:d24a38523990 | 21 | { |
| cshao06 | 0:d24a38523990 | 22 | float read = _ain; |
| jd0205 | 6:71a6328709ea | 23 | float rfsr = _r * (1 - read) / read; |
| cshao06 | 0:d24a38523990 | 24 | float slope = (4 - 2) / (log10(6.2) - log10(0.25)); |
| cshao06 | 0:d24a38523990 | 25 | float a = log10(rfsr); |
| cshao06 | 0:d24a38523990 | 26 | if (a < log10(6.2)) |
| cshao06 | 0:d24a38523990 | 27 | { |
| cshao06 | 0:d24a38523990 | 28 | return pow(10, ((log10(6.2) - a) * slope + 2)); |
| cshao06 | 0:d24a38523990 | 29 | } |
| cshao06 | 0:d24a38523990 | 30 | else |
| cshao06 | 0:d24a38523990 | 31 | { |
| cshao06 | 0:d24a38523990 | 32 | return 0; |
| cshao06 | 0:d24a38523990 | 33 | } |
| cshao06 | 0:d24a38523990 | 34 | } |
