Chief Delphi

Chief Delphi (http://www.chiefdelphi.com/forums/index.php)
-   Java (http://www.chiefdelphi.com/forums/forumdisplay.php?f=184)
-   -   Programming Limit Switch (http://www.chiefdelphi.com/forums/showthread.php?t=124776)

OwenVanTiem 16-01-2014 20:06

Programming Limit Switch
 
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.

NWChen 16-01-2014 20:14

Re: Programming Limit Switch
 
Initialize limit switches as a digital input:
Code:

DigitalInput switch = new DigitalInput(channel)
To check if a switch is closed or not, use the get() method:
Code:

if(switch.get()) doSomething();
See this thread.

notmattlythgoe 17-01-2014 09:58

Re: Programming Limit Switch
 
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.

Code:

final DigitalInput limitSwitch = new DigitalInput(1);
Button limitSwitchButton = new Button() {
    public boolean get() {
          return limitSwitch.get();
    }
};
limitSwitchButton.whenPressed(new SomethingCommand());


gixxy 17-01-2014 15:11

Re: Programming Limit Switch
 
Quote:

Originally Posted by notmattlythgoe (Post 1328452)
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.

Code:

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:
Code:

Button limitSwitchButton = new DigitalIOButton(1);
limitSwitchButton.whenPressed(new limitSwitchCommand());


notmattlythgoe 17-01-2014 15:22

Re: Programming Limit Switch
 
Quote:

Originally Posted by gixxy (Post 1328546)
Actually there is already a class for this in WPILib: DigitalIOButton.

So you just need:
Code:

Button limitSwitchButton = new DigitalIOButton(1);
limitSwitchButton.whenPressed(new limitSwitchCommand());


Even simpler.


All times are GMT -5. The time now is 22:35.

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