View Full Version : Programming Limit Switch
OwenVanTiem
16-01-2014, 20:06
I am the programmer for my team, and I am curious how to program a limit switch. I cant seem to find any documentation or code snippets elsewhere on the internet.
Initialize limit switches as a digital input:
DigitalInput switch = new DigitalInput(channel)
To check if a switch is closed or not, use the get() method:
if(switch.get()) doSomething();
See this thread. (http://www.chiefdelphi.com/forums/showthread.php?t=114318)
notmattlythgoe
17-01-2014, 09:58
What Signet said.
Also, if you ware using the Command Based structure with Java you can set the limit switch up to act as a button to fire a command.
final DigitalInput limitSwitch = new DigitalInput(1);
Button limitSwitchButton = new Button() {
public boolean get() {
return limitSwitch.get();
}
};
limitSwitchButton.whenPressed(new SomethingCommand());
What Signet said.
Also, if you ware using the Command Based structure with Java you can set the limit switch up to act as a button to fire a command.
final DigitalInput limitSwitch = new DigitalInput(1);
Button limitSwitchButton = new Button() {
public boolean get() {
return limitSwitch.get();
}
};
limitSwitchButton.whenPressed(new SomethingCommand());
Actually there is already a class for this in WPILib: DigitalIOButton.
So you just need:
Button limitSwitchButton = new DigitalIOButton(1);
limitSwitchButton.whenPressed(new limitSwitchCommand());
notmattlythgoe
17-01-2014, 15:22
Actually there is already a class for this in WPILib: DigitalIOButton.
So you just need:
Button limitSwitchButton = new DigitalIOButton(1);
limitSwitchButton.whenPressed(new limitSwitchCommand());
Even simpler.
vBulletin® v3.6.4, Copyright ©2000-2017, Jelsoft Enterprises Ltd.