Create a gist now

Instantly share code, notes, and snippets.

Limit Switch Sample Code
package org.usfirst.frc.team4940.robot;
import edu.wpi.first.wpilibj.Joystick;
import edu.wpi.first.wpilibj.CANTalon;
import edu.wpi.first.wpilibj.SampleRobot;
import edu.wpi.first.wpilibj.Timer;
import edu.wpi.first.wpilibj.DigitalInput;
/**
* This is a short sample program demonstrating how to use the basic throttle
* mode of the new CAN Talon.
*/
public class Robot extends SampleRobot {
CANTalon motor;
Joystick xbox;
DigitalInput limit;
public Robot() {
motor = new CANTalon(1); // Initialize the CanTalonSRX on device 1.
xbox = new Joystick(0);
limit = new DigitalInput(1);
}
/**
* Runs the motor.
*/
public void operatorControl() {
while (isOperatorControl() && isEnabled()) {
// Set the motor's output to half power.
// This takes a number from -1 (100% speed in reverse) to +1 (100% speed
// going forward)
if(limit.get()){
motor.set(1);
} else {
motor.set(xbox.getRawAxis(5));
}
System.out.println(limit.get());
Timer.delay(0.01); // Note that the CANTalon only receives updates every
// 10ms, so updating more quickly would not gain you
// anything.
}
motor.disable();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment