Skip to content

Instantly share code, notes, and snippets.

@shfitz
Created November 10, 2020 19:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save shfitz/03f76a6460506c27465e7c1fbb6c7318 to your computer and use it in GitHub Desktop.
Save shfitz/03f76a6460506c27465e7c1fbb6c7318 to your computer and use it in GitHub Desktop.
// constant for the pin the LED is attached to
const int ledPin = 2;
void setup() {
// set the led pin as an output
pinMode(ledPin, OUTPUT);
}
void loop() {
// analogWrite has 8-bits of precision
// it has 256 steps (between 0 -255)
// 0 == 0V while 255 == 3.3V
for (int i = 0; i < 255; i++) {
analogWrite(ledPin, i);
delay(15); // slight delay so we can see the fade
}
for (int i = 255; i > 0; i--) {
analogWrite(ledPin, i);
delay(15);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment