-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathVcc.cpp
58 lines (50 loc) · 1.41 KB
/
Vcc.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
48
49
50
51
52
53
54
55
56
57
58
#include <Arduino.h>
#include "Vcc.h"
Vcc::Vcc(int pin0, int pin1) {
// Constructor
// Takes an int as pin to power up
// and another int for the voltage dividor pin
_powerPin = pin0;
_voltageDividerPin = pin1;
}
boolean Vcc::regOn(void) {
// Switch device on by putting pin HIGH
digitalWrite(_powerPin, HIGH);
_onTimeMs = millis();
_powerState = true;
DEBUGln("Vcc reg on")
// TODO: Add code to check charger has gone on?!?!?!
}
void Vcc::regOff(void) {
// turn off the Device by putting pin LOW
digitalWrite(_powerPin, LOW);
_powerState = false;
DEBUGln("Vcc reg off")
}
boolean Vcc::regIsOn(void) {
// return state
// on == true
// off == false
//DEBUG("Vcc state is:");
//DEBUGln(_powerState);
return _powerState;
}
float Vcc::read(void) {
//Serial.println("Vcc reading vcc");
//Serial.flush();
vccReadings = 0 ;
vccVolts = 0;
analogRead(_voltageDividerPin);
for (byte i=0; i<10; i++) {
//take 10 samples, and average
//DEBUG("analogRead: ");
//DEBUGln(analogRead(_voltageDividerPin));
vccReadings+=analogRead(_voltageDividerPin);
}
vccVolts = VCC_FORMULA(vccReadings / 10.0);
//DEBUGln(vccVolts);
return(vccVolts);
// dtostrf(batteryVolts,3,2, BATstr); //update the BATStr which gets sent every BATT_CYCLES or along with the MOTION message
// 3 chars long 2 after decimal point
//if (batteryVolts <= BATT_LOW) BATstr = "LOW";
}