The first assignment (due Friday) has two parts. Part 1 is to build a device that can detect black and white ping-pong balls as they roll by on a slanted track. The program should beep when a ball rolls by a reflectance light sensor, using two different notes to distinguish between black and white. It should also keep track of how many balls of each color it has seen so far. Here is an example (which we will also demo in lab):
As you can see, initially there is not much Lego building involved. We'll make it a little more interesting in a little while, and over the weekend it will get quite a bit more challenging, of course. For now, however, the challenge lies in writing the program to detect and count the balls. First, build a slanted track like the one shown above and attach a light sensor. Get hold of a white and a black ping-pong ball (which we will supply), and observe the sensor's readings as you move the balls past it. Determine the ranges of values corresponding to "no ball", "white ball", and "black ball".
The key for determining a ball's color as it rolls by the sensor is to keep track of the minimum value the sensor returns. To do this, declare two global variables, "min" and "current". (Later, you'll also need two other global variables for counting the number of balls of each color.) Try implementing the following strategy:
Note: Do not use any of the concurrency commands for this assignment. They are not necessary here since no two things happen in parallel.
Once your ball counter works, move on to part 2 of the assignment: add some Lego machinery that actually sorts the balls into two bins! We'll be more specific for the next homework, but this time any mechanism that manages to sort the balls into two different containers will do. Make sure, however, that it sorts properly even if the balls roll by in quick succession.
When you are done, print out your code (names and group number in a comment!) and hand it in Friday at the beginning of class. We will also go around to see your counter and sorter in action during Friday's lab.