Public Class Form1

    Dim WithEvents RC As New vRobots.RoCar01

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        RC.SetEvent(4)          '設定啟用碰觸感測器
        RC.StartEvent()         '啟動感測器
        RC.MoveC("F")
    End Sub

    Private Sub RC_TouchsChanged(ByVal byTouch As Byte) Handles RC.TouchsChanged
        Select Case byTouch
            Case 1              '碰觸到左邊
                Call Turn(1)    '呼叫Turn副程式
            Case 2              '碰觸到右邊
                Call Turn(2)    '呼叫Turn副程式
        End Select
    End Sub

    Public Sub Turn(ByVal path As Byte)
        RC.StopEvent()          '關閉感測器
        If path = 2 Then        '根據傳遞的參數值，來決定應往左轉還是往右轉
            RC.MoveC("R")
        Else
            RC.MoveC("L")
        End If
        For i = 1 To 3          '根據傳遞的參數值，來決定是第一組LED，還是第二組LED閃燈
            RC.LEDsOut(path, 255)
            RC.WaitN(100)
            RC.LEDsOut(path, 0)
            RC.WaitN(100)
        Next
        RC.MoveC("F")
        RC.StartEvent()         '啟動感測器
    End Sub
End Class
