-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy patharduino_voltmeter.cpp
94 lines (86 loc) · 1.42 KB
/
arduino_voltmeter.cpp
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
#include<iostream>
using namespace std;
float voltage(float n){
//dividing voltage by 3 using resistors
float v= (n/1024)*5*3;
return v;
}
int Percentage3sLiPo(float v){
if (v>12.60){
return 999;
}
else if(v>12.45){
return 100;
}
else if(v>12.33){
return 95;
}
else if(v>12.24){
return 90;
}
else if(v>12.06){
return 85;
}
else if(v>11.94){
return 80;
}
else if(v>11.85){
return 75;
}
else if(v>11.73){
return 70;
}
else if(v>11.61){
return 65;
}
else if(v>11.55){
return 60;
}
else if(v>11.52){
return 55;
}
else if(v>11.46){
return 50;
}
else if(v>11.40){
return 45;
}
else if(v>11.37){
return 40;
}
else if(v>11.31){
return 35;
}
else if(v>11.25){
return 30;
}
else if(v>11.19){
return 25;
}
else if(v>11.13){
return 20;
}
else if(v>11.07){
return 15;
}
else if(v>11.06){
return 10;
}
else if(v>11.05){
return 5;
}
else if(v<11.05){
return 0;
}
else {
return -1;
}
}
int main(){
int n;
float v;
cin>>n;
v=voltage(n);
cout<<"battery capacity is little less than "<<Percentage3sLiPo(v)<<endl;
cout<<"battery voltage is "<<v<<endl;
}