OPTIONS: An Exploration of Possibilities

Summer 2000 - EE/CS LEGO Project, Example Program

Here is an example program that tests the motors, the bump switches, and output ports of the LEGO car.

/* ------------------------------------------------------------------------
File: example.c
This program runs the double differential LEGO car using version 4 
of the computer board.
Demonstrates motors, bump switches, output ports

This program uses the Engr/CS 101 robotics library version 2.   Keil C headers 
are not guarded.  If robotics library is used, its header file should be the 
only included file.
---------------------------------------------------------------------------*/

#include "robotics2.h"

/* Constant declarations */
#define LIGHT_PULSE 20  /* About 1 sec */
#define MAX_LED 6
#define REVERSE_TIME 10
#define TURN_TIME 10

void main (void)
{ 
   /* Variable declarations */
   unsigned char i;

   /* Initialization */
   AllStop();
   InitializeSwitches();
   Delay (40);  /* Wait about 2 sec */

   /* Test LEDs */
   for (i = 1; i <= MAX_LED; i++)
   {
      SetOutputPort(i, LOW);    /* Turn on LED i */
      Delay (LIGHT_PULSE);
      SetOutputPort (i, HIGH);  /* Turn off LED i */
      Delay (LIGHT_PULSE);
   }  /* end for */

   /* Test bump sensors */
   while (1)  /* Repeat forever */
   {
      Forward (START);

      if (BumpLeft())  /* Back up and turn right */
      {
         Reverse (START);
         Delay (REVERSE_TIME);
         Reverse (STOP);

         Right (START);
         Delay (TURN_TIME);
         Right (STOP);
      }  /* end if bumped left */

      if (BumpRight())  /* Backup and turn left */
      {
         Reverse (START);
         Delay (REVERSE_TIME);
         Reverse (STOP);

         Left (START);
         Delay (TURN_TIME);
         Left (STOP);
      }  /* end if bumped right */
   }  /* end while */
}  /* end main */


Converted using latex2html on Wed Jun 14 13:00:13 CDT 2000