I need to be able to raise a digital output port to the high condition and keep it high until I shut it off. The processor needs to execute other code (eg. steering the robot) while the output port is latched high. Please tell me what commands do this. Thank you.

Tue Oct 23, 2012 2:37 pm

magicode

Moderator

Joined: Tue Sep 14, 2010 9:19 pmPosts: 496

Re: Latching output on Digital I/O ports

SensorValue[port] = 0 and SensorValue[port] = 1 can be used to set a digital port high or low.

_________________sudo rm -rf /

Tue Oct 23, 2012 2:43 pm

JohnWatson

Site Admin

Joined: Thu May 24, 2012 12:15 pmPosts: 722

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:

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.

Who is online

Users browsing this forum: No registered users and 2 guests

You cannot post new topics in this forumYou cannot reply to topics in this forumYou cannot edit your posts in this forumYou cannot delete your posts in this forumYou cannot post attachments in this forum