'*********************************************************** '** ** '** I2C Routines for OOPic-R ** '** with the SRF08 Ultrasonic Ranger Modules ** '** ** '** Copyright 2003 - Devantech Ltd ** '** Commercial use of this software is prohibited ** '** Private and educational use only is permitted ** '** ** '** Written by Gerald Coe - January 2003 ** '** ** '*********************************************************** '** ** '** To view the Version, Light Sensor or Range Values ** '** Double click the object in the Debug Panel ** '** ** '*********************************************************** Dim SRF08 As New oI2C ' Create the SRF08 object Dim Ver as new oByte Dim Light as new oByte Dim Range as new oWord Sub main() SRF08.Node = 112 ' Decimal of Hex address 0xE0 shifted right by 1 SRF08.Mode = cv10bit ' I2C mode is 10-Bit Addressing. SRF08.NoInc = 1 ' Don't increment Do SRF08.Location = 0 ' Command Register SRF08.Width = cv8bit ' 1 byte wide transfer SRF08 = 81 ' Ranging Command - Result in cm Do ' Wait for ranging to complete Ver = SRF08 ' This will wait forever if your sonar Loop While Ver=255 ' becomes disconnected SRF08.Location = 1 ' Light Sensor Register Light = SRF08 ' Get Light Sensor value SRF08.Width = cv16bit ' 2 byte wide transfer SRF08.Location = 2 ' 1st Range Register Range = SRF08 ' Get Range to 1st object Loop End Sub