
23-03-2013, 16:27
|
|
Registered User
 FRC #2813
|
|
Join Date: Feb 2013
Location: San Jose
Posts: 33
|
|
|
Re: AXDL345_I2C java problems
It is still not working
Here is the code
Quote:
package edu.wpi.first.wpilibj.templates;
import edu.wpi.first.wpilibj.ADXL345_I2C;
import edu.wpi.first.wpilibj.DriverStationLCD;
import edu.wpi.first.wpilibj.SimpleRobot;
import edu.wpi.first.wpilibj.Timer;
import java.util.Date;
public class RobotTemplate extends SimpleRobot {
ADXL345_I2C accelerometer;
public RobotTemplate()
{
DriverStationLCD.getInstance().println(DriverStati onLCD.Line.kUser2, 1, "Initializing...");
DriverStationLCD.getInstance().updateLCD();
// erase the line before the next time it gets called
DriverStationLCD.getInstance().println(DriverStati onLCD.Line.kUser2, 1, " ");
}
/**
* This function is called once each time the robot enters autonomous mode.
*/
public void autonomous() {
Timer.delay(0.05);
}
/**
* This function is called once each time the robot enters operator control.
*/
public void operatorControl() {
accelerometer = new ADXL345_I2C(1, ADXL345_I2C.DataFormat_Range.k2G);
// I2C i2c = accelerometer.getI2C();
// if (i2c.addressOnly()) {
// DriverStationLCD.getInstance().println(DriverStati onLCD.Line.kUser3, 1, "No Data");
// DriverStationLCD.getInstance().println(DriverStati onLCD.Line.kUser4, 1, "");
// }
DriverStationLCD lcd = DriverStationLCD.getInstance();
// lcd.println(DriverStationLCD.Line.kUser1, 1, (new Date()).toString());
// lcd.println(DriverStationLCD.Line.kUser2, 1, "Starting operator control");
// lcd.updateLCD();
//this.getWatchdog().setEnabled(false);
while(true) {
double x = accelerometer.getAcceleration(ADXL345_I2C.Axes.kX) ;
double y = accelerometer.getAcceleration(ADXL345_I2C.Axes.kY) ;
double z = accelerometer.getAcceleration(ADXL345_I2C.Axes.kZ) ;
lcd.println(DriverStationLCD.Line.kUser1, 1, (new Date()).toString());
lcd.println(DriverStationLCD.Line.kUser2, 1, "X: " + x);
lcd.println(DriverStationLCD.Line.kUser3, 1, "Y: " + y);
lcd.println(DriverStationLCD.Line.kUser4, 1, "Z: " + z);
lcd.updateLCD();
Timer.delay(0.05);
}
}
}
|
|