Does anyone know a good way to make a revolving object that is code driven?

I have made a couple but they drive me crazy trying to work out the glitches.

The problem I run into is that basically I am giving the code conditions to look for that will cause the object to change directions. What happens is that the conditions occur twice for each cycle causing confusion for the player. At least I think that is what is happening.

Here is one but it uses four frames and two versions of the object. Iím thinking that I should be able to do this with two different functions and a variable that switches between two different values that would act as a switch.