001 /*----------------------------------------------------------------------------*/ 002 /* Copyright (c) FIRST 2008-2012. All Rights Reserved. */ 003 /* Open Source Software - may be modified and shared by FRC teams. The code */ 004 /* must be accompanied by the FIRST BSD license file in the root directory of */ 005 /* the project. */ 006 /*----------------------------------------------------------------------------*/ 007 008 package edu.wpi.first.wpilibj.buttons; 009 010 import edu.wpi.first.wpilibj.DriverStation; 011 import edu.wpi.first.wpilibj.DriverStationEnhancedIO.EnhancedIOException; 012 013 /** 014 * 015 * @author Greg 016 */ 017 public class AnalogIOButton extends Trigger { 018 019 public static double THRESHOLD = 0.5; 020 021 int port; 022 023 public AnalogIOButton(int port) { 024 this.port = port; 025 } 026 027 public boolean get() { 028 try { 029 return DriverStation.getInstance().getEnhancedIO().getAnalogIn(port) < THRESHOLD; 030 } catch (EnhancedIOException ex) { 031 return false; 032 } 033 } 034 035 }