Download presentation
Presentation is loading. Please wait.
1
Global Variables When we introduced variables we defined them inside task main() task main() { int x; statement; …. } The variable x is only defined inside task main. What if we want to use a variable in several tasks?
2
In the following program the variable bump is known and accessible from all the tasks. int bump=0; task main() { …… } task detect_bump() { …… } task watch_timer() { …… }
3
A Task That Keeps Track of Time The RCX provides 4 timers which are set to zero when task main() begins running. Each tick of the timer is 0.1sec or 100ms. The time can be accessed by the statement Timer(n); where n=0,1,2,3. A timer can be reset by using ClearTimer(n); Don’t forget that timers work in ticks of 1/10 of a second, while e.g. the wait command uses ticks of 1/100 of a second. #define TIMER_LIMIT 100 task watch_timer() { while(true) { until(Timer(0) > TIMER_LIMIT); PlayTone(440, 10); ClearTimer(0); bumps = 0; }
4
If I want do something if the number of bumps exceeds some threshold value during a period of time, perhaps 10 seconds, I could use the task from the last slide!
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.