Created
November 16, 2016 00:30
-
-
Save harleauxcarrera/438e1724a17a573cb53eddcca021404e to your computer and use it in GitHub Desktop.
CodeV.1_MicroMouse
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
int LeftMotorForward = 10; // Pin 10 has Left Motor connected on Arduino boards. | |
int LeftMotorReverse = 9; // Pin 9 has Left Motor connected on Arduino boards. | |
int RightMotorForward = 12; // Pin 12 has Right Motor connected on Arduino boards. | |
int RightMotorReverse = 13; // Pin 13 has Right Motor connected on Arduino boards. | |
#define trigPin 12 // define the pins of your sensor | |
#define echoPin 13 | |
//////////////////////////////////////////////////////////////////////////////////////////////////////////////// | |
//int RightMotorForward, LeftMotorForward = 12; // Pin 12 has Right Motor connected on Arduino boards.///// in this process the plan is to eliminate wires as much posible | |
//int RightMotorReverse, LeftMotorForward = 13; // Pin 13 has Right Motor connected on Arduino boards. | |
///////////////////////////////////////////////////////////////////////////////////////////////////////////// | |
//----------------------------------------------------------------------------- | |
void setup(){ | |
Serial.begin(9600); // begin serial communitication data read rate 9600 bps | |
pinMode(trigPin, OUTPUT);// set the trig pin to output (Send sound waves)// current output 12 | |
pinMode(echoPin, INPUT);// set the echo pin to input (recieve sound waves) // current input of pin 13 | |
pinMode(LeftMotorForward, OUTPUT); // initialize the pin as an output. | |
pinMode(RightMotorForward, OUTPUT); // initialize the pin as an output. | |
pinMode(LeftMotorReverse, OUTPUT); // initialize the pin as an output. | |
pinMode(RightMotorReverse, OUTPUT); // initialize the pin as an output. | |
// ---------------------------------- | |
} | |
//----------------------------------------------------------------------------- | |
// The following Loop is to make the Robot go staright | |
void loop() | |
{ | |
long duration, distance; // start the scan | |
digitalWrite(trigPin, LOW); | |
delayMicroseconds(2); // delays are required for a succesful sensor operation. | |
digitalWrite(trigPin, HIGH); | |
delayMicroseconds(10); //this delay is required as well! | |
digitalWrite(trigPin, LOW); | |
duration = pulseIn(echoPin, HIGH); | |
distance = (duration/2) / 29.1;// convert the distance to centimeters. | |
if (distance < 15)/*if there's an obstacle 25 centimers, ahead, do the following: */ { | |
Serial.println ("Close Obstacle detected!" ); | |
Serial.println ("Obstacle Details:"); | |
Serial.print ("Distance From Robot is " ); | |
Serial.print ( distance); | |
Serial.print ( " CM!");// print out the distance in centimeters. | |
Serial.println (" The obstacle is declared a threat due to close distance. "); | |
Serial.println (" Turning !"); | |
//servo1.write(266); | |
digitalWrite(RightMotorForward, HIGH); // turn the Right Motor OFF | |
digitalWrite(LeftMotorReverse, HIGH); | |
}// end of if | |
//----------------------------------------------------------------------------- | |
else{ | |
Serial.println("no obstacle"); | |
digitalWrite(RightMotorForward, HIGH); // turn the Right Motor OFF | |
digitalWrite(LeftMotorForward, HIGH); | |
} | |
} | |
// void Rightturn(); | |
// | |
// digitalWrite(RightMotorForward, LOW); // turn the Right Motor OFF | |
// digitalWrite(LeftMotorForward, HIGH); // turn the Left Motor ON | |
// // here we can implement a for loop to calculate the ammount to turn | |
// delay(3000); // wait for 10 seconds | |
// | |
// digitalWrite(RightMotorForward,LOW); // turn the Right Motor OFF | |
// digitalWrite(LeftMotorForward, LOW); // turn the Left Motor OFF | |
// delay(3000); // wait for 10 seconds | |
////----------------------------------------------------------------------------- | |
// void Leftturn(); | |
// | |
// digitalWrite(RightMotorForward, HIGH); // turn the Right Motor ON | |
// digitalWrite(LeftMotorForward, LOW); // turn the Left Motor OFF | |
// delay(3000); // wait for 10 seconds | |
// | |
// digitalWrite(RightMotorForward,LOW); // turn the Right Motor OFF | |
// digitalWrite(LeftMotorForward, LOW); // turn the Left Motor OFF | |
// delay(3000); // wait for 10 seconds | |
////----------------------------------------------------------------------------- | |
// void Reverse(); | |
// | |
// digitalWrite(RightMotorReverse, HIGH); // turn the Right Motor ON | |
// digitalWrite(LeftMotorReverse, HIGH); // turn the Left Motor ON | |
// // delay(10000); // wait for a 10 seconds | |
// | |
// digitalWrite(RightMotorReverse, LOW); // turn the Right Motor ON | |
// digitalWrite(LeftMotorReverse, LOW); // turn the Left Motor ON | |
// delay(3000); // wait for a 3 seconds | |
////----------------------------------------------------------------------------- | |
// | |
// void Allstop(); | |
// | |
// digitalWrite(RightMotorReverse, LOW); // turn the Right Motor off | |
// digitalWrite(LeftMotorReverse, LOW); // turn the Left Motor off | |
// //delay(3000); // wait for 10 seconds | |
//// digitalWrite(RightMotorForward,LOW); // turn the Right Motor OFF | |
//// digitalWrite(LeftMotorForward, LOW); // turn the Left Motor OFF | |
//// delay(1); // wait for 10 seconds | |
////---------- | |
// } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment