How would I code it in my program to do a battery warning when it is less than 20?
The battery level is almost always visible on the controller screen by default, so it wouldn’t really be necessary.
// https://help.vex.com/article/141-how-to-plan-for-charging-the-v5-robot-battery
// says that V5 batteries should never be used when below 10% charge
// print warning to brain and controller screens when battery charge is 10% or less
int batteryAlert(){
while(1){
if (Brain.Battery.capacity(percentUnits::pct) <= 10){
Brain.Screen.clearScreen(color::orange);
Controller1.Screen.clearScreen();
vex::task::sleep(250);
Brain.Screen.printAt(90, 135, ">> RECHARGE BATTERY <<");
Controller1.rumble("-");
Controller1.Screen.setCursor(1, 2);
Controller1.Screen.print("RECHARGE");
Controller1.Screen.setCursor(2, 8);
Controller1.Screen.print("BATTERY");
vex::task::sleep(500);
}
vex::task::sleep(500);
}
}
int main() {
vex::task alert(batteryAlert); // start alert task
//Prevent main from exiting with an infinite loop.
while(1) {
vex::task::sleep(100);//Sleep the task for a short amount of time to prevent wasted resources.
}
}
This is set for 10%, easy to change to 20.
My team members tend to not look at the controller screen which is why I’m just trying to making it vibrate to get their attention.
Thank you, my problem was that I thought you needed to make the percentage into a separate integer.