Copyright © Parallax Inc.
Page 8 of 12
long cy
long cz
long ff_x
long ff_y
long ff_z
long multiBYTE[3]
PUB Go | last_ticks
pst.start(31, 30, 0, 115200)
' Set modes
Wrt_1B(CTRL_REG3, $08) ' Data ready signal
Wrt_1B(CTRL_REG4, $80) ' Block data update
Wrt_1B(CTRL_REG1, $1F) ' Enable all axes
last_ticks := cnt
repeat
pst.tx(1) ' Set Terminal data
WaitForDataReady
' at top of screen
Read_MultiB(OUT_X_INC) ' Read XYZ bytes
' Divide by 114 to reduce noise
x := (x - cx) / 114
y := (y - cy) / 114
z := (z - cz) / 114
RawXYZ
WaitCnt(ClkFreq / 4 + Cnt) ' Delay before next loop
PUB RawXYZ
'Display Raw X,Y,Z data
pst.str(string("RAW X ",11))
pst.dec(x)
pst.str(string(13, "RAW Y ",11))
pst.dec(y)
pst.str(string(13, "RAW Z ",11))
pst.dec(z)
'' Below here routines to support I2C interfacing
PUB WaitForDataReady | status
repeat
status := Read_1B(STATUS_REG)
if (status & $08) == $08
quit
PUB Wrt_1B(SUB1, data)
''Write single byte to Gyroscope.