Skip to content

Commit

Permalink
Update final_project.ino
Browse files Browse the repository at this point in the history
  • Loading branch information
tiffanalin committed Dec 25, 2022
1 parent 851a393 commit d1d548c
Showing 1 changed file with 26 additions and 26 deletions.
52 changes: 26 additions & 26 deletions final_project/final_project.ino
Original file line number Diff line number Diff line change
Expand Up @@ -16,17 +16,17 @@
//defining motors speed and duration
#define REVERSE_SPEED 200
#define TURN_SPEED 200
#define FORWARD_SPEED 400
#define FORWARD_SPEED 100
#define REVERSE_DURATION 500
#define TURN_DURATION 500
#define FORWARD_DURATION 5000
#define STOP 0
#define STOP_DURATION 100

//setting up ultrasound sensor pins and max distance
#define TRIGGER_PIN 13
#define ECHO_PIN 12
#define MAX_DISTANCE 200
#define TRIGGER_PIN 12
#define ECHO_PIN 11
#define MAX_DISTANCE 200

NewPing sonar(TRIGGER_PIN, ECHO_PIN, MAX_DISTANCE);

Expand All @@ -41,36 +41,36 @@ int lastError = 0;

void setup() {
// for testing ultrasonic sensor:
Serial.begin(115200);
Serial.begin(115200);

}

/*************************************************/

void loop()
{
//learning how ultrasonic sensor works
delay(50); // pause 50ms between pings (about 20 pings/sec)
delay(200); // pause 50ms between pings (about 20 pings/sec)
unsigned int uS = sonar.ping(); // this int gets ping time in microseconds (uS) after sending
Serial.print("Ping: ");
Serial.print(uS / US_ROUNDTRIP_CM); // Convert ping time to distance in cm and print result (0 = outside set distance range)
Serial.println("cm");

// learning how motor setspeeds work with delay
motors.setSpeeds(FORWARD_SPEED,FORWARD_SPEED);
delay(FORWARD_DURATION);

motors.setSpeeds(TURN_SPEED, -TURN_SPEED);
delay(TURN_DURATION);

motors.setSpeeds(FORWARD_SPEED,FORWARD_SPEED);
delay(FORWARD_DURATION);
Serial.print(uS); // Convert ping time to distance in cm and print result (0 = outside set distance range)
Serial.println("qdssd");
if (uS != 0 && uS < 500){
Serial.println("hey");
motors.setSpeeds(STOP, STOP);
// if (random(2)==0)
// {
// motors.setSpeeds(-REVERSE_SPEED, REVERSE_SPEED);
// }
// else
// {
// motors.setSpeeds(REVERSE_SPEED, -REVERSE_SPEED);
// }
//delay(2000);
} else {
Serial.println("yo");
motors.setSpeeds(FORWARD_SPEED, FORWARD_SPEED);
}

motors.setSpeeds(TURN_SPEED, -TURN_SPEED);
delay(TURN_DURATION);

motors.setSpeeds(STOP, STOP);
delay(STOP_DURATION);

motors.setSpeeds(REVERSE_SPEED,REVERSE_SPEED);
delay(REVERSE_DURATION);

}

0 comments on commit d1d548c

Please sign in to comment.