Skip to content

Instantly share code, notes, and snippets.

@duggan
Created Oct 20, 2017
Embed
What would you like to do?
Arduino. Fading an LED in and out to produce a glow effect via the PWM pins.
/* Fading an LED in and out to produce a glow effect
via the PWM pins.
*/
int timer = 10;
int pin = 3;
int val = 0;
void setup(){
pinMode(pin, OUTPUT);
}
void loop(){
while (val <= 220) {
analogWrite(pin, val);
val++;
delay(timer);
}
while (val >= 30) {
analogWrite(pin, val);
val--;
delay(timer);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment