Programming for a limit switch is straightforward. You just need to read the value of the switch and test for “active”. Sometimes a limit switch will return a True when it’s inactive, and False when it’s active; sometimes it will be the other way around. You also need to know whether the motor would be moving “forward” or “reverse” when it hits the switch.
When you see that the switch is active and the motor is being asked to travel in the direction you don’t want it to go anymore, set the motor value to zero. That’s it. If the switch is not active, don’t do anything special; that will let the motor move normally. If the motor isn’t being told to go in the direction you don’t want it to go, don’t do anything special; that will let the motor go back away from the limit.
In the API, theres a class called, DigitalInput. Once you create the class and specified with GPIO to keep track of, you can use the get() function to keep track of the state of the switch. Then you can use it as the boolean expression for the “if” statement.