forked from Yveaux/Arduino_Vcc
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Vcc.h
64 lines (52 loc) · 2.14 KB
/
Vcc.h
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
/*
Vcc - A supply voltage measuring library for Arduino
Created by Ivo Pullens, Emmission, 2014
Inspired by:
http://provideyourown.com/2012/secret-arduino-voltmeter-measure-battery-voltage/
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
#ifndef VCC_H
#define VCC_H
#include "Arduino.h"
class Vcc
{
public:
/**
* Constructor
*
* @param correction Correction factor, when reported Vcc is off from measured (externally) Vcc
* (due to variations in bandgap voltage of +/- 0.1V)
* Calculate as Vcc_measured/Vcc_reported. Defaults to 1.
*/
Vcc( const float correction = 1.0 );
/**
* Retrieve current Vcc level.
*
* @return Current Vcc level, in Volts.
*/
float Read_Volts(void);
/**
* Retrieve current Vcc level. The total voltage range shall be passed
* as low/high bound. For e.g. an alkaline AA battery this range can be set
* to [0.6,..,1.5] Volts.
*
* @param range_min Low bound to Vcc level range, in Volts.
* @param range_max High bound to Vcc level range, in Volts.
* @param clip When set, assures returned percentage is clipped to [0..100]% range.
* @return Current Vcc level, as percentage of expected Vcc level.
*/
float Read_Perc(const float range_min = 0.0, const float range_max = 0.0, const boolean clip = true);
protected:
float m_correction; /**< Correction factor, when reported Vcc is off. */
};
#endif