130 likes | 218 Views
Lesson 5: Multiple Tasks & Timers Programming Solutions. Exercise 1 .
E N D
Exercise 1 Write a program with 2 tasks. The first task should monitor one touch sensor forever and play a beep whenever it is pressed. The second task should monitor a second touch sensor forever. When it is touched, motor A should turn on in the forward direction for 1 second, then stop.
Exercise 1: Solution Don’t forget the stop lights at the end of each task. Use 2 different colored Jump/Land pairs for the 2 different tasks. You need a task split Remember to specify different ports for the touch sensors.
Exercise 2 Write a program with 3 tasks. The first task should play 4 beeps. The second task should turn on motor A in the forward direction for 2 seconds, then stop. The third task should turn on motor C in the reverse direction for 5 seconds, then stop.
Exercise 2: Solution If you use a loop, you use 1 less icon. …then split the task again. The secret is to split the tasks... You need to use a numeric constant modifier to get 5 seconds.
Exercise 3: Solution Write a program that beeps for exactly 5 seconds. This is similar to the rotational sensor fork problem. Time is expressed in 10ths of seconds. Remember to reset your timer.
Problem 5a What’s wrong with this program?
Solution 5a Remember: Only forks need a fork merge. Task splits need red stop lights at the end of each task.
Problem 5b What’s wrong with this program? Hint: What do all forks need?
Solution 5b Unfortunately, if you use a task split after a fork, there is NO WAY to merge the fork back together, so just don’t do it.
Problem 5c This program should beep for exactly 5 seconds, but it beeps forever! What’s wrong? Hint: What do you do immediately after you land on the Red Land?
Solution 5c The problem is, the timer was being reset back to 0 every time you landed. In this program, the timer is reset only once at the beginning of the program.