Skip to content

Instantly share code, notes, and snippets.

@extrasleepy
Created March 31, 2015 16:57
Show Gist options
  • Save extrasleepy/f6567cca2f2e6ab6321a to your computer and use it in GitHub Desktop.
Save extrasleepy/f6567cca2f2e6ab6321a to your computer and use it in GitHub Desktop.
// LED Fadeing Example (PWM) http://arduino.cc/en/Reference/AnalogWrite
void setup() {
pinMode(5, OUTPUT);
pinMode(6, OUTPUT);
pinMode(7, OUTPUT); //NO PWM
pinMode(8, OUTPUT); //NO PWM
pinMode(9, OUTPUT);
pinMode(10, OUTPUT);
pinMode(11, OUTPUT);
pinMode(12, OUTPUT); //NO PWM
}
void loop() {
//------fade in loop--------------
for (int brightness=0;brightness<=254;brightness++){
// set the brightness for the LEDs that support PWM
analogWrite(5, brightness);
analogWrite(6, brightness);
analogWrite(9, brightness);
analogWrite(10, brightness);
analogWrite(11, brightness);
// wait for 2 milliseconds to see the effect
delay(2);
}
//-----end of fade in loop---------
//------fade out loop--------------
for (int brightness=254;brightness>=0;brightness=brightness-5){
// set the brightness for the LEDs that support PWM
analogWrite(5, brightness);
analogWrite(6, brightness);
analogWrite(9, brightness);
analogWrite(10, brightness);
analogWrite(11, brightness);
// wait for 2 milliseconds to see the effect
digitalWrite(12,HIGH)
delay(20);
digitalWrite(12,LOW)
delay(20);
}
//-----end of fade out loop---------
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment