I have the following code in my microcontroller project:
if (newThrottle < currentThrottle)
{
for (int set = currentThrottle; set >= newThrottle; set--)
{
// Perform actions to set the throttle
}
}
else
{
for (int set = currentThrottle; set <= newThrottle; set++)
{
// Perform actions to set the throttle
}
}
If it's not blatantly obvious, this code snippet is used to ramp the motor throttle up or down from its current value to a new value.
Is there any more elegant way to write this?