public static void Main() { Debug.Print("\n\n"); Debug.Print("ADXL345 Interrupt Example."); Debug.Print("--------------------------"); var adxl345 = new ADXL345(); Debug.Print("Device ID: " + adxl345.DeviceID); // // Attach an interrupt handler. // adxl345.AccelerationChanged += (s, e) => { Debug.Print("X: " + e.CurrentValue.X.ToString() + ", Y: " + e.CurrentValue.Y.ToString() + ", Z: " + e.CurrentValue.Z.ToString()); }; // // Interrupts are attached so power on the sensor. // adxl345.SetPowerState(false, false, true, false, ADXL345.Frequency.EightHz); // // Put the Netduino to sleep as the interrupt handler will deal // with changes in acceleration. // Thread.Sleep(Timeout.Infinite); }
/// <summary> /// コンストラクタ /// </summary> public MainDataViewModel() { // ADXL345オブジェクト初期化 _ADXL345 = new ADXL345(); // 仮初期化 _ADXL345.InitializeSerialPort( "COM4", 9600, System.IO.Ports.Parity.None, System.IO.Ports.StopBits.One, 8 ); _ADXL345.IsInitialized = true; // 値設定 Canvas_X.Value = 220; Canvas_Y.Value = 155; Canvas_X = _ADXL345.axisValue.Canvas_XAxis; Canvas_Y = _ADXL345.axisValue.Canvas_YAxis; Acc_X = _ADXL345.axisValue.XAxis; Acc_Y = _ADXL345.axisValue.YAxis; // 購読 Acc_X.Subscribe(x => ActingInputByAccelerationValue('X', x)); Acc_Y.Subscribe(y => ActingInputByAccelerationValue('Y', y)); ConnectADXL345.Subscribe(_ => _ADXL345.StartConnection()); DisconnectADXL345.Subscribe(_ => _ADXL345.FinishConnection()); }
public static void Main() { Debug.Print("\n\n"); Debug.Print("ADXL345 Register Test Application."); Debug.Print("----------------------------------"); var adxl345 = new ADXL345(); Debug.Print("Device ID: " + adxl345.DeviceID); adxl345.SetPowerState(false, false, true, false, ADXL345.Frequency.EightHz); while (true) { adxl345.Update(); Debug.Print("X: " + adxl345.X + ", Y: " + adxl345.Y + ", Z: " + adxl345.Z); Thread.Sleep(500); } }
public static void Main() { ADXL345 adxl = new ADXL345(); adxl.Init(ADXL345.ADXL345_ADDR_ALT_LOW); while (true) { Thread.Sleep(150); var results = new int[3]; adxl.ReadAccel(out results); Debug.Print("X : " + results[0].ToString()); Debug.Print("Y : " + results[1].ToString()); Debug.Print("Z : " + results[2].ToString()); } }
public static ADXL345 initADXL345() { // Create an instance of the ADXL345 accel. accel = new ADXL345(); // Ensure that we are connected to the accel // (this will throw an exception if the accel does not respond). accel.EnsureConnected(); // Tell the accel we are interested in a range of +/- 2g. accel.Range = 16; // Tell the accel we want it to use full resolution. accel.FullResolution = true; // Enable the measurements on the device. accel.EnableMeasurements(); // Set the data rate to output at 50Hz accel.SetDataRate(0x0A); return accel; }