Hi
I know questions here should only be for B4r, but maybe someone can help me.
Has anyone already done something with monitoring the power supply?
I'm trying to write such a program for my Seeeduino xiao, but it doesn't really work.
When the voltage drops below a certain level(2,50 Volt), the power led should start blinking.
But no matter how high the voltage is, the Power-Led does not blink.
I use 2x AA batteries as power supply.
I'm doing something wrong, but what?
Here is the sketch I use:
I know questions here should only be for B4r, but maybe someone can help me.
Has anyone already done something with monitoring the power supply?
I'm trying to write such a program for my Seeeduino xiao, but it doesn't really work.
When the voltage drops below a certain level(2,50 Volt), the power led should start blinking.
But no matter how high the voltage is, the Power-Led does not blink.
I use 2x AA batteries as power supply.
I'm doing something wrong, but what?
Here is the sketch I use:
B4X:
const int pbPwLed = 1; // Power-Led
const int pbAnalog = 0; // Analog-Input
float voltage = 0.0;
int batvalue = 0;
unsigned long lastblink = millis();
void setup() {
Serial.begin(115200);
pinMode(pbPwLed, OUTPUT);
pinMode(pbAnalog, OUTPUT);
}
void loop() {
ManageBattery();
}
void ManageBattery() {
batvalue = analogRead(pbAnalog);
voltage = batvalue * (3.30 / 1023.00);
if (voltage < 2.50) {
//Power-Led Blinken lassen
if ((millis() - lastblink) > 250){
digitalWrite(pbPwLed, !digitalRead(pbPwLed)); // LED wird ein- bzw. ausgeschaltet
lastblink = millis();
}
}
else{
digitalWrite(pbPwLed, HIGH); // turn ON the LED
}
Serial.print("Input Voltage = ");
Serial.println(voltage);
}