Advertisement
Guest User

Untitled

a guest
Dec 5th, 2012
45
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.03 KB | None | 0 0
  1. using System;
  2. using System.Collections;
  3. using Microsoft.SPOT;
  4. using Microsoft.SPOT.Hardware;
  5.  
  6. namespace Tester
  7. {
  8.  
  9.     class I2CManager
  10.     {
  11.         I2CDevice.Configuration accelConfig = new I2CDevice.Configuration(0x53, 100);
  12.  
  13.         byte[] data = new byte[6];
  14.  
  15.         I2CDevice.I2CTransaction[] ReadAccel;
  16.  
  17.         I2CDevice accel;
  18.  
  19.         public I2CManager()
  20.         {
  21.             ReadAccel = new I2CDevice.I2CTransaction[]
  22.             {
  23.                 I2CDevice.CreateWriteTransaction(new byte[]{0x30}),
  24.                 I2CDevice.CreateReadTransaction(data)
  25.             };
  26.             accel = new I2CDevice(accelConfig);
  27.         }
  28.  
  29.         public void Read()
  30.         {
  31.             int read1 = accel.Execute(new I2CDevice.I2CTransaction[] { ReadAccel[0] }, 1000);
  32.             int read2 = accel.Execute(new I2CDevice.I2CTransaction[] { ReadAccel[1] }, 1000);
  33.             byte[] temp = ReadAccel[1].Buffer;
  34.             Debug.Print("Read: " + read1 + ", " + read2 + ", " + temp[0] + ", " + temp[1]);
  35.         }
  36.     }
  37. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement