Lesson 5 multiple tasks timers programming solutions
Download
1 / 13

Lesson 5: Multiple Tasks & Timers Programming Solutions - PowerPoint PPT Presentation


  • 59 Views
  • Uploaded on

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

loader
I am the owner, or an agent authorized to act on behalf of the owner, of the copyrighted work described.
capcha
Download Presentation

PowerPoint Slideshow about 'Lesson 5: Multiple Tasks & Timers Programming Solutions' - nathan


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.While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server.


- - - - - - - - - - - - - - - - - - - - - - - - - - E N D - - - - - - - - - - - - - - - - - - - - - - - - - -
Presentation Transcript
Lesson 5 multiple tasks timers programming solutions

Lesson 5: Multiple Tasks & TimersProgramming Solutions


Exercise 1
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
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
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
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
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
Problem 5a

What’s wrong with this program?


Solution 5a
Solution 5a

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


Problem 5b
Problem 5b

What’s wrong with this program?

Hint: What

do all forks

need?


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


ad