Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

I need flowchart for this code : #include UltraSonicDistanceSensor ultrasonic(A0,A1); float distance; // left motor int leftMotorSpeedPin = 3; int leftMotorForwardPin = 4; int leftMotorBackwardPin

I need flowchart for this code :

#include

UltraSonicDistanceSensor ultrasonic(A0,A1);

float distance;

// left motor

int leftMotorSpeedPin = 3;

int leftMotorForwardPin = 4;

int leftMotorBackwardPin = 5;

// right motor

int rightMotorSpeedPin = 11;

int rightMotorForwardPin = 12;

int rightMotorBackwardPin = 13;

void setup() {// Motor Control pins as outputs

pinMode(leftMotorSpeedPin, OUTPUT);

pinMode(leftMotorForwardPin, OUTPUT);

pinMode(leftMotorBackwardPin, OUTPUT);

pinMode(rightMotorSpeedPin, OUTPUT);

pinMode(rightMotorForwardPin, OUTPUT);

pinMode(rightMotorBackwardPin, OUTPUT);

Serial.begin(9600);// Initialize serial communication for debugging

digitalWrite(leftMotorSpeedPin, HIGH);

digitalWrite(rightMotorSpeedPin, HIGH);

}

void loop() {

distance = ultrasonic.measureDistanceCm();

//Use 'CM' for centimeters or 'INC' for inches

Serial.println(distance);// Print distance to serial monitor

if (distance > -1 && distance < 25)

{

stop();

delay(1000);

goBackward();

delay(300);

stop();

delay(1000);

if(random(0, 2) == 0)

{

goLeft();

}

else

{

goRight();

}

delay(500);

stop();

delay(700);

}

else {

goForward();

}

}

// Function to move the vehicle forward

void goForward() {

digitalWrite(leftMotorForwardPin, HIGH);

digitalWrite(leftMotorBackwardPin, LOW);

digitalWrite(rightMotorForwardPin, HIGH);

digitalWrite(rightMotorBackwardPin, LOW);

}

void goBackward() {

digitalWrite(leftMotorForwardPin, LOW);

digitalWrite(leftMotorBackwardPin, HIGH);

digitalWrite(rightMotorForwardPin, LOW);

digitalWrite(rightMotorBackwardPin, HIGH);

}

void stop() { // Function to stop the motors

digitalWrite(leftMotorForwardPin, LOW);

digitalWrite(leftMotorBackwardPin, LOW);

digitalWrite(rightMotorForwardPin, LOW);

digitalWrite(rightMotorBackwardPin, LOW);

}

void goRight() {

digitalWrite(leftMotorForwardPin, HIGH);

digitalWrite(leftMotorBackwardPin, LOW);

digitalWrite(rightMotorForwardPin, LOW);

digitalWrite(rightMotorBackwardPin, LOW);

}

void goLeft() {

digitalWrite(leftMotorForwardPin, LOW);

digitalWrite(leftMotorBackwardPin, LOW);

digitalWrite(rightMotorForwardPin, HIGH);

digitalWrite(rightMotorBackwardPin, LOW);

}

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_2

Step: 3

blur-text-image_3

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

Object Oriented Databases Prentice Hall International Series In Computer Science

Authors: John G. Hughes

1st Edition

0136298745, 978-0136298748

More Books

Students also viewed these Databases questions

Question

differentiate between tasks that should and should not be delegated

Answered: 1 week ago

Question

Does it have correct contact information?

Answered: 1 week ago