Log in

View Full Version : How do you program limit switches?


Negative 9
18-02-2013, 21:29
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
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
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
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
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
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
Thanks, guys! Limit switch is working :)

Bill_B
18-02-2013, 23:06
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
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
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/hphotos-prn1/18586_490032097722820_942295922_n.jpg

https://sphotos-a.xx.fbcdn.net/hphotos-frc1/21737_490032087722821_1683332209_n.jpg

https://sphotos-a.xx.fbcdn.net/hphotos-ash3/535494_490032124389484_1217571241_n.jpg

arithehun
19-02-2013, 01:44
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.


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();
}

}