personal changes
Fork of FSR by
FSR.h@6:71a6328709ea, 2017-05-03 (annotated)
- Committer:
- jd0205
- Date:
- Wed May 03 21:01:09 2017 +0000
- Revision:
- 6:71a6328709ea
- Parent:
- 5:d9520bf7eb9e
Just personal changes
Who changed what in which revision?
| User | Revision | Line number | New contents of line |
|---|---|---|---|
| cshao06 | 0:d24a38523990 | 1 | #ifndef FSR_H |
| cshao06 | 0:d24a38523990 | 2 | #define FSR_H |
| cshao06 | 0:d24a38523990 | 3 | |
| cshao06 | 0:d24a38523990 | 4 | #include "mbed.h" |
| cshao06 | 0:d24a38523990 | 5 | |
| cshao06 | 0:d24a38523990 | 6 | /** Force sensitive resistor class using an AnalogIn pin |
| cshao06 | 0:d24a38523990 | 7 | * |
| cshao06 | 0:d24a38523990 | 8 | * Example: |
| cshao06 | 0:d24a38523990 | 9 | * @code |
| cshao06 | 0:d24a38523990 | 10 | * #include "mbed.h" |
| cshao06 | 0:d24a38523990 | 11 | * #include "FSR.h" |
| cshao06 | 5:d9520bf7eb9e | 12 | * FSR fsr(p20, 10); // Pin 20 is used as the AnalogIn pin and a 10k resistor is used as a voltage divider |
| cshao06 | 0:d24a38523990 | 13 | * int main(){ |
| cshao06 | 0:d24a38523990 | 14 | * while (1) |
| cshao06 | 0:d24a38523990 | 15 | * { |
| cshao06 | 0:d24a38523990 | 16 | * printf("The raw data is %f\n", fsr.readRaw()); |
| cshao06 | 0:d24a38523990 | 17 | * printf("The resistance of the FSR is %f\n", fsr.readFSRResistance()); |
| cshao06 | 0:d24a38523990 | 18 | * printf("The weight on the FSR is %f\n\n", fsr.readWeight()); |
| cshao06 | 0:d24a38523990 | 19 | * wait(0.3); //just here to slow down the output for easier reading |
| cshao06 | 0:d24a38523990 | 20 | * } |
| cshao06 | 0:d24a38523990 | 21 | * } |
| cshao06 | 0:d24a38523990 | 22 | * @endcode |
| cshao06 | 0:d24a38523990 | 23 | */ |
| cshao06 | 0:d24a38523990 | 24 | |
| cshao06 | 0:d24a38523990 | 25 | class FSR |
| cshao06 | 0:d24a38523990 | 26 | { |
| cshao06 | 0:d24a38523990 | 27 | public: |
| cshao06 | 0:d24a38523990 | 28 | /** Create an FSR object |
| cshao06 | 0:d24a38523990 | 29 | * |
| cshao06 | 3:6fc368701789 | 30 | * @param Pin AnalogIn pin number |
| cshao06 | 3:6fc368701789 | 31 | * @param resistance resistance of the voltage divider resistor in k |
| cshao06 | 0:d24a38523990 | 32 | */ |
| cshao06 | 0:d24a38523990 | 33 | FSR(PinName Pin, float resistance); |
| cshao06 | 0:d24a38523990 | 34 | |
| cshao06 | 0:d24a38523990 | 35 | /** Read the raw data |
| cshao06 | 0:d24a38523990 | 36 | * |
| cshao06 | 0:d24a38523990 | 37 | * @return the raw float data ranging from 0 to 1 |
| cshao06 | 0:d24a38523990 | 38 | */ |
| cshao06 | 0:d24a38523990 | 39 | float readRaw(); |
| cshao06 | 0:d24a38523990 | 40 | |
| cshao06 | 0:d24a38523990 | 41 | /** Read the resistance of the FSR |
| cshao06 | 0:d24a38523990 | 42 | * |
| cshao06 | 0:d24a38523990 | 43 | * @return the resistance of the FSR |
| cshao06 | 0:d24a38523990 | 44 | */ |
| cshao06 | 0:d24a38523990 | 45 | float readFSRResistance(); |
| cshao06 | 0:d24a38523990 | 46 | |
| cshao06 | 0:d24a38523990 | 47 | /** Read the weight in N. 0 anyway if the weight is less than 100g |
| cshao06 | 0:d24a38523990 | 48 | * |
| cshao06 | 0:d24a38523990 | 49 | * @return the weight ranging from 100g to 10000g |
| cshao06 | 0:d24a38523990 | 50 | */ |
| cshao06 | 0:d24a38523990 | 51 | float readWeight(); |
| cshao06 | 0:d24a38523990 | 52 | protected: |
| cshao06 | 0:d24a38523990 | 53 | AnalogIn _ain; |
| cshao06 | 0:d24a38523990 | 54 | float _r; |
| cshao06 | 0:d24a38523990 | 55 | }; |
| cshao06 | 0:d24a38523990 | 56 | |
| cshao06 | 0:d24a38523990 | 57 | #endif |
