Skip to content

Instantly share code, notes, and snippets.

@duggan
Created October 20, 2017 13:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save duggan/e7d5a0dcd6070fad25462c4b334c56ba to your computer and use it in GitHub Desktop.
Save duggan/e7d5a0dcd6070fad25462c4b334c56ba to your computer and use it in GitHub Desktop.
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