diff --git a/wiflash_esp32/wiflash_esp32.ino b/wiflash_esp32/wiflash_esp32.ino index 6984f2e..d36aba1 100644 --- a/wiflash_esp32/wiflash_esp32.ino +++ b/wiflash_esp32/wiflash_esp32.ino @@ -83,6 +83,9 @@ NeoPixelBus *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");