diff --git a/final_project/final_project.ino b/final_project/final_project.ino index 2ead01d..0a46366 100644 --- a/final_project/final_project.ino +++ b/final_project/final_project.ino @@ -16,7 +16,7 @@ //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 @@ -24,9 +24,9 @@ #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); @@ -41,7 +41,8 @@ int lastError = 0; void setup() { // for testing ultrasonic sensor: -Serial.begin(115200); + Serial.begin(115200); + } /*************************************************/ @@ -49,28 +50,27 @@ 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); + }