Class ADXL345_I2C

java.lang.Object
edu.wpi.first.wpilibj.ADXL345_I2C
All Implemented Interfaces:
Accelerometer, Sendable, AutoCloseable

public class ADXL345_I2C
extends Object
implements Accelerometer, Sendable, AutoCloseable
ADXL345 I2C Accelerometer.
  • Field Details

  • Constructor Details

    • ADXL345_I2C

      public ADXL345_I2C​(I2C.Port port, Accelerometer.Range range)
      Constructs the ADXL345 Accelerometer with I2C address 0x1D.
      Parameters:
      port - The I2C port the accelerometer is attached to
      range - The range (+ or -) that the accelerometer will measure.
    • ADXL345_I2C

      public ADXL345_I2C​(I2C.Port port, Accelerometer.Range range, int deviceAddress)
      Constructs the ADXL345 Accelerometer over I2C.
      Parameters:
      port - The I2C port the accelerometer is attached to
      range - The range (+ or -) that the accelerometer will measure.
      deviceAddress - I2C address of the accelerometer (0x1D or 0x53)
  • Method Details

    • close

      public void close()
      Specified by:
      close in interface AutoCloseable
    • setRange

      public void setRange​(Accelerometer.Range range)
      Description copied from interface: Accelerometer
      Common interface for setting the measuring range of an accelerometer.
      Specified by:
      setRange in interface Accelerometer
      Parameters:
      range - The maximum acceleration, positive or negative, that the accelerometer will measure. Not all accelerometers support all ranges.
    • getX

      public double getX()
      Description copied from interface: Accelerometer
      Common interface for getting the x axis acceleration.
      Specified by:
      getX in interface Accelerometer
      Returns:
      The acceleration along the x axis in g-forces
    • getY

      public double getY()
      Description copied from interface: Accelerometer
      Common interface for getting the y axis acceleration.
      Specified by:
      getY in interface Accelerometer
      Returns:
      The acceleration along the y axis in g-forces
    • getZ

      public double getZ()
      Description copied from interface: Accelerometer
      Common interface for getting the z axis acceleration.
      Specified by:
      getZ in interface Accelerometer
      Returns:
      The acceleration along the z axis in g-forces
    • getAcceleration

      public double getAcceleration​(ADXL345_I2C.Axes axis)
      Get the acceleration of one axis in Gs.
      Parameters:
      axis - The axis to read from.
      Returns:
      Acceleration of the ADXL345 in Gs.
    • getAccelerations

      public ADXL345_I2C.AllAxes getAccelerations()
      Get the acceleration of all axes in Gs.
      Returns:
      An object containing the acceleration measured on each axis of the ADXL345 in Gs.
    • initSendable

      public void initSendable​(SendableBuilder builder)
      Description copied from interface: Sendable
      Initializes this Sendable object.
      Specified by:
      initSendable in interface Sendable
      Parameters:
      builder - sendable builder