-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathElectroSensor.cpp
More file actions
64 lines (49 loc) · 1.19 KB
/
Copy pathElectroSensor.cpp
File metadata and controls
64 lines (49 loc) · 1.19 KB
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
/*
* -Electric Sensing Library-
*
* this cpp file for Electric Sensing Library
*
* author jihoonkimtech (jihoonkimtech@naver.com)
* (Republic of Korea)
* version V0.0.1
*/
#include "ElectroSensor.h"
VoltSensor::ElectroSensor(int type, int pin){
_pin = pin;
_type = type;
pinMode(_pin, INPUT);
}
VoltSensor::readVoltage(int unit = NORMAL){
double analogInTmp = analogRead(_pin);
double voltTmp = (analogInTmp * _multiple) / _analogRes;
_voltage = voltTmp / (_res2/(_res1+_res2));
if(NORMAL)
return _voltage;
else if(MILLI)
return _voltage/1000.0;
else if(KILO)
_voltage*1000.0;
}
VoltSensor::printVoltage(char lastChr = '\n'){
Serial.print("VOLTAGE : ");
Serial.print(readVoltage());
Serial.print(" V ");
Serial.print(lastChr);
}
VoltSensor::readCurrent(int unit = NORMAL){
double analogInTmp = analogRead(_pin);
double voltTmp = (analogInTmp - 511) * 5 / 1024;
_current = voltTmp / 0.185;
if(NORMAL)
return _current;
else if(MILLI)
return _current/1000.0;
else if(KILO)
_current*1000.0;
}
VoltSensor::printCurrent(char lastChr = '\n'){
Serial.print("CURRENT : ");
Serial.print(readCurrent());
Serial.print(" A ");
Serial.print(lastChr);
}