Created
November 10, 2020 19:21
-
-
Save shfitz/03f76a6460506c27465e7c1fbb6c7318 to your computer and use it in GitHub Desktop.
This file contains 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
// 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