Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Arduino LED Fade In Out
// Commands for leda -- 1960
int leda = 2; // the PWM pin the LED is attached to
int brightnessa = 0; // how bright the LED is
int fadeAmounta = 18; // how many points to fade the LED by
// Commands for ledb -- 1961
int ledb = 3;
int brightnessb = 0;
int fadeAmountb = 13;
// Commands for ledc -- 1962
int ledc = 4;
int brightnessc = 0;
int fadeAmountc = 7;
// Commands for ledd -- 1963
int ledd = 5;
int brightnessd = 0;
int fadeAmountd = 16;
// Commands for lede -- 1964
int lede = 6;
int brightnesse = 0;
int fadeAmounte = 14;
// Commands for ledf -- 1965
int ledf = 7;
int brightnessf = 0;
int fadeAmountf = 14.5;
// Commands for ledg -- 1966
int ledg = 8;
int brightnessg = 0;
int fadeAmountg = 15;
// Commands for ledh -- 1967
int ledh = 9;
int brightnessh = 0;
int fadeAmounth = 5.99;
// Commands for ledi -- 1968
int ledi = 10;
int brightnessi = 0;
int fadeAmounti = 8;
// Commands for ledj -- 1969
int ledj = 11;
int brightnessj = 0;
int fadeAmountj = 12;
// the setup routine runs once when you press reset:
void setup() {
// declare pin 9 to be an output:
pinMode(leda, OUTPUT);
pinMode(ledb, OUTPUT);
pinMode(ledc, OUTPUT);
pinMode(ledd, OUTPUT);
pinMode(lede, OUTPUT);
pinMode(ledf, OUTPUT);
pinMode(ledg, OUTPUT);
pinMode(ledh, OUTPUT);
pinMode(ledi, OUTPUT);
pinMode(ledj, OUTPUT);
}
// the loop routine runs over and over again forever:
void loop() {
// wait for 30 milliseconds to see the dimming effect
delay(100);
//1960 Code
// set the brightness of pin 2:
analogWrite(leda, brightnessa);
// change the brightness for next time through the loop:
brightnessa = brightnessa + fadeAmounta;
// reverse the direction of the fading at the ends of the fade:
if (brightnessa <= 0 || brightnessa >= 255) {
fadeAmounta = -fadeAmounta;
}
//1961 Code
analogWrite(ledb, brightnessb);
brightnessb = brightnessb + fadeAmountb;
if (brightnessb <= 0 || brightnessb >= 255) {
fadeAmountb = -fadeAmountb;
}
// 1962 Code
analogWrite(ledc, brightnessc);
brightnessc = brightnessc + fadeAmountc;
if (brightnessc <= 0 || brightnessc >= 255) {
fadeAmountc = -fadeAmountc;
}
// 1963 Code
analogWrite(ledd, brightnessd);
brightnessd = brightnessd + fadeAmountd;
if (brightnessd <= 0 || brightnessd >= 255) {
fadeAmountd = -fadeAmountd;
}
//1964 Code
analogWrite(lede, brightnesse);
brightnesse = brightnesse + fadeAmounte;
if (brightnesse <= 0 || brightnesse >= 255) {
fadeAmounte = -fadeAmounte;
}
//1965 Code
analogWrite(ledf, brightnessf);
brightnessf = brightnessf + fadeAmountf;
if (brightnessf <= 0 || brightnessf >= 255) {
fadeAmountf = -fadeAmountf;
}
//1966 Code
analogWrite(ledg, brightnessg);
brightnessg = brightnessg + fadeAmountg;
if (brightnessg <= 0 || brightnessg >= 255) {
fadeAmountg = -fadeAmountg;
}
//1967 Code
analogWrite(ledh, brightnessh);
brightnessh = brightnessh + fadeAmounth;
if (brightnessh <= 0 || brightnessh >= 255) {
fadeAmounth = -fadeAmounth;
}
//1968 Code
analogWrite(ledi, brightnessi);
brightnessi = brightnessi + fadeAmounti;
if (brightnessi <= 0 || brightnessi >= 255) {
fadeAmounti = -fadeAmounti;
}
//1969 Code
analogWrite(ledj, brightnessj);
brightnessj = brightnessj + fadeAmountj;
if (brightnessj <= 0 || brightnessj >= 255) {
fadeAmountj = -fadeAmountj;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.