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