Skip to content

Instantly share code, notes, and snippets.

@samilkorkmaz
Last active February 16, 2020 19:35
Show Gist options
  • Save samilkorkmaz/cdfa9657bfecd6e9df8c32621f60e362 to your computer and use it in GitHub Desktop.
Save samilkorkmaz/cdfa9657bfecd6e9df8c32621f60e362 to your computer and use it in GitHub Desktop.
Simple LED fade with Arduino Nano
//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