Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

/ FadeLED Turns on an LED and fades it in and out // This example code is in the public domain #define LED 13 int

image text in transcribed

/ FadeLED Turns on an LED and fades it in and out // This example code is in the public domain #define LED 13 int duty 19; int speedi0 // LED connected to pin 13 /1 duty is used to change duty cycle // this value determines how quickly // the LED fades in int fade = 0; // indicates whether to fade in or out void setup) // initialize the digital pin as an output. / Pin 13 has an LED connected on most Arduino boards pinMode (LED, OUTPUT) ) // setup void loop() digitalWrite(LED, HIGH) delay (duty) digitalWrite(LED, LOW) delay (20-duty); speedi speedi 1i if (speedi >5) // set the LED on // wait for duty milliseconds /I set the LED off // wait for 20-duty ms /I we do each duty cycle for 11 periods speedl0 if (fade0)[ // reduce the duty cycle // increase the duty cycle // minimum duty cycle reached? duty duty -1: ) else dutyduty li if (duty1) fade 1 if (duty10 fade = 0; // maximum duty cycle reached? // if speed /I 1oop This sketch introduces several new concepts, including integer variables, if-else statements, and arithmetic statements. Try to follow the flow of the sketch. See if you can determine from the sketch how long it should take to complete one fade-in/fade-out cycle. Compare this estimate with the measured time of a fade-in/fade-out cycle. As before, it is best to measure the period by timing several cycles rather than just one Estimate of cycle period from the sketch: Measured cycle period / FadeLED Turns on an LED and fades it in and out // This example code is in the public domain #define LED 13 int duty 19; int speedi0 // LED connected to pin 13 /1 duty is used to change duty cycle // this value determines how quickly // the LED fades in int fade = 0; // indicates whether to fade in or out void setup) // initialize the digital pin as an output. / Pin 13 has an LED connected on most Arduino boards pinMode (LED, OUTPUT) ) // setup void loop() digitalWrite(LED, HIGH) delay (duty) digitalWrite(LED, LOW) delay (20-duty); speedi speedi 1i if (speedi >5) // set the LED on // wait for duty milliseconds /I set the LED off // wait for 20-duty ms /I we do each duty cycle for 11 periods speedl0 if (fade0)[ // reduce the duty cycle // increase the duty cycle // minimum duty cycle reached? duty duty -1: ) else dutyduty li if (duty1) fade 1 if (duty10 fade = 0; // maximum duty cycle reached? // if speed /I 1oop This sketch introduces several new concepts, including integer variables, if-else statements, and arithmetic statements. Try to follow the flow of the sketch. See if you can determine from the sketch how long it should take to complete one fade-in/fade-out cycle. Compare this estimate with the measured time of a fade-in/fade-out cycle. As before, it is best to measure the period by timing several cycles rather than just one Estimate of cycle period from the sketch: Measured cycle period

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

More Books

Students also viewed these Databases questions

Question

What is a journal?

Answered: 1 week ago

Question

Evaluate the definite integral. */2 (T/2 sin(27t/T a) dt a) dt

Answered: 1 week ago

Question

Q.No.1 Explain Large scale map ? Q.No.2 Explain small scale map ?

Answered: 1 week ago

Question

Question Who can establish a Keogh retirement plan?

Answered: 1 week ago