Robot C-program for Group A-1 (light), E5 Fall 2002

Sasha Laundy

David Benitez

Eric Williams

```void main(void)
{
/* Group A1 - Sasha Laundy, David Benitez, and Eric Williams */
/* Seeking the Light */
/* Fall 2002, Swarthmore College */

/* declarations */
int rightbumpflag,leftbumpflag;
int white[4];
int input[4];
int next[4];  /* i think this array is obselete */
int i,j,k,n,m;

rightbumpflag=1;
leftbumpflag=1;

/* take in the brightest spot */
printf("\nPut on light; press start.");
start_press();

for (j = 2; j <= 3; j++)
{
white[j] = analog(j);
}

printf("\nWhere shall I start?");
start_press();

printf("\nHere we go!!!");
motor(0,80);
motor(1,80);

while(input[2] != white[2] && !stop_button()) /* while we're not at the max and while the stop button is not pushed */
{

/* gathering information */
for(m = 2;m <= 3; m++)
{

input[m] = analog(m);
input[3] = 20 + input[3];  /* compensation for difference in sensors */

}

printf("\nL=%d R=%d",input[2], input[3]);

/* while it's too dark and robot's unbumped */
while(input[3] >= 100 && (leftbumpflag == 1 && rightbumpflag == 1))
{
motor(1,100);
motor(0,100);

for(m = 2;m <= 3; m++)
{

input[m] = analog(m); /* same gathering as before */
input[3] = 20 + input[3];
rightbumpflag = digital(8);
leftbumpflag = digital(7);
printf("\nL=%d R=%d",input[2], input[3]);

}

motor(1,100);
motor(0,100);
}

/* execute bump routine */
if(leftbumpflag == 0)
{

beep();beep();
motor(1,-100);
motor(0,-100);
sleep(1.5);

/* turn right */
motor(1,100);
motor(0,-50);
sleep(1.5);

}

if (rightbumpflag == 0)
{

beep();beep();

motor(1,-100);
motor(0,-100);
sleep(1.5);

/*  turn left */

motor(0,100);
motor(1,-50);
sleep(1.5);
}

if (leftbumpflag == 0 && rightbumpflag == 0)
{

beep();beep();
motor(1,-100);
motor(0,-100);
sleep(2.5);

motor(1,100);
motor(0,-50);
sleep(3.0);

}

rightbumpflag = 1;
leftbumpflag = 1;  /* reset, so they're not continually bumped */

if(input[3] >= input[2])  /* if left is darker */
{

motor(0,100);
motor(1,40);

}

motor(0,20);
motor(1,20);

if(input[3]<=input[2])
{
/*  turn left  */

motor(1,100);
motor(0,40);

}

motor(0,20);
motor(1,20);

}

/* finishing sequence that tells us that the robot has found the lightest */

ao();

beep();
beep();
beep();
beep();
beep();

/* victory dance */
motor(1,100);
motor(0,-100);
sleep(6.0);
ao();
beep();

printf("\nDone!");
}
```