-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFSR.cpp
More file actions
34 lines (31 loc) · 770 Bytes
/
FSR.cpp
File metadata and controls
34 lines (31 loc) · 770 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
#include "FSR.h"
#include <Arduino.h>
/**
* FSR constructor.<BR>
* pin- Analog pin required.
*/
FSR::FSR(const int pin) : AnalogReader(pin), Vcc(5), res(3300)
{
pinMode(pin, INPUT);
}
/**
* Get the resistance (in Ohms) of the sensor.
*/
float FSR::getResistance()
{
float senVoltage = read() * Vcc / 1023;
return res * (Vcc / senVoltage - 1);
}
/**
* Converte resistance to force using curve from data sheet [in grams/cm^2].<BR>
* Return value ranges 100g/cm^2 to 10Kg/cm^2.
*/
float FSR::getForce()
{
float resistance = getResistance();
//calculate force using curve broken into two parts of different slope
if (resistance <= 600)
return (1.0 / resistance - 0.00075) / 0.00000032639;
else
return (1.0 / resistance) / 0.000000642857;
}