I need help writing this prelab. The Programming language used is C/C++ Heres th
ID: 3761367 • Letter: I
Question
I need help writing this prelab. The Programming language used is C/C++
Heres the instruction via picture:
Thanks for the help in advance!
Figure 9-2. Waveform Control Display Figure 92. Waveform Control Display Lab Assignment: The code for this lab is very simple. It is intended to read the voltage every 10 milliseconds and then send it out to the PWM. Note we will be using the PWM from the Timerl software. Demonstrations of its use can be found on the Files->Hardware Interfacing link, in B_TimerOneDemo.pdf and E_MotorController.pdf Setup Set up your Timer used for 10 milliseconds Set Timerl to have a 500 microseconds period and a PWM on pin 9 Loop if 10 milliseconds has passed Read analog voltage on AO Set Duty Cycle on the PWM pin Turn off pin 13 (the LED) Prelab: Write the program described above and upload it to the Prelab 9 location.Explanation / Answer
#include <iostream>
#include <stdlib.h>
using namespace std;
int main() {
// your code goes here
double voltage[100];
int time = 10, pwm, pin, i, k=0, duty_cycle;
char pin_13[5];
for(i=0; i<=500; i=i+time) {
pwm = 9;
if(i>=10){
cin>>pin_13;
if(pin_13 == "ON") {
k = k+1;
voltage[k] = rand()%230 + 1;
cout<<" Voltage at "<<i<<" ms is "<<voltage[k]<<" volts.";
duty_cycle = pwm;
pin_13 = "OFF";
cout<<"Pin 13 status is : "<<pin_13;
}
}
}
return 0;
}