I was wondering if it is possibly to , for example, detect the current battery voltage from a battery plugged into the cortex, and possibly a power expander, and have the ability to make robotc jump to a section of timed code, depending on the voltage, for example, if it was at 7.2v, then could you have it jump to a section that would have different timing for moving, then a, for example, 6.2v battery? This thought came to mind when I was switching over to encoders, but I was wondering if it was possible.
Thanks!
Yes its possible, not really a very good way to do it but it could be done. Something like this.
// different functions to run based on voltage
void func_1() {
}
void func_2() {
}
void func_3() {
}
// a demo, not real code.
task main()
{
int voltage;
// voltage in mV
voltage = nImmediateBatteryLevel;
if( voltage > 7500 )
func_1();
else
if( voltage > 7000 )
func_2();
else
if( voltage > 6500 )
func_3();
// more code...
}
You would be better of researching PID control.