Grey shaft tends to rotate clockwise thanks to a spiral spring located in the blue box (a weight and wire can be used instead of the spring).
Yellow cam controls 360 deg. interrupted rotation of the grey shaft.
The spring that maintains the contact between the cam and green slider is not shown.
Other driving source for the green slider is possible, for example, a pneumatic cylinder.