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

Please help. This is should be simple for someone with a better understanding of

ID: 3814643 • Letter: P

Question

Please help. This is should be simple for someone with a better understanding of programming but I cannot figure out what I need to change

Write a C++ program for the Arduino UNO where the user can enter the pulse width in MICROSECONDS (1500, for example) and class Servo will be used to send the pulse to pin D10 to control a servo (causing it to rotate to a certain new orientation/position).

I need to write this program which will allow a user to input a pulse width value between 1100-1900 microseconds and the output will cause a potentiometer to turn to corresponding values between 0 and 180 degrees.

This is the set up I have so far but it does not work correctly.

Global Variables /*Write a C++ program (Program 8C) for the Arduino UNO where the user can enter the pulse width in a (1500 for example) and class Servo will be used to send the pulse to pin D10 to control a servo (causing it to rotate to a certain new orientation/position). include Servo servoLeft servoRight. int value 0; float Duty cycle 0.000 float DCV 0.000 void setup Serial begin (9600) Serial print ("Enter a value for the width of the pulse IN MILISECONDS: pin Mode (10, OUTPUT) //servo Left. attach (10) void loop reading until values entered if (Serial available float value Serial parseInt read input from keyboard Serial print ("Invalue read Serial println (value); servoLeft.writeMicroseconds (value) else Serial write ("In Value Entered Serial println (value) analogwrite (10, value); SEND PWM signal to D11 with D value 255 Serial write ("PiM signal sent to D10 "); servoLeft. detach

Explanation / Answer

void setup()
{
Serial.begin(8500);
}
int calc()
{
int num=0,x=0;

for(x;x<=j;x++)
num=num+(buff[x]-48)*pow(10,j-x);

return num;
}
int input,num;
int buff[5];
int j=-1;

void loop()
{
if(Serial.available()>0)
{
input=Serial.read();

if(input==',')
{
num=calc();
j=-1;
Serial.println(num);
}
else
{
j++;
buff[j]=input;
}
}
}