In the Java edition of the game, you’ll want to place two sticky pistons instead of one regular piston.

To get the flying machine to stop, you’ll want to put your immovable blocks, like obsidian, in its path. Once it reaches the blocks, it should come to a halt. Swap the pistons to change the direction of the flying machine. If you place a trap door next to the immovable blocks you use to stop the flying machine, you can just open and close it to get it to move again.

Source: https://www.distractify.com/p/how-to-make-flying-machine-minecraft