Download presentation
Presentation is loading. Please wait.
Published byCarmella Berry Modified over 9 years ago
1
ROBOTC for IFI Timothy Friez Class #4 2/5/08
2
Agenda for Tonight Timers Functions Your Questions
3
Timers ROBOTC has 4 “global timers” These timers start when your vex is powered on –Not necessarily when your program starts Useful for performing specific actions for a set period of time Differs from wait1Msec –Waits: Pause program and keep doing what you were doing –Timing: Do a specific thing for a specific amount of time.
4
How to use Timers Four Timers names : T1, T2, T3, T4 Accessed with the functions: –Time1[] – counts in 1 millisecond increments –Time10[] – counts in 10 millisecond increments –Time100[] – counts in 100 millisecond increments Maximum Counts – 16 bits – 32,768 increments Clearing Timers –ClearTimer(timer);
5
Timer Example
6
Functions Functions are used to access portions of code multiple times and to increase the organization of your code. You can use functions to: –Clean up and shorten your code –Repeat similar portions of code with copy and pasting –Pass Parameters to have portions of code do different things.
7
Limitations of Functions ROBOTC only handles functions of the type “void” –They do not return values to the task calling the function Variable declared inside of functions are “local variables” –You cannot declare a variable in one function and have it accessible in another function.
8
How to use functions Functions are declared like task main, just with a different naming convention –Void taskname() rather than task main() Example: void straight() { Motor[port1] = 100; Motor[port2] = 100; wait1Msec(1000); } Calling this function: –straight();
9
Passing Parameters Passing Parameters lets you send values to a function when you call it. Example: void straight(int speed) { Motor[port1] = speed; Motor[port2] = speed; wait1Msec(1000); } Calling this function: –Straight(100); Separate multiple parameters with commas.
10
Function Example
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.