-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathforcesmooth.ino
113 lines (66 loc) · 1.94 KB
/
forcesmooth.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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
#define Platform.h
int fsrPin = A0;
int fsrReading;
int fsrVoltage;
unsigned long fsrResistance;
unsigned long fsrConductance;
long fsrForce;
long fsrForce2;
int val;
void setup() {
Serial.begin(57600);
Serial.setTimeout(25);
}
void loop() {
fsrReading = analogRead(fsrPin);
Serial.print("Analog reading = ");
Serial.println(fsrReading);
int batteryV = Bean.getBatteryVoltage();
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 = 2800 - batteryV;
fsrResistance *= 9200;
fsrResistance /= batteryV;
Serial.print("FSR resistance in ohms = ");
Serial.println(fsrResistance);
fsrConductance = fsrResistance; //we measure in micromhos so
fsrConductance /= 920000;
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);
} else {
fsrForce = fsrConductance - 1000;
fsrForce /= 30;
Serial.println(fsrForce);
Serial.print("Newtons:");
{
val=analogRead(fsrForce);
{
{
char buffer[64];
size_t readLength = 64;
uint8_t length = 0;
length = Serial.readBytes(buffer, readLength);
// Return all the serial pins
if ( 0x02 == buffer[0] && 1 == length)
buffer[0] =
buffer[1] =
buffer[3] =
buffer[4]=
buffer[5]=
Serial.write((uint8_t*)buffer, 6);
{
}
}
}
}}}}