Code: Select all
Option Explicit
Dim Stack1(1 To 48) As Byte
Dim Stack2(1 To 48) As Byte
Dim Width1 as Single, Feet1 as Single, Inches1 as Single
Dim Width2 as Single, Feet2 as Single, Inches2 as Single
'---------------------------------------------------
Public Sub Main()
CallTask "SonarTask1", Stack1
Call Sleep(0.2)
CallTask "SonarTask2", Stack2
Call Sleep(0.2)
Do
Call Sleep(120.0)
Loop
End Sub
'-------------------------------------------------------------------------------------
Private Sub SonarTask1()
Do
Call PulseOut(17, 3.0, 1)
Call PulseIn(17, 1, Width1)
Feet1 = Width1 * 550.0 'assuming 1100 feet per sec
Inches1 = Feet1 * 12.0
Debug.Print CStr(Inches1)
Call Delay(0.3)
If Inches1 <5.0 then
Call Putpin (25,0) 'turns on LED pin 25, ZX-24a
Else
Call Putpin (25,1) 'turns off LED pin 25, ZX-24a
End If
Call PutPin(17, 1)
Loop
End Sub
'-------------------------------------------------------------------------------------
Private Sub SonarTask2()
Do
Call PulseOut(18, 3.0, 1)
Call PulseIn(18, 1, Width2)
Feet2 = Width2 * 550.0 'assuming 1100 feet per sec
Inches2 = Feet2 * 12.0
Debug.Print CStr(Inches2)
Call Delay(0.3)
If Inches2 <5.0 then
Call Putpin (26,0) 'turns on LED pin 26, ZX-24a
Else
Call Putpin (26,1) 'turns off LED pin 26, ZX-24a
End If
Call PutPin(18, 1)
Loop
End Sub
Dan