CS 273
Homework 8
Due Wednesday, April 25, 2001
Read text pages 385-393, about the analog input.
Not From the Book
Write a driver for the analog inputs. It should have the following
API
- Synopsis
unsigned char analog(unsigned char analogno)
- Parameter
- Valid values are 1 through 8. Specifies which of the analog
inputs to read (as with the digital input, there is no
equivalent of the broadcast value used for the motor driver)
- Return Value
- Return 255 on an out-of-range input. Otherwise return the value
returned by the analog input.
- Known Bug
- There won't be any way to distinguish an invalid user input from
a value of 255 returned by the sensor. It's very unusual to get
a value of 255 if there is actually a sensor attached to the
analog port, so this is not a serious problem.
When the user requests a value, you'll need to
- Check the user's input
- Turn on the analog subsystem
- Request the analog subsystem read the specified port
- Wait for valid data
- Read the four values returned for the specified port, and
average them.
- Turn off the analog subsystem.
- Return the value to the user.
Lab
Wire up two bumpers for your robot. Use the driver I gave you, and
the driver you wrote for HW7, to write a program that will go forward
unless it hits a wall, and will do obstacle avoidance as discussed in
class if it does run into a wall.
Last modified: Thu Apr 19 17:21:04 MDT 2001