' MultitaskingDemo.bas ' a multitasking tutorial using a Robodyssey Mouse and Gripper ' by C.D.Odom on 5-18-06 ' www.basicxandrobotics.com ' chris_odom@georgeschool.org Option Explicit ' /////////// Globals /////////// ' Pins Const LeftServoPin as Byte = 5 ' Pin #0 on RAMB Const RightServoPin as Byte = 6 ' Pin #1 on RAMB Const GripperPin as Byte = 7 ' Pin #2 on RAMB ' Pulsewidths Const LeftForward as Single = 0.002 Const RightForward as Single = 0.001 Const GripperOpen as Single = 0.0011 Const GripperClosed as Single = 0.00175 ' Allocate space for the stack Dim GripperStack(1 to 150) as Byte ' /////////// Main /////////// Public Sub Main() ' Note Well: Call the task outside of the Do-Loop! ' CallTask "GripperTask", GripperStack ' Is multitasked Do ' Move forward one step Call PulseOut(LeftServoPin, LeftForward, 1) Call PulseOut(RightServoPin, RightForward, 1) Call Delay(0.02) ' a necessary delay Loop End Sub ' /////////// GripperTask /////////// Public Sub GripperTask() Dim i as Integer ' Note Well: There IS a Do-Loop here! Do ' Close the Gripper's jaws For i = 1 to 20 Call PulseOut(GripperPin, GripperClosed, 1) Call Delay(0.02) Next ' Open the Gripper's jaws For i = 1 to 20 Call PulseOut(GripperPin, GripperOpen, 1) Call Delay(0.02) Next Loop End Sub