how to code a limit switch through CANSparkmax?
You can look here for configuring a limit switch: https://www.revrobotics.com/sparkmax-users-manual/#section-2-4-1
Also this if you are plugging right into the Spark Max: https://github.com/REVrobotics/SPARK-MAX-Examples/tree/master/Java/Limit%20Switch
However, that will only help you if you’re connecting the limit switch directly to the Spark Max. If you are connecting it to the RoboRIO, you will use the DigitalInput
class like we did in last year’s code here: https://github.com/frc1444/robot2019/blob/5734215595a7e7ef172c552b35ae7aa1122d16ba/src/main/java/com/first1444/frc/robot2019/subsystems/implementations/MotorLift.java#L65 Although it uses a Talon, it’s the same idea.
hey how about limit switch plugged to the talon srx
I’m gonna play some “teach a man to fish…”
When looking to figure out how to write code, there are three primary resources I use, in order:
- Manufacturer provided sample code.
- Manufacturer provided API documentation.
- Code written by other teams, that does similar things.
For 1 and 2, they are both usually linked from the manufacturer’s product page. Additionally, google.com is the probably the best tool out there for a “blind” search.
In your specific case, CTRE provides links to 1 and 2 on their website:
There is a C++ example for reading from and processing with limit switches. The API documentation on some of the functions used can be found here.
Thank you
This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.