#include

Servo servoLeft;

Servo servoRight;

 

void setup()

{

  delay(1000);

  pinMode(7, INPUT);

  pinMode(5, INPUT);

  servoLeft.attach(13);

  servoRight.attach(12);                      

}

 

void loop()

 

  byte wLeft = digitalRead(5);

  byte wRight = digitalRead(7);

 

 

  if ((wLeft == 0) && (wRight ==0))

  {

    backward(1000);

    turnLeft(800);

  }

  else if (wLeft == 0)

 

 

  {

    backward(1000);

    turnRight(800);

  }

  else if ((wRight ==0))

  {

    backward(1000);

    turnLeft(800);

  }

  else

  {

    forward(20);

 }

}

 

void forward (int time)

{

  servoLeft.writeMicroseconds(1700);

  servoRight.writeMicroseconds(1300);

  delay(time);

}

 

void turnLeft (int time)

{

  servoLeft.writeMicroseconds(1300);

  servoRight.writeMicroseconds(1300);

  delay(time);

}

 

void turnRight (int time)

{

  servoLeft.writeMicroseconds(1700);

  servoRight.writeMicroseconds(1700);

  delay(time);

}

 

void backward (int time)

{

  servoLeft.writeMicroseconds(1300);

  servoRight.writeMicroseconds(1700);

  delay(time);

}

//Tells the arduino to access the servo library programmed into it so it know how to deal with servos.

//Declares the left servo so it arduino knows to use it later./

//Declares the right servo so it arduino can know to use it later.

 

//What arduino does when it boots up.

 

//Tells arduino to wait for 1 sec so I have time to move my hand away.

//Tells arduino that Digital Pin 7 will be used for input.

//Tells arduino that Digital Pin 5 will be used for input.

//Allows servoLeft to start responding to commands and names the servo in slot 13 as "servoLeft".

//Allows servoRight to start responding to commands and names the servo in slot 12 as "servoRight".

 

 

//Arduino will go through the commands in here in a loop.

 

//It tells arduino that when I ask it to compare the byte "wLeft" that wLeft is defined by the digital read of pin 5.

//It tells arduino that when I ask it to compare the byte "wRight" that wRight is defined by the digital read of pin 5.

//If the digital read is zero, that means a whisker has been pressed and energy is going through the whisker

//and to ground as opposed to to either of the digital pins.

//When both whiskers are pressed,

 

//Follow the instructions in the created function "backward" laid out later for 1 sec.

//Follow the instructions in the created function "turnLeft" laid out later for .8 sec.

 

//When the left whisker is pressed,

//(note: Code reads in a linear fashion. If both wLeft and wRight equal zero, it would still meet the requirement for this if statement,

// but since it reads the first if statement first it would execute those commands instead.

 

//A function elaborated later.

//A function elaborated later.

 

//If right whisker pressed,

 

//A function elaborated later.

//A function elaborated later.

 

//If neither is pressed,

 

//A function elaborated later.

 

 

//I use the functions so I don't have to write out the exact details every time.

//Tells arduino what to do when the "forward" function command is used and what to do with the integer in parentheses.

 

//Left servo goes counter-clockwise.

//Right servo goes clockwise.

//For however many milliseconds are in the parentheses.

 

 

//Tells arduino what to do when the "turnLeft" function command is used and what to do with the integer in parentheses.

 

//Left servo goes clockwise.

//Right servo goes clockwise.

//For however many milliseconds are in the parentheses.

 

 

//Tells arduino what to do when the "turnRight" function command is used and what to do with the integer in parentheses.

 

//Left servo goes counter-clockwise.

//Right servo goes counter-clockwise.

//For however many milliseconds are in the parentheses.

 

 

//Tells arduino what to do when the "backward" function command is used and what to do with the integer in parentheses.

 

//Left servo goes clockwise.

//Right servo goes counter-clockwise.

//For however many milliseconds are in the parentheses.