Created
March 7, 2018 00:37
-
-
Save pepasflo/df6427eda9b7372f37a9202d85feda30 to your computer and use it in GitHub Desktop.
An Arduino sketch which fades an LED in and out.
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
int led_pin = 13; | |
void setup() { | |
pinMode(led_pin, OUTPUT); | |
} | |
void loop() { | |
int on_time; | |
int off_time; | |
int period = 1000; | |
for(int i = 1; i <= period; i = i+1) { | |
on_time = i; | |
digitalWrite(led_pin, HIGH); | |
delayMicroseconds(on_time); | |
off_time = period - on_time; | |
digitalWrite(led_pin, LOW); | |
delayMicroseconds(off_time); | |
} | |
for(int i = period; i > 0; i = i-1) { | |
on_time = i; | |
digitalWrite(led_pin, HIGH); | |
delayMicroseconds(on_time); | |
off_time = period - on_time; | |
digitalWrite(led_pin, LOW); | |
delayMicroseconds(off_time); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment