Last active
February 16, 2020 19:35
-
-
Save samilkorkmaz/cdfa9657bfecd6e9df8c32621f60e362 to your computer and use it in GitHub Desktop.
Simple LED fade with Arduino Nano
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
//Reference: https://www.arduino.cc/en/Tutorial/Fade | |
const int ledPin = 9; | |
int brightness = 0; | |
int change = 5; | |
void setup() { | |
pinMode(ledPin, OUTPUT); | |
Serial.begin(9600); | |
} | |
void loop() { | |
if (brightness <= 0) { | |
Serial.println("Increasing"); | |
change = 5; | |
} | |
if (brightness >= 255) { | |
Serial.println("Decreasing"); | |
change = -5; | |
} | |
brightness = brightness + change; | |
analogWrite(ledPin, brightness); | |
delay(30); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment