| 
  • If you are citizen of an European Union member nation, you may not use this service unless you are at least 16 years old.

  • Stop wasting time looking for files and revisions. Connect your Gmail, DriveDropbox, and Slack accounts and in less than 2 minutes, Dokkio will automatically organize all your file attachments. Learn more and claim your free account.

View
 

Code for RC Car

Page history last edited by Michael Nardo 8 years, 4 months ago

 

/*

  3 point turn, attempt 1

*/

 

void setup() {                

  // initialize the digital pins as outputs.

  pinMode(3, OUTPUT);   // Forward

  pinMode(4, OUTPUT);   // Backwards

  pinMode(5, OUTPUT);   // Left

  pinMode(6, OUTPUT);   // Right

  Serial.begin(9600);

 

  allOff();

}

 

void driveForward()

{

  digitalWrite(3,LOW); // set direction forward

  digitalWrite (4,HIGH); // turn on drive motor

}

 

void driveBackwards()

{

  digitalWrite(3,HIGH); // set direction forward

  digitalWrite (4,HIGH); // turn on drive motor

}

 

void turnRight()

{

  digitalWrite(5,LOW);

  digitalWrite(6,HIGH);

  delay (2000);

  allOff();

}

 

void turnLeft()

{

  digitalWrite(5,HIGH);

  digitalWrite(6,HIGH);

  delay (2000);

  allOff();

}

 

void allOff()

{ for(int i = 3; i<=6; i++)

  {

    //Serial.println(i);

    digitalWrite(i,LOW);

  }

}

 

 

void loop()

{

//

//  

//  for(int i = 3; i<=6; i++)

//  {

//    Serial.println(i);

//    digitalWrite(i, HIGH);

//    delay(1000);

//    digitalWrite(i,LOW);

//  }

 

 

driveForward();

delay(1000);

allOff();

driveBackwards();

delay(1000);

allOff();

 

// drive forward to right

turnRight();

driveForward();

delay(1000);

turnLeft();

 

//drive forward to left

turnLeft();

driveForward();

delay(1000);

turnLeft();

 

// drive Backwards to right

turnRight();

driveForward();

delay(1000);

turnLeft();

 

//drive forward to left

turnLeft();

driveBackwards();

delay(1000);

turnLeft();

 

//start random driving

 

int x = random (1,11);

 

if (x == 1)

{

  //drive backward to left

  turnLeft();

  driveBackwards();

  delay(2000);

  turnLeft();

}

if (x == 2)

{

  //drive forward to left at random variable

  turnLeft();

  driveForward();

  delay(random(500,3000));

  turnLeft();

}

if (x == 3)

{

  //drive backward to left at random variable

  turnLeft();

  driveBackwards();

  delay(random(500,5000));

  turnLeft();

}

if (x == 4)

{

  //drive backward to right at random variable

  turnRight();

  driveBackwards();

  delay(random(500,5000));

  turnRight();

}

if (x == 5)

{

  //drive forward to right at random variable

  turnRight();

  driveForward();

  delay(random(500,5000));

  turnRight();

}

if (x == 6)

{

  //drive forward to left

  turnLeft();

  driveForward();

  delay(2000);

  turnLeft();

}

if (x = 7)

{

  //drive backward to left

  turnLeft();

  driveBackwards();

  delay(2000);

  turnLeft();

}

if (x = 8)

{

  //drive backward to right

  turnRight();

  driveBackwards();

  delay(2000);

  turnRight();

}

}

 

 

 

Comments (0)

You don't have permission to comment on this page.