Re: Latching output on Digital I/O ports
If you wish to have the lights continually blinking, this would actually be a good time for multitasking
We can modify the example from the multitasking thread (below) to suite our needs:
We are going to focus on just the light blinking part for now. Since it is a 'secondary' part of the code (the driving being the 'main' part), we will give the blinking its own task
The first line, the #pragma statement, is created by ROBOTC automatically when we set digital port 1 as a digital output (through the Motors and Sensors Setup). Next, we have the actual task; just like task main, task blink gets a name (in this case, 'blink') and a set of parentheses (). We want the lights to continually blink, so we create an infinite loop 'while(true)' that continually runs the code contained inside of it.
The ClearTimer(T1) command clears the value of the T1 timer and resets it back to 0, which then allows us to use it in another while loop to control how long the light is on 'while(time1[T1] < 2000)' (since the time1 command counts in milliseconds, we wait for 2000 milliseconds, which is 2 seconds). Once the light is on for the appropriate amount of time, we clear the T1 timer and use another while loop to control how long the light is turned off (it is almost exactly the same as the previous loop; the only difference is that digitalPort1 (the alias we gave digital port 1 in the Motors and Sensor setup window) is turned off instead of on.
The final pieces of the code (and by far the most important) is the task main. The first thing task main does is starts the 'blink' task using the StartTask() command. We make one final infinite loop and place all other appropriate code inside of it, and place a 10 millisecond wait command at the end of it to prevent the task from taking over the CPU.
When the code is run, both tasks will run *at the same time* and flash the LED (or in your particular case, drive the switch) while at the same time enabling the steering and control code.
For more information on multitasking, definitely take a look at the multitasking thread
and the multitasking tips section of our wiki
(special thanks to community member jpearman for his contributions to multitasking in ROBOTC.
Check out our Blog
! And our Facebook page
Need help? Take a look at our updated help documentation
and the ROBOTC Forums.