Question: This is an Arduino Code used to move a small robot forward. The arduino is connected to a Servo and Stepper motors that move the

This is an Arduino Code used to move a small robot forward. The arduino is connected to a Servo and Stepper motors that move the robot. Please provide an explanation of the code and how it achieves this motion.

// CONSTANTS

#include #include

const int stepsPerRevolution = 200; const float DARK_THRESHOLD = 500;

Stepper leftStepper(stepsPerRevolution, 7, 8, 9, 10); Stepper rightStepper(stepsPerRevolution, 3, 4, 5, 6); int pos =255;

Servo myServo;

int amount = 1;

int powerpinLeftUltra = 50; int powerpinRightUltra = 51;

const int trigPinLeft = 33; const int echoPinLeft = 30; const int trigPinRight = 32; const int echoPinRight = 31;

int switch1 = 39; int switch2 = 41; int distanceRight = 0; int distanceLeft = 0; int durationLeft = 0; int durationRight = 0;

// VARIABLES

long duration;

void setup()

{ pinMode(trigPinLeft, OUTPUT); // Sets the trigPin as an Output

pinMode(echoPinLeft, INPUT); // Sets the echoPin as an Input pinMode(trigPinRight, OUTPUT); // Sets the trigPin as an Output pinMode(echoPinRight, INPUT); // Sets the echoPin as an Input

pinMode(switch1, INPUT); pinMode(switch2, INPUT); pinMode(powerpinLeftUltra, OUTPUT); pinMode(powerpinRightUltra, OUTPUT);

const int LIGHT_PIN = A0; // Pin connected to voltage divider output

const float VCC = 5.0; const float R_DIV = 10000;

int spud = 60; int first = 0; int stepCount = 0; int readPin = 3;

leftStepper.setSpeed(spud); rightStepper.setSpeed(spud);

pinMode(readPin, INPUT);

myServo.attach(11);

delay(10);

}

void loop() { while (true) { leftStepper.step(amount); rightStepper.step(amount);}

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!