/*  **********************************************************************
    Interactive C program for controlling a robot

      Creator:  Susan Fox
      Date:  Apr 29, 1998
     
      Contents:  This file contains a program which beeps every time the
                 start button on the robot is pressed.  It also prints out
                 a message on the LCD when that happens.
    **********************************************************************  */


/* --------------------------------------------------------------------- */
/*  This section defines general constants */

int true = 1;
int false = 0;


/*  This section defines constants for the digital inputs and the 
    motor inputs */

int leftMotor = 1;
int rightMotor = 3;


int leftTouch = 7;
int rightTouch = 8;


/* --------------------------------------------------------------------- */
/*  This section defines a few standard speeds for the robot */

int slow = 10;
int half = 50;
int full = 100;


/* --------------------------------------------------------------------- */
/*  This section defines helping procedures to interact with the touch 
    sensors */


/* return true if the given sensor is currently touched */
int touched(int sensor)
{
   return(digital(sensor));
}


/* return true if both sensors are currently being touched, false otherwise */
int bothTouched()
{
   return( touched(leftTouch) && touched(rightTouch));
}


/* --------------------------------------------------------------------- */
/* This section has helping procedures for moving in standard ways */


/* Move forward at the given speed, straight ahead */
void forwardForever(int speed)
{
   motor(leftMotor, speed);
   motor(rightMotor, speed);
}


/* Move forward at the given speed for the given amount of time, where
   time is given in milliseconds */
void forward(int speed, long time)
{
   motor(leftMotor, speed);
   motor(rightMotor, speed);
   msleep(time);
   ao();
}


/* Move straight backward... note speeds should be given as 
   positive values */
void backForever(int speed)
{
   motor(leftMotor, (0 - speed));
   motor(rightMotor, (0 - speed));
}


/* Move straight backward for the given number of milliseconds */
void backward(int speed, long time)
{
   motor(leftMotor, (0 - speed));
   motor(rightMotor, (0 - speed));
   msleep(time);
   ao();
}


/* Stop moving */
void stop()
{
   ao();
}


/* Turn right in place, forever, without moving forward */
void spinRight(int speed)
{
   motor(leftMotor, speed);
   motor(rightMotor, (0 - speed));
}


/* Turn right for the specified number of milliseconds */
void turnRight(int speed, long time)
{
   motor(leftMotor, speed);
   motor(rightMotor, (0 - speed));
   msleep(time);
   ao();
}

/* Turn left in place, forever, without moving forward */
void spinLeft(int speed)
{
   motor(leftMotor, (0 - speed));
   motor(rightMotor, speed);
}


/* Turn left for the specified number of milliseconds */
void turnLeft(int speed, long time)
{
   motor(leftMotor, (0 - speed));
   motor(rightMotor, speed);
   msleep(time);
   ao();
}

/* --------------------------------------------------------------------- */
/*  The following section contains the main program and any helping 
    procedures it needs.  THIS SECTION IS THE ONLY ONE THAT YOU SHOULD
    CHANGE!!!    */


void main()
{
   while (true)   /* loop forever */
   {
      if (start_button())       /* if start button is pressed */
      {                                 
         beep();                       /* then beep and change message */
         printf("Start pushed!!\n");
      }
      else
      {
         printf("Waiting...\n");       /* otherwise print waiting mess. */
      }
   }  /* end of while loop */
}  /* end of main */


