controlling the cube movement

I am new to blender and I’d like to make a continuous function to control the cube movement , like a square wave , when the value is one I’d like the cube to move in the y direction , when it’s zero I’d like it to stop.
Any idea how should I do that , using what kind of sensors?