Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

I believe the Arduino uses C code, so please create it in C programming Ive alre

ID: 3870859 • Letter: I

Question

I believe the Arduino uses C code, so please create it in C programming

Ive already completed numbers 2 and 3, im having trouble with 1 and 4. the Servo in number 2 is an FITEC FS90R and in number 3 im using a Tower Pro SG90 Thank you in advance!  

1. Write an Arduino program that controls a DC Motor a. Must include a function that sets the direction of the motor and speed

i. Input Arguments: int Direction, int Speed b. Program should read from the serial port i. Receiving value ‘0’ sets the motor speed to 0

ii. Receiving value ‘9’ sets the motor speed to 255

iii. Values ‘1’ – ‘8’ are equally spaced speeds between 0 - 255

iv. Receiving ‘F’ sets the motor direction to FORWARD

v. Receiving ‘R’ sets the motor direction to REVERSE

2. Write an Arduino program that ramps up and ramps down the speed of the continuous servo

a. Must include a function that sets the speed and direction of the servo

b. Motor should increase speed from stopped to maximum in 5 seconds

3. Write an Arduino program that moves the position servo in 10 degree increments through its entire range of motion.

a. Must include a function that accepts the desired angle as an input argument and sends the appropriate command

b. Pause at each angle for 0.5 seconds

4. Write an Arduino program that combines questions 1-3.

Explanation / Answer

/*
Arduino program
*/

int enablePin = 11;
int in1Pin = 10;
int in2Pin = 9;
int switchPin = 7;
int potPin = 0;

void setup()
{
pinMode(in1Pin, OUTPUT);
pinMode(in2Pin, OUTPUT);
pinMode(enablePin, OUTPUT);
pinMode(switchPin, INPUT_PULLUP);
}

void loop()
{
int speed = analogRead(potPin) / 4;
boolean reverse = digitalRead(switchPin);
setMotor(speed, reverse);
}

void setMotor(int speed, boolean reverse)
{
analogWrite(enablePin, speed);
digitalWrite(in1Pin, ! reverse);
digitalWrite(in2Pin, reverse);
}

Pins are defined and their modes set in the 'setup' function as normal.
In the loop function, a value for the motor speed is found by dividing the analog reading from the pot by 4.
The factor is 4 because the analog reading will be between 0 and 1023 and the analog output needs to be between 0 and 255.
If the button is pressed, the motor will run in forward, otherwise it will run in reverse. The value of the 'reverse' variable is just set to the value read from the switch pin. So, if the button is pressed, this will be False, otherwise it will be True.
The speed and reverse values are passed to a function called 'setMotor' that will set the appropriate pins on the driver chip to control the motor.


void setMotor(int speed, boolean reverse)
{
analogWrite(enablePin, speed);
digitalWrite(in1Pin, ! reverse);
digitalWrite(in2Pin, reverse);
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote