-
Notifications
You must be signed in to change notification settings - Fork 0
/
analogRead.ino
56 lines (47 loc) · 1.16 KB
/
analogRead.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
// analogRead tab,
// Energia sketch
// StellarisWheeStat5_4a
// June 23, 2014 -JSS
//////////////// Read voltage pin ///////////
void readVolts() {
int inVolt = 0; // voltage read
for (int i =0; i<=15; ++i){
inVolt += analogRead(Vread_pin);
}
mVread = inVolt/16;
mVread = mVread*vcc/4096;
mVread = (vcc/2)-mVread;
Serial.print(mVread);
Serial.print(",");
}
//////////////////// Read current pin //////////////
void readCurrent(boolean printI) {
unsigned int iRead = 0; // current read
for (int i =0; i<=15; ++i){
iRead += analogRead(Iread_pin);
}
mVi = iRead/16;
if (gotLims == false){
iMax = mVi-2048;
iMin = mVi-2048;
gotLims = true;
}
if(mVi >= iMax+2048) {
iMax = mVi-2048;
}
if(mVi <= iMin+2048) {
iMin = mVi-2048;
}
// float cor1 = 0.4253*amplif + 1.2866;
mVi = mVi*vcc/4096 + corr; // Vout
// float offset = (res6/res5 +1)*dOff*vcc/330;
float offset = (dOff)*vcc/330;
mVi = mVi-offset;
mVi = res5/res6*mVi/res4;
float off2 = (165-dOff)*vcc/330/res4;
mVi = mVi -off2;
if (printI == true) {
Serial.print(mVi);
Serial.print(",");
}
}