Listing 9.2: Cut and paste this program into the code window of the OOPic Multi-language Compiler
Dim S As New oSerialx Sub Main() 'Turn internal "pullup resistor" on 'Assign bump switches to I/O pins 8 and 10 R.IOLine= 31 'reset pin 'Reset the motor controller 'Run "Do...Loop" 'If depressed, back robot up and turn 'Motor 1 'Motor 2 OOPic.Delay = 200 'Reset the motor controller End If 'Motor 1 'Motor 2 OOPic.Delay = 5 Loop End Sub 'A simple program to control two DC motors (through a
'Pololu Micro Dual Serial Motor Controller) and two
'bump switches.
Dim R As New oDio1
Dim LSwitch As New oDio1
Dim RSwitch As New oDio1
OOPic.Pullup = cvTrue
LSwitch.IOLine = 8
LSwitch.Direction = cvInput
RSwitch.IOLine = 10
RSwitch.Direction = cvInput
S.Baud = cv4800
S.IolineS = 30 'motor controller pin
S.Operate = cvTrue
R.Direction = cvOutput
OOPic.Delay = 50
R.Invert 'invert reset pin
R.Invert 'invert reset pin
Do
'Check if either switch is depressed
If (LSwitch.Value = 0) or (RSwitch.Value = 0) then
S.Value = 128 'Start byte
S.Value = 0 'Device type
S.Value = 1 'Motor and direction
S.Value = 120 'Motor speed
S.Value = 128 'Start byte
S.Value = 0 'Device type
S.Value = 2 'Motor and direction
S.Value = 60 'Motor speed
R.Invert 'Invert reset pin
R.Invert 'Invert reset pin
'Send robot forward
S.Value = 128 'Start byte
S.Value = 0 'Device type
S.Value = 0 'Motor and direction
S.Value = 127 'Motor speed
S.Value = 128 'Start byte
S.Value = 0 'Device type
S.Value = 3 'Motor and direction
S.Value = 127 'Motor speed