Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Joe Celkos Data And Databases Concepts In Practice

Authors: Joe Celko

1st Edition

1558604324, 978-1558604322

More Books

Students also viewed these Databases questions