Rotate 180 degrees over and over again over time

I have a object and I want it to rotate 180 degrees in the z axis, wait a second and repeat.

Background info:
I first created an animation in a 3d application, but the player is a physics controlled ball, and parenting the ball to the rotating object is giving trouble.
I got around that by creating a rotating object in unity using Transform.Rotate()
but now I need a way to have it stop every 180 degrees. (so the player can get on it)

const float ROTATE_TIME = 3.0f; // seconds
const float WAIT_TIME = 1.0f; // seconds
const float ROTATION_MAX = 180.0f; // degrees
float timer = 0.0f;

void Update(){
    // increment timer
    timer += Time.deltaTime;

    // reset the timer after it goes past total time
    while (timer > ROTATE_TIME + WAIT_TIME) {
        timer -= ROTATE_TIME + WAIT_TIME;
    }

    // rotate the object
    if (timer < ROTATE_TIME) {
        gameObject.transform.Rotate(Vector3.up * Time.deltaTime * ROTATION_MAX / ROTATE_TIME);
    }
}

Does this code do what you need? Do you see how it works?