Question: Does this code meet these requirements? Your code must include the following: Decision Making. Looping. User - defined functions. The code must include three (
Does this code meet these requirements?
Your code must include the following:
Decision Making.
Looping.
Userdefined functions. The code must include three userdefined functionsno more, no less.
These functions must be usedcalled for main functionality.
At least one function must take at least one parameter. The function must use the parameter.
At least one function must return something. The return must be used by the receiving end.
At least one function that takes at least one parameter and returns something. Both the parameter and return must be used.
No function should be voidvoid In other words, userdefined functions must meet andor above.
BestPractices. Your code must be written with best practices in mind. A few reminders below:
Variables.
Meaningful names and adequate data types.
If you have a value used in multiple places, put it into a variable if it changes or into a "DEFINE" or "CONST" if it does not change and use the variableconstant as you go through the code. For example, if your full speed is instead of using the value in multiple places, store the variable speed This variable can then be used in different places of the code and as "speed for half speed or similar variations. Ensure consistency with the use of the variablesconstants
White space. White space is encouraged for indentations of your code in the right places" and to "break" the code into sections such as variables, function calls, printfscanf statements, operations, etc.
Clean Code. Remove all lines of code that have no functionality other than the required headercomments This includes:
debugging lines
default Arduinoembedded comments
unused variables
code that is not meant to meet the provided requirements.
Please use inprogram "comments by requirement" ONLY and a complete header. NOTE: Overcommented code and comments with functionality descriptions will not be allowed for demos.
#include
#define PINMotorAIN
#define PINMotorPWMB
#define PINMotorPWMA
#define PINMotorBIN
#define PINMotorSTBY
#define ECHOPIN
#define TRIGPIN
#define FULLSPEED
#define CAUTIONSPEED
#define CLOSEENOUGHDISTANCE
#define TOOCLOSEDISTANCE
#define ENOUGHSPACEDISTANCE
#define BACKUPDISTANCE
Servo servo;
int angle ;
struct Distances
int left;
int right;
;
void setup
Serial.begin;
pinModePINMotorPWMA, OUTPUT;
pinModePINMotorPWMB OUTPUT;
pinModePINMotorAIN OUTPUT;
pinModePINMotorBIN OUTPUT;
pinModePINMotorSTBY OUTPUT;
pinModeTRIGPIN, OUTPUT;
pinModeECHOPIN, INPUT;
servo.attach;
servo.writeangle;
void loop
digitalWritePINMotorSTBY HIGH;
float distance readPing;
if distance ENOUGHSPACEDISTANCE
moveForwardFULLSPEED;
else if distance CLOSEENOUGHDISTANCE && distance ENOUGHSPACEDISTANCE
moveForwardCAUTIONSPEED;
else if distance TOOCLOSEDISTANCE && distance CLOSEENOUGHDISTANCE
Distances distances Peer;
if distancesright distances.left
turnRight;
else
turnLeft;
delay;
else
moveBackward;
delay;
Stop;
delay;
Distances Peer
Distances distances;
lookLeft;
delay;
distances.left readPing;
lookStraight;
delay;
lookRight;
delay;
distances.right readPing;
lookStraight;
delay;
return distances;
int readPing
digitalWriteTRIGPIN, LOW;
delayMicroseconds;
digitalWriteTRIGPIN, HIGH;
delayMicroseconds;
digitalWriteTRIGPIN, LOW;
unsigned long durationus pulseInECHOPIN, HIGH;
float distancecm durationus;
Serial.printdistance: ;
Serial.printdistancecm;
Serial.println cm;
return distancecm;
void Stop
digitalWritePINMotorAIN HIGH;
analogWritePINMotorPWMA, ;
digitalWritePINMotorBIN HIGH;
analogWritePINMotorPWMB;
void moveForwardint speed
digitalWritePINMotorAIN HIGH;
analogWritePINMotorPWMA, speed;
digitalWritePINMotorBIN HIGH;
analogWritePINMotorPWMB speed;
void moveBackward
digitalWritePINMotorAIN LOW;
analogWritePINMotorPWMA, FULLSPEED;
digitalWritePINMotorBIN LOW;
analogWritePINMotorPWMB FULLSPEED;
void lookRight
Stop;
servo.write;
void lookStraight
Stop;
servo.write;
void lookLeft
Stop;
servo.write;
void turnLeft
digitalWritePINMotorAIN HIGH;
analogWritePINMotorPWMA, ;
digitalWritePINMotorBIN HIGH;
analogWritePINMotorPWMB;
void turnRight
digitalWritePINMotorAIN HIGH;
analogWritePINMotorPWMA, ;
digitalWritePINMotorBIN HIGH;
analogWritePINMotorPWMB;
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
