-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathLipo.cpp
29 lines (25 loc) · 842 Bytes
/
Lipo.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
#include <Arduino.h>
#include "Lipo.h"
Lipo::Lipo(int pin) {
// Constructor
// Takes an int as pin to power up
_voltageDividerPin = pin;
}
float Lipo::read(void) {
//DEBUG("lipo read: ");
lipoBatteryReadings = 0 ;
lipoBatteryVolts = 0;
analogRead(_voltageDividerPin);
for (byte i=0; i<10; i++) {
//take 10 samples, and average
//DEBUG("analogRead: ");
//DEBUGln(analogRead(_voltageDividerPin));
lipoBatteryReadings+=analogRead(_voltageDividerPin);
}
lipoBatteryVolts = BATT_FORMULA(lipoBatteryReadings / 10.0);
//DEBUGln(lipoBatteryVolts);
return(lipoBatteryVolts);
// 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";
}