0% found this document useful (0 votes)
63 views2 pages

Dsdsdsds

This code fades an LED connected to pin 9 by using the analogWrite() function to gradually increase or decrease the brightness over time. It initializes pin 9 as an output, sets the initial brightness to 0, and defines the amount to fade the LED each loop. The main loop then writes the brightness value to pin 9, increments the brightness amount, and reverses direction when the brightness reaches 0 or 255, waiting 30ms between loops to see the dimming effect.

Uploaded by

api-277007871
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as ODT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
63 views2 pages

Dsdsdsds

This code fades an LED connected to pin 9 by using the analogWrite() function to gradually increase or decrease the brightness over time. It initializes pin 9 as an output, sets the initial brightness to 0, and defines the amount to fade the LED each loop. The main loop then writes the brightness value to pin 9, increments the brightness amount, and reverses direction when the brightness reaches 0 or 255, waiting 30ms between loops to see the dimming effect.

Uploaded by

api-277007871
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as ODT, PDF, TXT or read online on Scribd
You are on page 1/ 2

/*

Fade
This example shows how to fade an LED on pin 9
using the analogWrite() function.
This example code is in the public domain.
*/
int led = 9;

// the pin that the LED is attached to

int brightness = 0;
int fadeAmount = 5;
LED by

// how bright the LED is


// how many points to fade the

// the setup routine runs once when you press reset:


void setup() {
// declare pin 9 to be an output:
pinMode(led, OUTPUT);
}
// the loop routine runs over and over again forever:
void loop() {
// set the brightness of pin 9:
analogWrite(led, brightness);
// change the brightness for next time through the loop:

brightness = brightness + fadeAmount;


// reverse the direction of the fading at the ends of the
fade:
if (brightness == 0 || brightness == 255) {
fadeAmount = -fadeAmount ;
}
// wait for 30 milliseconds to see the dimming effect
delay(30);
}

You might also like