-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfinalforce.ino
105 lines (66 loc) · 2.07 KB
/
finalforce.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
int fsrPin = A0;
int fsrReading = 0;
int sensorVal = 0; // store the value coming from the sensor
int smoothedVal = 0; // smoothed result
int samples = 4;
int value = 0;
int resistance;
int fsrVoltage;
unsigned long fsrResistance;
unsigned long fsrConductance;
long fsrForce;
float force;
int hits = 0; // impact count
int forceTrig = 1000; // impact sensitivity
int val;
void setup() {Serial.begin(57600);}
void loop() {
{
uint16_t force[] = { 0, 0 , 0};
uint16_t gAll = (abs(fsrForce)+abs(fsrForce)+abs(fsrForce));
if ((gAll > 1000));
Serial.println( hits );
delay(50); // prevent duplicate detection
if (fsrForce > 2) { Bean.setLed(0,0,255); } // blue
if (fsrForce > 5) { Bean.setLed(255,0,0); } // red
if (fsrForce > 3) { Bean.setLed(0,255,0); } // green
if (fsrForce < 0) { Bean.setLed(0,0,0); } //NONE
hits++;
fsrReading = analogRead(fsrPin);
Serial.print("Analog:");
sensorVal = analogRead(fsrReading);
smoothedVal = smoothedVal + ((sensorVal -smoothedVal)/samples);
Serial.print("Smoothed Analog:");
Serial.println(smoothedVal, DEC);
// slow down amount of readings and prints
delay(100);
float voltage = sensorVal * (2.7 / 1023.0);
Serial.print("Voltage:");
Serial.println(voltage,DEC);
delay(100);
value = analogRead(sensorVal);
resistance = ((9200 * value)/(1-(value/1023.0)));
Serial.print("Resistance:");
Serial.println(resistance,DEC);
delay(200);
if (voltage == 0)
{Serial.println("0");
} else {
fsrResistance = 2700 - voltage;
fsrResistance *= 9200;
fsrResistance /= voltage;
Serial.print("FSR resistance in ohms = ");
Serial.println(fsrResistance);
fsrConductance = 920000;
fsrConductance /= resistance*100;
Serial.print("Conductance in microMhos: ");
Serial.println(fsrConductance);
if (fsrConductance <= 1000) {
fsrForce = fsrConductance / 80;
Serial.print("Newtons");
Serial.println(fsrForce);
} else {
fsrForce = fsrConductance - 1000;
fsrForce /= 30;
Serial.println(fsrForce);
}}}}