I have yet to implement some code that will let me know when USB power is connected: see viewtopic.php?t=199750
I have written the following code to give a low battery warning:
Code: Select all
if (seconds % 5 == 0) { // check battery once every 5 seconds
checkBattery();
}
Code: Select all
void checkBattery() {
float measuredvbat = analogRead(VBATPIN);
measuredvbat *= 2; // we divided by 2, so multiply back
measuredvbat *= 3.3; // Multiply by 3.3V, our reference voltage
measuredvbat /= 1024; // convert to voltage
// Serial.print("VBat: ");
// Serial.println(measuredvbat);
if (measuredvbat <= 3.5) { // if battery is low sound beep and flash bat
digitalWrite(switchAmp, HIGH); // put amp off standby
AudioPlayer.play("beep.wav", 0); // beep
delay(50);
digitalWrite(switchAmp, LOW); // put amp on standby
time_now = millis();
while (millis() <= (time_now + 1000)) { // millis used for a non blocking delay
clockDisplay.drawColon(false);
clockDisplay.println("BAT ");
clockDisplay.writeDisplay();
}
}
}
Any idea why this may be?