I am currently coding a ZUMO32U4 to do certain tasks. The problem is relatively tiny compared to the amount of code, yet it still is a major problem when it comes to functionality. The code keeps outputting 0% battery to the lcd display, even on startup (note that this is an imaginary, code defined battery), even though i see no logical reason in my code for it doing so. Expected output should be 100% at the beginning, decreasing as time goes. I get no compile errors. I would also rule out electronics errors seeing as the Polulu ZUMO32U4 is a premade product.
//This function is called on every loop
//the setup is also not important
void update_battery(){
//if the battery is above 100%, set it to 100% again.
if (battery > 100.00){
battery = 100.0;
}
lcd.clear();
lcd.print(battery);
lcd.print("%");
//beeps if the battery is low.
battery_low_warning(battery);
// if the speed is over 0, start the battery drain. ignores stationary drain.
if (speedMperS > 0) {
battery -= battery_drain();
}
//charges battery if it's going backwards.
else if (speedMperS < 0){
battery += battery_drain()*charge_multiplier; //multiplier if we want faster charging. Can be tuned for a specific purpose.
}
charging_cycle();
five_percent_counter(battery, battery_switch);
battery_production_error();
calculate_battery_health(avg_speed, highest_speed, timeCloseMax);
check_battery_health();
}
float battery_drain(){
//at this point this function only returns the distance.
//this would mean that 1m of distance is 1% of battery drain.
//this can be tweaked to our liking/needs easily.
return distance*0.1;
}
void meterDistanceCalc(int leftCount,int rightCount){
float avgCount = (leftCount + rightCount)/2.0;
distance = (avgCount/907.0)*oneRotation;
}
void speedMeterPerSecond(){
if(currentTid - prevTime >= 1000){
speedMperS = distance - currentDistance;
update_arrays();
//arrayIndex is used as a meter to know how many seconds have passed.
//The array function is not relevant in this part
arrayIndex++;
currentDistance = distance;
prevTime = millis();
}
}