LCD Battery

I was just fooling around and found a good old LCD
I thought of several ways too use it too
The way I have it set up is it displays whether I am in driver control or autonomous but I want it to when I push any button (no preference) to display the battery life I am using RobotC if anyone could post a code that would seriously help thanks so much

The variable you’re looking for is nAvgBatteryLevel, which holds the current battery voltage in millivolts.

I’m sure there’s a more efficient way to do this, but the current code I have to display the battery level in volts is:

//Setup battery voltage meters
int mainVoltage1 = floor(nAvgBatteryLevel / 1000.0);
int mainVoltage2 = (nAvgBatteryLevel - (mainVoltage1 * 1000)) / 10;
//Display the current main battery voltage.
displayLCDString(0, 1, "Main");
displayLCDNumber(0, 9, mainVoltage1);
displayLCDString(0, 10, ".");
displayLCDNumber(0, 11, mainVoltage2);
displayLCDString(0, 13, "v");

Buttons are accessed by the variable nLCDButtons.

If nLCDButtons == 0, no buttons are pressed.

This should get you started… :slight_smile:


I didn’t see where I pressed the button to display the voltage?

I didn’t write the whole program for you, but just gave you the building blocks required.

WHILE the program is running, IF you push a button you DISPLAY the battery voltage. OTHERWISE, you DISPLAY something else…



Thanks I got it it works something you might want to try is nImmediatebatterylevel not nAvgBatteryLvl