Here's an improved program for the DiscRover. This new code uses the OOPic's Virtual Circuit technology.
These VCs are an integral part of OOPic programming and are ideally suited for event-based programming, something that's key in robotic control.

By re-coding the control routine with VCs, we are able to easily create more sophisticated behaviors for the individual switches
(the program in the book only has one set back-up routine that occurs when one or both switches are triggered). Building the code with VCs
also makes it easier to layer on new, more complicated routines
as we add other sensor systems. This code was created by Jesse Hurdus. Thanks, Jesse!

'An event driven program using Virtual Circuits
'to control two DC motors through a Pololu Motor Controller
'with two bump switches.

Dim S As New oSerialX
Dim R As New oDio1

Dim LSwitch As New oDio1
Dim RSwitch As New oDio1

Dim LTouch As New oWire
Dim RTouch As New oWire
Dim LTurn As New oEvent
Dim RTurn As New oEvent

Sub Main( )

OOPic.Pullup = cvTrue

LSwitch.IOLine = 8
LSwitch.Direction = cvInput 'Switch Initialization
RSwitch.IOLine = 10
RSwitch.Direction = cvInput

R.IOLine = 31
S.Baud = cv4800
S.IolineS = 30
S.Operate = cvTrue 'Motor controller serial initialization
R.Direction = cvOutput
OOPic.Delay = 50

LTouch.Input.Link(LSwitch.Value)
LTouch.InvertIn = cvTrue
LTouch.Output.Link(RTurn.Operate)
RTouch.Input.Link(RSwitch.Value) 'setup bump parameters
RTouch.InvertIn = cvTrue
RTouch.Output.Link(LTurn.Operate)

LTouch.Operate = cvTrue
RTouch.Operate = cvTrue 'begin watching for events

Do
S.Value = 128
S.Value = 0
S.Value = 0
S.Value = 127 'travel forward
S.Value = 128
S.Value = 0
S.Value = 3
S.Value = 127
OOPic.Delay = 150
Loop

End Sub

Sub LTurn_CODE ( ) 'left turn sub-procedure

S.Value = 128
S.Value = 0
S.Value = 1
S.Value = 45
S.Value = 128
S.Value = 0
S.Value = 2
S.Value = 127
OOPic.Delay = 150

End Sub

Sub RTurn_CODE ( ) 'right turn sub-procedure

S.Value = 128
S.Value = 0
S.Value = 1
S.Value =127
S.Value = 128
S.Value = 0
S.Value = 2
S.Value = 45
OOPic.Delay = 150

End Sub