Sample Programs
Challenges:
o Make a bumper touch cause the robot to back up, turn away from the obstacle, and then resume exploring.
(The BumpNGo program shows one possible solution, including waiting for a bump at the beginning of the
program before starting.)
o Teach the robot how to navigate a (specific) obstacle course.
o “Bounce” along a wall: drive until you touch a wall, then turn away from it and arc back toward it, continuing
to “bounce” along.
BumpNGo
This program is an example of a solution to the first challenge in Program 3. It waits for a bump at the beginning of
the program, then drives forward until it bumps something, at which point it backs up, turns away from the obstacle,
and then continues forward again (continuing to avoid obstacles).
Program 4
Purpose: Learn how to send text from the robot to a PC via a serial connection. The text is received by a program
such as HyperTerminal on Windows.
Program: HelloWorld
Extensions:
o Change the text.
o Send the text once a second.
o Print “open” or “closed” based on the state of the left bumper.
Challenges:
o Print text once a second until either bumper is closed.
o Print “open” or “closed” based on the state of the left bumper, but only print it when the state changes. (Hint:
you will need a variable to remember the current state.)
o Print open and closed messages (as in the previous challenge) for both bumpers.
Program 5
Purpose: Learn how to receive text/commands to the robot from a PC via a serial connection.
Programs: InputChar, InputText
Extension: Change InputText to print a special message when the program receives a ‘?’.
Challenges:
o Use serial input to control the robot, e.g. moving forward, turning left/right, and moving backward in response
to ‘f’, ‘l’, ‘r’, and ‘b’. Have each motion performed for 1 second, then wait for more input.
o Take code from a couple of your previous programs, create functions for those activities, and use input to
determine which activity to perform. Have your program start by sending text with a menu of options.
Program 6
Purpose: Learn how to read analog input values from the light sensors. This program sends the values to a PC via a
serial connection.
Program: ADCPrint
Extension: Add output for the second sensor.
Challenge: Drive forward until the light sensor reads much higher or lower than the initial reading
RemoteControl
This program uses input from the numeric keypad to drive the robot in short bursts. It prints (via serial output) the
values of the light sensors each time a character is received (any character works, not just “driving” keys). This
program combines driving, serial input, serial output, and reading of analog sensors.
Program 7
Purpose: Learn how to read from and write to the EEPROM memory. This program reads and stores the light sensor
values.
Program: EEPROM
Extension: Show sensor values while you are waiting for a key press (e.g. every 200 ms).
11-3-2005 29