-
Notifications
You must be signed in to change notification settings - Fork 2
/
Voltage.cpp
47 lines (40 loc) · 1.28 KB
/
Voltage.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
/* Voltage.cpp
!*******************************************************************************
!* Description: Provides the functionality for voltage sensors.
!*
!* Known Bugs: Equation for voltage not implemented
!*
!*
!* DATE COMMENTS AUTHOR
!*=============================================================================
!* 26JAN16 Initial Delivery, have not tested T. von Friesen
!* everything yet
!*
!* 01FEB16 Compiled and debugged, everything T. von Friesen
!* checks out, need to test equation
!* accuracy with live data.
!*
!*****************************************************************************/
/* INCLUDES
******************************************************************************/
#include "Voltage.h"
#include "Arduino.h"
Voltage::Voltage(int pin)
{
this->pin = pin;
this->LastReadData = 0;
}
void Voltage::read(void)
{
double temp = 0;
//Read the analog value on pin
temp = analogRead(this->pin);
//Analog read returns a value of 1024 resolution => 1 unit = .0049V
/* Voltage Sensing Conversion Equation:
Vout = 0.0281Vin - 0.3427
Vin = (Vout + 0.3427)/0.0281
*/
temp = ((temp + 0.3427) * .0049) / 0.0281;
//Cast the double value into an integer
this->LastReadData = (uint8_t) temp;
}