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

Audrino 2 LED fade Write audrino code that has 3 functions and a Loop Iteration

ID: 2250225 • Letter: A

Question

Audrino 2 LED fade

Write audrino code that has 3 functions and a Loop Iteration

The functions include: LED update, to preform calulations, and display debugging info.

The Loop iteration should include a while loop that controls the following actions

>while(redAnalogValue >= 0 and yellowAnalogValue <= 255)

**update leds function call**

**peform calculations function call**

> Calculate the duty cycle percentage

> Calculate the pin voltage values. the pin voltage callulations based on the analog write values. 255 represents a 100% duty cycle, which is 5V.

**display debugging info function call**

> which includes Serially transmiting the data and displaying it in the Serial Monitor.

> analog write values

>duty cycle percentage values

>pin voltage values, using at least 2 decimal places

>current values, using at least 3 decimal places

>The red LED should become dimmer and the yellow LED should become brighter.

And another loop which controls the red LED becomming brighter and the yellow LED getting dimmer.

  

Explanation / Answer

const int Input1A = 0;
const int Input2A = 1;
const int ledL = 3;
const int ledR = 4;


void setup() {
pinMode(Input1A, OUTPUT);
pinMode(Input2A, OUTPUT);


}

void loop() {
for (int fadeValue = 0 ; fadeValue <=255; fadeValue += 5){
analogWrite(ledL, fadeValue);
analogWrite(ledR, fadeValue);
delay(50);
}
for (int fadeValue = 255 ; fadeValue >= 0; fadeValue -= 5) {
analogWrite(ledL, fadeValue);
analogWrite(ledR, fadeValue);
delay(50);
}
digitalWrite(Input1A, LOW);
digitalWrite(Input2A, HIGH);
delay(2000);
digitalWrite(Input1A, HIGH);
digitalWrite(Input2A, LOW);
delay(2000);

}