' CMPS01 Compass -> OOPic Example Code ' ' This reads compass register 1, an 8 bit value representing the bearing ' as a 0 - 255 value. ' To read the value in degrees, change the Bearing from oByte to oWord ' and the .Location to 2, and the .Width to cv16bit ' Registers 2,3 are 0 - 3599 representing 0 - 359.9 degrees ' Dim Compass As New oI2C ' Create the compass objects Dim Led As New oDio1 ' Dim Bearing as new oByte ' Somewhere to store the reading Sub main() Setup ' Setup the LED and compass Do Compass.Location = 1 ' Address of single byte bearing Compass.Width = cv8bit ' Compass Data is 1-byte wide. Bearing = Compass.Value ' Get it If( (Bearing<5) Or (Bearing>250) ) Then Led = 1 Else ' Light the Led if within 5 degrees of north Led = 0 End If Loop End Sub Sub SetUp() Compass.Node = 96 ' Decimal of Hex address 0xC0 shifted right by 1 Compass.Mode = cv10bit ' I2C mode is 10-Bit Addressing. Compass.NoInc = 1 ' Don't increment Led.IOLine = 30 ' Pin 28 on 40 way connector Led.Direction = cvOutput ' End Sub