This is my first post here. Learning C for the first time to build a robot! :)
Are switch statements a better alternative to express the multiple if-else statements below? I mean this snippet of code works fine. But I'm just really curious about switch statements and want to learn about them.
If yes, I'm not exactly sure how to do them. I've googled extensively but just feel more and more intimidated by the complex programs out there. :/
while(1)
{
signed float A;
A = get_angle();
if (A > 540 && A <= 700)
{
put_speed(200, 600); //function to specify duty cycle and speed
}
else if (A > 1 && A <= 180)
{
put_speed (600, 200);
}
else if (A > 180 && A <= 360)
{
put_speed(600, 100);
}
else if (A > 360 && A <= 540)
{
put_speed(100, 600);
}
else
{
put_speed(600, 600);
}
} // End of While