Using a counter and a limit switch