Chief Delphi

Chief Delphi (http://www.chiefdelphi.com/forums/index.php)
-   Java (http://www.chiefdelphi.com/forums/forumdisplay.php?f=184)
-   -   How do you program limit switches? (http://www.chiefdelphi.com/forums/showthread.php?t=113906)

Negative 9 18-02-2013 21:29

How do you program limit switches?
 
Right now I have a limit switch plugged into one of the ports on the Digital IO. Now what methods/classes do use to tell whether the limit switch is pressed or not. There doesn't seem to be a "limit switch" and I'm not sure what to use.

Anyone else know?

tuXguy15 18-02-2013 21:36

Re: How do you program limit switches?
 
Im working on the same thing for my team for tomorrow. What are you trying to control with the switch?

shank948 18-02-2013 21:38

Re: How do you program limit switches?
 
Use a DigitalInput. It should be declared as a static variable, like this:

public static DigitalInput limitSwitch;

Initialize it like this:

limitSwitch = new DigitalInput(slot,channel);

To use the limit switch, call the get() method on it, which, assuming you have it wired correctly, will return true if the switch is closed and false if it is open.

Any more questions?

Negative 9 18-02-2013 21:47

Re: How do you program limit switches?
 
Quote:

Originally Posted by shank948 (Post 1235961)
Use a DigitalInput. It should be declared as a static variable, like this:

public static DigitalInput limitSwitch;

Initialize it like this:

limitSwitch = new DigitalInput(slot,channel);

To use the limit switch, call the get() method on it, which, assuming you have it wired correctly, will return true if the switch is closed and false if it is open.

Any more questions?

ok, so for the constructor. I pass the slot that it's plugged into on the DigitalIO for the slot, but what do I pass for channel?

Negative 9 18-02-2013 21:48

Re: How do you program limit switches?
 
Quote:

Originally Posted by Zer0 (Post 1235960)
Im working on the same thing for my team for tomorrow. What are you trying to control with the switch?

A motorized car jack that stops working when it goes too low or too high

dheerm 18-02-2013 21:55

Re: How do you program limit switches?
 
DigitalInput name = new DigitalInput(slot)


fill in slot with the slot on the DIO that the switch is plugged into and name with whatever you want to call it.

name.get() will return you the boolean indicating whether the switch is pressed or Unpressed. If it's wired right, true will be pressed and false will be unpressed

Negative 9 18-02-2013 22:35

Re: How do you program limit switches?
 
Thanks, guys! Limit switch is working :)

Bill_B 18-02-2013 23:06

Re: How do you program limit switches?
 
Quote:

Originally Posted by Negative 9 (Post 1235974)
A motorized car jack that stops working when it goes too low or too high

Scissor jack? Very suave just to think of it.

Negative 9 18-02-2013 23:10

Re: How do you program limit switches?
 
Quote:

Originally Posted by Bill_B (Post 1236025)
Scissor jack? Very suave just to think of it.

Yup! We use it to change the angle of our shooter.

F22Rapture 19-02-2013 00:33

Re: How do you program limit switches?
 
Quote:

Originally Posted by Negative 9 (Post 1236026)
Yup! We use it to change the angle of our shooter.

Awesome! So are we :cool:

Here's ours:

https://sphotos-a.xx.fbcdn.net/hphot...42295922_n.jpg

https://sphotos-a.xx.fbcdn.net/hphot...83332209_n.jpg

https://sphotos-a.xx.fbcdn.net/hphot...17571241_n.jpg

arithehun 19-02-2013 01:44

Re: How do you program limit switches?
 
For some of you using command based programming, I noticed that the DigitalIOButton class wasn't working properly, so I programmed my own DigitalButton class using the very-functional DigitalInput class.

Code:

public class DigitalButton extends Button {
    private int channel;
    DigitalInput buttonInput;
   
    public DigitalButton(int channel) {
        this.channel = channel;
        buttonInput = new DigitalInput(channel);
    }

    public int getChannel() {
        return this.channel;
    }
   
    public boolean get() {
        return buttonInput.get();
    }
   
}



All times are GMT -5. The time now is 10:08.

Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
Copyright © Chief Delphi