Coding Switch

I was hoping someone might be willing to help on how to implement the code for limit switch. And also be able to give some advice on getting info from the joystick. Any kind of help would be much appreciated.

Hi, I’ve never written code for a limit switch before, but here’s some code I found

public class MyRobot extends IterativeRobot{
    DigitalInput limitSwitch;
    public void robotInit(){
        DigitalInput limitSwitch = new DigitalInput(1); // Put Port # inside parentheses
    }

    public void teleopPeriodic()
    {
        System.out.println(limitSwitch.get())
    }
}

When implemented, that example should print a boolean representing the limitSwitch’s state (active/inactive, on/off, true/false).

I hope this code is of help to you, and feel free to reach out if you’re still working on implementing it and need some pointers.

I’d highly recommend checking out the FRC screensteps:

https://wpilib.screenstepslive.com/s/currentCS/m/java/l/599709-switches-using-limit-switches-to-control-behavior

https://wpilib.screenstepslive.com/s/currentCS/m/java/l/599723-joysticks

so is the IterativeRobot a class that you already have ?

Thanks I appreciate the help but the thing is that the code that was provided on these sites did not work on with the code that i had. I don’t have much knowledge about c++ nor coding robot it’s mostly been examples and google.

Could you share the code you’re trying and what you want to do with the limit switch?

It’s better to share what you have if you have a problem and want help.

It sounds like you’re missing a lot of fundamental knowledge that you need to write programs for FRC. You should take the time to read FIRST’s official documentation; it’s very approachable and will lay the foundation you need.

If you’re using C++, start here. If you’re using Java, start here.

Once you have a bit of the bigger picture, the links Andrew shared should be very helpful.

1 Like

I would have really liked to learn more about the fundamentals. but the thing is the documentations provided by FIRST is really vague. And on top of that we don’t have much time to start from the very bottom at this point.

Sharif, did you try one of the language appropriate links provided by bvisness? You seem to be stuck in the early/more basic stages of writing your robot code. The documentation linked there, if followed step by step is good for getting going. I agree that on the more advanced topics that the documentation/examples are a bit lacking but this community tends to make up for those short comings when specific questions are asked with problematic source code provided.

I highly recommend those links. Good luck with your efforts.
Steve

It is true I do suck at the very basic :frowning: But at first I started with the same Documentations that bvIsness provided. But i Don’t know I can’t make sense of them by myself it would be helpful if one of you would look at the code I have and give some feedback on It but I don’t want to post the code here.

Need me to get more specific?

If you’re using C++, start in this specific section. If you’re using Java, start in this specific section. These articles are step-by-step tutorials on creating and running a real teleoperated robot project on a real robot. You owe it to yourself to go through that in full so you understand what’s going on.

If you encounter issues as you work through it, go ahead and ask a mentor on your team or ask others here. But no one will be able to help you unless you ask a more specific question.

And on that note, if you want feedback on your specific code, you’ll have to share it somewhere. Either post something here, or if you feel that’s too long, make a Gist on GitHub.

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.