Sub Process_Globals
Public Serial1 As Serial
Private wire As WireMaster
Private raf As RandomAccessFile
Private const MPU As Int = 0x48
Private timer1 As Timer
End Sub
Private Sub AppStart
Serial1.Initialize(115200)
Log("AppStart")
wire.Initialize
timer1.Initialize("timer1_Tick",1000)
timer1.Enabled=True
End Sub
Sub timer1_tick
wire.WriteTo2(MPU,True, Array As Byte(0x01))
wire.WriteTo2(MPU,True, Array As Byte(0xc2))'continuous mode , single ended input
wire.WriteTo2(MPU,True, Array As Byte(0xe3))
Dim t As Byte
t=0
Do While t=0 'checking for conversion completion
wire.WriteTo2(MPU,True, Array As Byte(0x01))
Dim c() As Byte = wire.RequestFrom(MPU, 2)
t=Bit.Get(c(0),7)
Log("conv status:",t)
Loop
wire.WriteTo(MPU, Array As Byte(0x00))
Dim b() As Byte = wire.RequestFrom(MPU, 2)
If b.Length = 2 Then
raf.Initialize(b, False)
Dim ch1 As Long = raf.Readuint16(raf.CurrentPosition)
'
Log("byte0 ",b(0))
Log("byte1 ",b(1))
Log(ch1)
Else
Log("Data Not Available...")
End If
End Sub