Skip to content

Instantly share code, notes, and snippets.

@shawngrimes
Last active April 9, 2016 15:11
Show Gist options
  • Save shawngrimes/9fab8fdeb2d180c88c4719ec050b9684 to your computer and use it in GitHub Desktop.
Save shawngrimes/9fab8fdeb2d180c88c4719ec050b9684 to your computer and use it in GitHub Desktop.
Basic Arduino sketch demonstrating analog output with a fade stepping LED.
int ledPin=9; //Store LED pin number in this variable
void setup() {
//No need for setup this time
pinMode(ledPin,OUTPUT); //Setup pin 9 for OUTPUT
}
void loop() {
analogWrite(ledPin,0); //Turn the LED on pin 9 off
delay(500); //Wait 500 milliseconds
analogWrite(ledPin,63); //Turn the LED on pin 9 25% on
delay(500); //Wait 500 milliseconds
analogWrite(ledPin,126); //Turn the LED on pin 9 50% on
delay(500);
analogWrite(ledPin,189); //Turn the LED on pin 9 75% on
delay(500);
analogWrite(ledPin,255); //Turn the LED on pin 9 100% on
delay(500);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment