Public Class Form1

    Dim WithEvents RC As New vRobots.RoCar01
    Dim i As Short = 5

    Sub TurnRight()
        RC.MoveC("R")
        RC.WaitN(100) '100微秒適合速度：中的試驗, 200微秒適合速度：慢的試驗(50~90適合度速:快)
        Application.DoEvents()
        RC.MoveC("F")
    End Sub

    Sub TurnLeft()
        RC.MoveC("L")
        RC.WaitN(100) '100微秒適合速度：中的試驗, 200微秒適合速度：慢的試驗(50~90適合度速:快)
        Application.DoEvents()
        RC.MoveC("F")
    End Sub

    Private Sub RC_CamsChanged(ByVal byCam As Byte) Handles RC.CamsChanged
        Static byCam_old
        If byCam_old = 6 And byCam = 7 Then '往右(110->111才左轉)
            TurnRight()
        ElseIf byCam_old = 3 And byCam = 7 Then '往右(011->111才左轉)
            TurnLeft()
        ElseIf byCam = 0 Then '在三點同時為黑色區時，進入停車的程序
            RC.MoveC("L")
            RC.WaitN(100)
            RC.MoveC("F")
            RC.WaitN(2000)
            RC.MoveC("X")
            RC.StopEvent()
        End If
        byCam_old = byCam
    End Sub
End Class
