Steam Piston Logic - How?

I have a vehicle which uses steam cannons to drive pistons up, which eventually rotates a gear which turns a wheel.
However, I'm having trouble getting logic to do the work of controlling the steam cannons.
The nearest thing to working seemed to be a motion sensor telling the steam cannons to go when the piston hit the bottom and stop once they reached the top, but for some reason, those dumb sensors have a control input delay; even after detecting the piston at the top of the stroke, they KEPT SHOOTING THE STEAM for about a quarter second longer than they should have.
Another problem: The interval of piston strokes is different at different speeds; so, the timing on the pistons that would work for top speed never works, because the pistons just keep windmilling around and not managing even two consecutive strokes.
So, I need to put a speedometer on there to 'switch piston timing', but I have no idea how to simply 'switch' control inputs using the logic gates we have in-game.
Can anyone help?