Peripheral mySonar As SonarA @ 0 'Set the module ID as 0 Dim Distance As Word 'Save the acquired ranging result. Sub MAIN() mySonar.SetFloorLevel(0) 'Set the floor level to be larger than 5cm. mySonar.SetRangingTime(63) 'Set the ranging time as 63 ms. mySonar.SetRepeatTime(20) 'Set the repeating interval as 20ms. mySonar.SetRepeatCount(0) 'Set the repeating count as 0 (infinity) mySonar.SetBurstPower(10) 'Set the bust power as 10. Debug "Distance=" mySonar.RepeatRanging() 'Perform repeated ranging mySonar.EnableRangingFinishEvent() 'Enable the RangingFinishEvent Do 'Infinite loop Loop ' End Sub Event mySonar.RangingFinishEvent() mySonar.GetDistance(1,Distance) 'Read the ranging result Debug CSRXY(10,1), CLREOS, Distance, " CM", CR 'Display the result. End Event