Intro CS Assignments
Assignments by week:
Fall Term:
Winter Term:
Spring Term:
Monday, February 25
Description
LightMeter
Homework
  • Run the LightMeter program that you created. Answer the following questions in an e-mail to me before the start of next class:
    • What is the minimum sample value you can get from the sensor? What did you point it at to get that value?
    • What is the maximum sample value you can get from the sensor? What did you point it at to get that value?
    • What do you need to point the sensor at in order to get a reading halfway between the minimum and maximum values?
  • Change your LightMeter program to run in "Red" mode. This turns on the red LED on the sensor and puts it in a reflective mode. Hold the sensor close to (about 1cm) several surfaces and answer the following questions in the same e-mail before the start of next class:
    • What surface can you point the sensor at that gives the minimum sample value?
    • What surface can you point the sensor at that gives the maximum sample value?
    • What surface gives a reading roughly halfway between the minimum and maximum values?
Tuesday, February 26
Description
Four-Wall Bot
Homework
  • Design, build, and program the Four-Wall Bot with the following specifications:
    1. When the robot is activated, it should wait for a button press.
    2. Once the button is pressed, the robot should move forward.
    3. The robot continues moving forward until it bumps into something (as detected by one or more touch sensors).
    4. Once the robot bumps into something, it should turn 90 degrees to the right (it may back up a small amount if necessary to enable turning).
    5. The robot should then continue this pattern until it has bumped into 4 things and turned 90 degrees 4 times. Thus, if the robot were started inside a 4-walled room, it should end up facing the same wall it was facing when it started.
  • Download the Four-Wall Bot skeleton class and add it to a new project in Eclipse. I've given you the basic framework for this project, but you'll need to add your own code.
Thursday, February 28
Description
Bot build
Homework
  • Edit the FourWallBot source code and add pre- and post-conditions for each of the methods that require them. Recall that these conditions are meant to describe what must be true about the robot before (pre-) and after (post-) a method runs. They are indended to help you understand how the methods fit together, and will be graded as part of the final program.
  • Once the pre- and post-conditions are done, start writing the code for each of the methods. Code is due to me during class on Friday.
  • If you're interested in playing sounds, here are some hints:

    • Create a WAV file of the sound you want to play. It needs to be in 8-bit or 16-bit PCM format, between 8 and 48kHz, and mono (not stereo). The free program Audacity can export sounds in the correct format.
    • Copy the exported WAV file to your robot by using a command like the following in the terminal:

      scp name_of_sound.wav root@10.2.129.XXX:/home/lejos/

      (substitute your robot's IP address)

    • In your program, play the sample using a line like this:

      brick.getAudio().playSample(new File("/home/lejos/name_of_sound.wav"));
Friday, March 1
Description
Four-Wall Bot
Homework
  • Have a great spring break!