Question: Assignment 3 : Arduino Code In this assignment, you get to practice writing applied C code against your Arduino. A note on collaboration - -
Assignment : Arduino Code
In this assignment, you get to practice writing applied C code against your Arduino. A note on collaboration it's totally fine and encouraged for you to work together with classmates roommates pets on the assignment. There is nothing wrong with sharing knowledge.
However, as you know I want to see individual effort on the assignment submissions. Share knowledge, not answers. Support and encourage the education of your friends and peers.
WHAT TO DO
Here's a checklist to help you complete this individual effort assignment.
Do not use TinkerCad! It is not a completely accurate simulation of the Arduino.
Connect your Arduino. We'll be working in the Arduino IDE and you'll need to be connected to your actual Arduino to make this code run. You don't need to wire anything up
Paste in the starter code. Much of the code is already written for you! Your job is to complete it to make it run. So go ahead and copy the code block below directly into your Arduino IDE code window. Then modify this code until it runs without any errors. There are lots of hints. You'll be adding your code wherever you see three dots.
Arduino Code
CalcAreaOfCircle
Complete this function so that it computes and returns the area of a circle given the radius.
Hint: look up how to do exponentiation in Arduino C
Hint: look up how to represent Pi in Arduino C no it is not
float CalcAreaOfCirclefloat Radius
float Answer
return Answer;
CalcFactorial
Complete this function so that it returns the factorial of Value.
Hint: look up what a factorial is if you don't remember.
Hint: look up what an "edge case" means.
Hint: look at the preceding function for how to return a value.
Hint: look up how a while loop works.
unsigned int CalcFactorialunsigned int Value
Test for edge case where Value is at or below zero. If so
return zero.
if Value
Ok we know Value is at least one so we can start multiplying factors. Create an unsigned int variable called Answer and set its initial value to
Keep going as long as Value is greater than zero and keep multiplying factors. Use a
while loop to keep repeating this step until Value hits zero.
while Value
Multiply Answer times Value and place the result in Answer.
Subtract one from Value and place the result in Value.
Return final result.
return Answer;
CalcSlopeAndIntercept
Complete this function so it calculates the slope and intercept of a line based on two points.
Notice that it uses passbyreference variables for Slope and Intercept.
Hint: review "pass by reference" to ensure you understand how it works.
Hint: look up what it means to return "void" from a function.
Hint: look up how to calculate the absolute value of a number in Arduino C
void CalcSlopeAndInterceptfloat X float Y float X float Y float &Slope, float &Intercept
Set the Slope and Intercept return parameters to zero before we do anything else.
Slope
Intercept
Test for edge case where XX is zero slope is undefined, line is vertical If we detect
this edge case, just return immediately. Remember we are not supposed to compare floating point values conversion errors Instead, calculate the absolute value of the difference
between X and X and test if it is "close" to zero.
float Difference
if Difference return;
Ok we know we have a nonzero run, so let's calculate it along with rise.
float Rise
float Run
Slope is rise over run.
Slope
Intercept is y mx using X Y for x y
Intercept
We don't need to return anything here, since we've been using passbyreference variables
for Slope and Intercept. So we're done!
Don't change anything after this point. It's the usual Arduino setup and loop functions
but with some test code added.
setup
void setup
Serial.begin;
Serial.printlnArduino Code Practice";
Serial.printArea of circle with radius ;
Serial.printlnCalcAreaOfCircle;
Serial.printFactorial of ;
Serial.printlnCalcFactorial;
float Slope;
float Intercept;
Serial.printLine through and has slope, intercept ;
CalcSlopeAndIntercept Slope, Intercept;
Serial.printSlope; Serial.print; Serial.printlnIntercept;
Serial.println;
loop
void loop
Submit your Assignment as a zip folder containing your Arduino code using DL Feel free to do online research to discover details; it is expected and required.
Assign
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
