// Fading LEDs 2 // by Paul Maddox (http://www.Vacoloco.net) an extension of the single LED fading // program by BARRAGAN // and was inspired by TodBots spooky arduino project 3, the Ambient Orb // I wanted to do a similar thing but without the PC attached // // This code fades 3 LEDs in and out, 120 degrees our of phase, // If you make the LEDs Red, Green and Blue you'll get a psychadelic colour change. // #define TOP 90 // tweak 'TOP' value dependant on brightness of LED #define BOTTOM 5 // sets how low to go, should be above zero! int value = 0; // variable to keep the actual value int phase0 = BOTTOM; // Initial Values int phase1 = TOP * 0.33 ; // 120 degress ahead int phase2 = TOP * 0.66 ; // 240 degress ahead int phase0inc = +5; int phase1inc = +5; int phase2inc = +5; int ledpin0 = 9; // light connected to digital pin 9 int ledpin1 = 10; // light connected to digital pin 10 int ledpin2 = 11; // light connected to digital pin 11 void setup() { // nothing for setup } void loop() { analogWrite(ledpin0, phase0); // sets the value (range from 0 to 255) analogWrite(ledpin1, phase1); // sets the value (range from 0 to 255) analogWrite(ledpin2, phase2); // sets the value (range from 0 to 255) phase0 += phase0inc; // increase/descrease values phase1 += phase1inc; phase2 += phase2inc; if (phase0 > TOP) // Check to see if anything is too big phase0inc = -5; if (phase1 > TOP) phase1inc = -5; if (phase2 > TOP) phase2inc = -5; if (phase0 < BOTTOM) // Check to see if anything is too small phase0inc = 5; if (phase1 < BOTTOM) phase1inc = 5; if (phase2 < BOTTOM) phase2inc = 5; delay(50); // Speed of the loop, bigger number = slower }