-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfsr.ino
94 lines (56 loc) · 1.79 KB
/
fsr.ino
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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
int fsrPin = A0;
int fsrReading;
int fsrVoltage;
unsigned long fsrResistance;
unsigned long fsrConductance;
long fsrForce;
int batteryV;
uint16_t val = 0;
void setup() {
analogReference(INTERNAL);
pinMode(A0, INPUT);
pinMode(0, OUTPUT);
pinMode(0,HIGH);
Serial.begin(57600);
}
void loop() {
{
uint16_t batteryV = 0;
batteryV = Bean.getBatteryVoltage();
Serial.print("Battery voltage: ");
Serial.println(batteryV, DEC);
fsrReading = analogRead(fsrPin);
Serial.print("Analog reading = ");
Serial.println(fsrReading);
fsrVoltage = batteryV;
Serial.println(fsrVoltage);
if (fsrVoltage == 0)
{
Serial.println("0");
} else {
// %The voltage = Vcc * R / (R + FSR) where R = 10K and Vcc = 5V
// so FSR = ((Vcc - V) * R) / V yay math!
fsrResistance = 5000 - batteryV; // fsrVoltage is in millivolts so 5V = 5000mV
fsrResistance *= 11000;
fsrResistance /= batteryV;
Serial.print("FSR resistance in ohms = ");
Serial.println(fsrResistance);
fsrConductance = batteryV*1000; //we measure in micromhos so
fsrConductance /= fsrResistance;
Serial.print("Conductance in microMhos: ");
Serial.println(fsrConductance);
// Use the two FSR guide graphs to approximate the force
if (fsrConductance <= 1000) {
fsrForce = fsrConductance / 80;
Serial.print("Newtons: ");
Serial.println(fsrForce);
Serial.write(fsrForce);
{
val=analogRead(fsrForce);
{
if(val>35)
Bean.setLed(0,0,255);
if (val<20) Bean.setLed(0,0,0);
}
}
}}}}