Make a sketch using getPhoto() to control the LED using proportional control. He
ID: 3940016 • Letter: M
Question
Make a sketch using getPhoto() to control the LED using proportional control. Here is an outline: Setout=0; Loop for k=1 to 100 Set analogWrite() to out Wait 100ms. Measure V using getPhoto Serial.println V Define err ie e=Vset-V; Define out=P*e; Make sure out is between [0 255]. Serial.println theta and out End loop Find the largest value of P=Pmax that does not causes the V to oscillate. How does it compare to your estimate from part I? What is the value of the error for the largest P that will not oscillate? Plot V and out verses step k from above for Pmax, Pmax/2, and Pmax/10. Add Integral control. Initialize es to 0 before the loop and after line g above add es=es+e; Then change line h to out=P*e+I*res. Find values of P=P0 and I=I0 that give good control. Plot V and out verses step k for (P0.I0), (P0, I0/10), (P0/10, I0). and (P0/10, I0/10). You may have to lengthen the k loop to see the full effects. Give a brief explanation of the plots.Explanation / Answer
/*
Mega analogWrite() test
This sketch fades LEDs up and down one at a time on digital pins 2 through 13.
This sketch was written for the Arduino Mega, and will not work on previous boards.
The circuit:
* LEDs attached from pins 2 through 13 to ground.
created 8 Feb 2009
by Tom Igoe
This example code is in the public domain.
*/
// These constants won't change. They're used to give names
// to the pins used:
const int lowestPin = 2;
const int highestPin = 13;
void setup() {
// set pins 2 through 13 as outputs:
for (int thisPin = lowestPin; thisPin <= highestPin; thisPin++) {
pinMode(thisPin, OUTPUT);
}
}
void loop() {
// iterate over the pins:
for (int thisPin = lowestPin; thisPin <= highestPin; thisPin++) {
// fade the LED on thisPin from off to brightest:
for (int brightness = 0; brightness < 255; brightness++) {
analogWrite(thisPin, brightness);
delay(2);
}
// fade the LED on thisPin from brithstest to off:
for (int brightness = 255; brightness >= 0; brightness--) {
analogWrite(thisPin, brightness);
delay(2);
}
// pause between LEDs:
delay(100);
}
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.