-
Notifications
You must be signed in to change notification settings - Fork 0
/
PPG-battery.ino
112 lines (92 loc) · 2.53 KB
/
PPG-battery.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
//Pin assignment
int WVPin = 0; //Wijs Vinger pin
int BHPPin = 1; //Bovenkant Handpalm pin
int MVHPin = 2; //Muis van hand pin
int DPin = 3; //Duim Pin
int BatteryPin = 5
//Reading assignment
int WVReading;
int BHPReading;
int MVHReading;
int DReading;
//Read voltage assignment
int WVVoltage;
int BHPVoltage;
int MVHVoltage;
int DVoltage;
//Resistance calculation assignment
unsigned long WVResistance;
unsigned long BHPResistance;
unsigned long MVHResistance;
unsigned long DResistance;
//Conductance calculation assignment
float WVConductance;
float BHPConductance;
float MVHConductance;
float DConductance;
//Force calculation assignment
float WVForce;
float BHPForce;
float MVHForce;
float DForce;
void setup() {
Serial.begin(9600);
}
void loop() {
//Assigning all values to their corresponding readings
WVReading = analogRead(WVPin);
BHPReading = analogRead(BHPPin);
MVHReading = analogRead(MVHPin);
DReading = analogRead(DPin);
//Mapping the voltage
WVVoltage = map(WVReading, 0, 1023, 0, 5000);
BHPVoltage = map(BHPReading, 0, 1023, 0, 5000);
MVHVoltage = map(MVHReading, 0, 1023, 0, 5000);
DVoltage = map(DReading, 0, 1023, 0, 5000);
//Calculating resistance
WVResistance = 5000 - WVVoltage;
WVResistance *= 10000;
WVResistance /= WVVoltage;
BHPResistance = 5000 - BHPVoltage;
BHPResistance *= 10000;
BHPResistance /= BHPVoltage;
MVHResistance = 5000 - MVHVoltage;
MVHResistance *= 10000;
MVHResistance /= MVHVoltage;
DResistance = 5000 - DVoltage;
DResistance *= 10000;
DResistance /= DVoltage;
//Calculating Conductance
WVConductance = 1000000;
WVConductance /= WVResistance;
BHPConductance = 1000000;
BHPConductance /= BHPResistance;
MVHConductance = 1000000;
MVHConductance /= MVHResistance;
DConductance = 1000000;
DConductance /= DResistance;
//Calculating The Force :P (Finally)
WVForce = WVConductance / 68;
//Serial.print("WijsVinger: ");
//Serial.println(WVForce);
BHPForce = BHPConductance / 68;
//Serial.print("BovenkantHandPalm: ");
//Serial.println(BHPForce);
MVHForce = MVHConductance / 68;
//Serial.print("MuisVanHand: ");
//Serial.println(MVHForce);
DForce = DConductance / 68;
//Serial.print("Duim: ");
//Serial.println(DForce);
Serial.print("#");
Serial.print(WVForce);
Serial.print(" ");
Serial.print(BHPForce);
Serial.print(" ");
Serial.print(MVHForce);
Serial.print(" ");
Serial.println(DForce);
Serial.print(" ");
Serial.println(analogRead(BatteryPin) * (5.0 / 1023.0))
delay(100);
}