Created
October 19, 2013 19:43
-
-
Save pearlchen/7060577 to your computer and use it in GitHub Desktop.
Use analogWrite() to fade an LED up and down.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
int ledPin = 6; // Note that pin 13 on the Uno doesn't support PWM! | |
int brightness = 0; | |
int stepValue = 1; | |
void setup() { | |
pinMode(ledPin, OUTPUT); // sets the pin as output | |
} | |
void loop() { | |
analogWrite(ledPin, brightness); | |
delay(10); | |
brightness = brightness + stepValue; | |
if ( brightness >= 255 ) { | |
stepValue = -1; | |
}else if ( brightness <= 0 ) { | |
stepValue = 1; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment