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 11, 2022
1 parent 1c6cd20 commit 851a393
Showing 1 changed file with 45 additions and 6 deletions.
51 changes: 45 additions & 6 deletions final_project/final_project.ino
Original file line number Diff line number Diff line change
Expand Up @@ -13,25 +13,64 @@
#include <ZumoShield.h>
#include <NewPing.h>

//defining motors speed and duration
#define REVERSE_SPEED 200
#define TURN_SPEED 200
#define FORWARD_SPEED 400
#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

NewPing sonar(TRIGGER_PIN, ECHO_PIN, MAX_DISTANCE);
NewPing sonar(TRIGGER_PIN, ECHO_PIN, MAX_DISTANCE);

//setting up Zumo robot
ZumoBuzzer buzzer;
ZumoReflectanceSensorArray reflectanceSensors;
ZumoMotors motors;
Pushbutton button(ZUMO_BUTTON);
int lastError = 0;

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

void setup() {
// put your setup code here, to run once:
// for testing ultrasonic sensor:
Serial.begin(115200);
}

void loop() {
// put your main code here, to run repeatedly:
delay(50); // Wait 50ms between pings (about 20 pings/sec). 29ms should be the shortest delay between pings.
unsigned int uS = sonar.ping(); // Send ping, get ping time in microseconds (uS).
/*************************************************/

void loop()
{
//learning how ultrasonic sensor works
delay(50); // 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);

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 851a393

Please sign in to comment.