-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathVcc.h
More file actions
49 lines (42 loc) · 1.35 KB
/
Vcc.h
File metadata and controls
49 lines (42 loc) · 1.35 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
#ifndef Vcc_h
#define Vcc_h
/*
* regulator
*
* Library to wrap regulator
*
* Greg Cope <greg.cope@gmail.com>
*
*/
#include <Arduino.h>
#define DEBUG(input) {Serial.print(input); Serial.flush();}
#define DEBUGln(input) {Serial.println(input); Serial.flush();}
// 3.3 (Vcc) / 1024 (ADC precision) = 0.0032258 0.00322265625
// Motineo example 1m+470k = 470 / ( 1000 +470 ) = 0.32 rounded up
// Ours 1.8m + 3.3m = 3300000 / ( 1800000 + 3300000 ) = 0.64705 or 1.55 (inverse)
// Ours 27M + 3.3M = 3300000 / ( 3300000 + 27000000 ) = 0.1089108911 or 9.181818182 inverse
//#define VCC_FORMULA(reading) reading * 0.0032258 * 1.1222222222 // >>> fine tune this parameter to match your voltage when fully charged
// details on how this works: https://lowpowerlab.com/forum/index.php/topic,1206.0.html
// 14.25V = measured 1.209V at pin
// 473 measured analog read
// 0.03012684989
// 0.02958984375
// measured
#define VCC_FORMULA(reading) reading * 0.03012684989
class Vcc
{
public:
Vcc(int pin0, int pin1);
float read(void);
boolean regOn(void);
void regOff(void);
boolean regIsOn(void);
private:
unsigned long _onTimeMs;
int _powerPin;
int _voltageDividerPin;
boolean _powerState;
int vccReadings;
float vccVolts;
};
#endif