' AdvancedMultiTasking.bas ' A more indepth multitasking tutorial ' by C.D.Odom on 2-14-06 ' www.basicxandrobotics.com ' chris_odom@georgeschool.org Option Explicit Public TurnOnGreen as Boolean ' A toggle to turn on and off the GreenLEDTask task ' Set aside memory space for each task: Dim RedLEDStack(1 to 50) as Byte ' Here, I set aside 50 bytes of space. ' To determine the exact stack space required, ' use Don Kinzer and Mike Perk's bxDism program found at: ' http://home.austin.rr.com/perks/micros/bxDism/ Dim GreenLEDStack(1 to 75) as Byte ' Just to show some variety, I set aside 75 bytes of space. ' To determine the exact stack space required, ' use Don Kinzer and Mike Perk's bxDism program found at: ' http://home.austin.rr.com/perks/micros/bxDism/ Public Sub Main() Dim i as Integer TurnOnGreen = True CallTask "RedLEDTask", RedLEDStack ' The RedLEDTask will run independently from Main CallTask "GreenLEDTask", GreenLEDStack ' The GreenLEDTask will run independently from Main ' While it counts to 500, watch the onboard LEDs. You should notice that ' RedLEDTask and GreenLEDTask do not interrupt the Main program For i = 1 to 500 Debug.Print "i = " & CStr(i) Next TurnOnGreen = False ' Stop the GreenLEDTask Call Delay(10.0) ' Pause for 10 seconds TurnOnGreen = True ' Reset toggle CallTask "GreenLEDTask", GreenLEDStack ' Start GreenLEDTask again End Sub ' ////////////////////// RedLEDTask /////////////////////// Sub RedLEDTask() Do Call PutPin(25,1) ' Turn Red LED off Call Delay(0.2) Call PutPin(25,0) ' Turn Red LED on Call Delay(0.2) Loop End Sub ' ////////////////////// GreenLEDTask /////////////////////// Sub GreenLEDTask() Do While TurnOnGreen Call PutPin(26,0) ' Turn Green LED on Call Delay(0.2) Call PutPin(26,1) ' Turn Green LED off Call Delay(0.2) Loop End Sub