read voltage from Hazzah32 battery connector

This commit is contained in:
Kevin Matz 2020-12-16 10:35:15 -05:00
parent 5d951eba47
commit 1e3a247a4b

View File

@ -83,6 +83,9 @@ NeoPixelBus<NeoGrbwFeature, Neo800KbpsMethod> *strip;
ESPAsyncE131 *e131 = new ESPAsyncE131();
Preferences prefs;
//// static hardware
const uint8_t battery_sense = A13; //Hazzah32 battery connected to A13
//// Global button variables
bool pressed = false; // track button state
uint32_t change_time; // time of button press (ms)
@ -161,6 +164,20 @@ bool loadConfig() {
}
/*
Read the battery level
*/
float batteryVoltage() {
float v;
v = analogRead(battery_sense); // 12bit reading
v /= 4095.0f; // percent of range
v *= 2.0f; // doubled
v *= 3.3f; // percent of referance voltage
v *= 1.1f; // multiply by ADC resolution (V)
return v;
}
/*
Arduino powerup
*/
@ -189,6 +206,9 @@ void setup() {
//// start fixtures hardware:
// battery monitor
pinMode(battery_sense, INPUT);
// button
if (config.button_enable) {
Serial.println("Initializing OSC button");