'SonarATest.inb : SonarA Module Test Program
Const Frequency As Word = 1047
Peripheral MySonar As SonarA @ 3
    'Set Module Name,Type, And ID
Dim
 Distance As Word
Sub main()
Do
 MySonar.Ranging()
       '通知超音波模組開始量測
 Pause(100)
 MySonar.GetDistance(1,Distance)
    '讀取量測結果 1=回傳距離單位
 Debug CLS,"Distance =", Distance,"cm",CR
 If (Distance<15 And Distance>10) Then
  Sound(12,200,Frequency):Pause (100)
  Else If(Distance<10)Then
        
  Sound(12,100,Frequency):Pause (20)
 End If
 End If
Loop
 
End Sub
 
沒有留言:
張貼留言