Avionics
Core avionics package for CURE flight computers
Loading...
Searching...
No Matches
PowerManagement.h
Go to the documentation of this file.
1
#ifndef PowerManagement_H
2
#define PowerManagement_H
3
4
#include "Arduino.h"
5
#include "pins.h"
6
12
class
BatteryVoltage
{
13
public
:
14
BatteryVoltage
(uint8_t adcPin,
float
conversionFactor)
15
: pin(adcPin), factor(conversionFactor) {}
16
22
float
readVoltage
() {
23
// Set the pin for reading
24
pinMode(pin, INPUT);
25
uint32_t rawValue = 0;
26
rawValue = analogRead(pin);
// Should give a value between 0 and 1023, not sure how to convert this to the true voltage.
27
// Conversion notes -> respect to Vref you would do Vref * analogRead()/2^12.
28
// After that you can use the voltage divider equation to get the battery voltage level
29
// Vref is 134.33?
30
// float voltage = pow((rawValue/2),12) * factor;
31
Serial
.println(rawValue);
32
return
rawValue;
33
}
34
41
bool
isAlive
(){
42
return
readVoltage
() > .3;
// Not sure what a good cutoff is
43
}
44
45
private
:
46
uint8_t pin;
47
float
factor;
48
};
49
50
#endif
// PowerManagement_H
BatteryVoltage::readVoltage
float readVoltage()
Sample the ADC and convert to battery voltage.
Definition
PowerManagement.h:22
BatteryVoltage::BatteryVoltage
BatteryVoltage(uint8_t adcPin, float conversionFactor)
Definition
PowerManagement.h:14
BatteryVoltage::isAlive
bool isAlive()
Check whether voltage exceeds a minimal threshold.
Definition
PowerManagement.h:41
Serial
MockSerial Serial
include
PowerManagement.h
Generated by
1.16.1