1 / 13

Lesson 5: Multiple Tasks & Timers Programming Solutions

Lesson 5: Multiple Tasks & Timers Programming Solutions. Exercise 1 .

nathan
Download Presentation

Lesson 5: Multiple Tasks & Timers Programming Solutions

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Lesson 5: Multiple Tasks & TimersProgramming Solutions

  2. 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.

  3. 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.

  4. 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.

  5. 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.

  6. 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.

  7. Lesson 5: Multiple Tasks & TimersTroubleshooting Tips

  8. Problem 5a What’s wrong with this program?

  9. Solution 5a Remember: Only forks need a fork merge. Task splits need red stop lights at the end of each task.

  10. Problem 5b What’s wrong with this program? Hint: What do all forks need?

  11. 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.

  12. 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?

  13. 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.

More Related