Programing Battery in Debug Stream

I have been playing with some codes to try to get the main battery and the battery expander voltage to read out in real. I was able to make one that if I “step in” to the code, I could get the voltage, but if I use the code for the debug stream, it rounds it to the nearest whole number. Anyone know how I can fix this?

Here is my debugger code


#pragma config(Sensor, in1,    PE,             sensorAnalog)
//*!!Code automatically generated by 'ROBOTC' configuration wizard               !!*//

#pragma DebuggerWindows ("debugStream")
task main()
{

	int bat;
	int batexp;
	clearDebugStream();
	clearTimer(T1);

	while(true){
		bat =  nImmediateBatteryLevel/1000.0;
		batexp =  SensorValue(PE)/280.0;
		writeDebugStreamLine("battery is %1.1f%c V", bat);
		writeDebugStreamLine("batteryexpander is %1.1f V", batexp);
		wait1Msec(1000);
	}
}

Hm… I think the problem might be that your variables bat and batexp are int type. That will automatically round numbers into integers. Try changing them to float and see what happens.

I used float and it worked, thanks.

You’re welcome, I’m glad it’s working now!