IDK if you're using iterative robot or command base but essentially:
Code:
private int start;
public void initialize() {
start = encoder.get();
motor.set(speed);
}
public void loop() { //this would be execute in a command not sure in iterative
if(encoder.get()-start > 500) {
motor.set(0);
}
}
Not tested not even written in an IDE so take it with a grain of salt