i am learning
i am trying to figure out how to make 2 LEDs fade but out of phase
here is my fail attempt
/*
*Double fade
*
*
*This sketch is an experement to make two leds fade on and off
*in opposite time to eachother.
*/
int led1 = 6; // the pin that the LED is attached to
int led2 = 5;
int brightness = 0; // how bright the LED is
int fadeAmount = 5; // how many points to fade the LED by
// the setup routine runs once when you press reset:
void setup() {
// declare pin 9 to be an output:
pinMode(led1, OUTPUT);
pinMode(led2, OUTPUT);
}
// the loop routine runs over and over again forever:
void loop() {
// set the brightness of pin 9:
analogWrite(led1, brightness);
delay(15);
analogWrite(led2, brightness);
// change the brightness for next time through the loop:
brightness = brightness + fadeAmount;
// reverse the direction of the fading at the ends of the fade:
if (brightness == 0 || brightness == 255) {
fadeAmount = -fadeAmount ;
}
// wait for 30 milliseconds to see the dimming effect
delay(30);
}
furthermore, i would like to learn from some lessons, but i cant seem to find anything that goes too deep. any advice?