// Timer/Fader 01 // // A delay-free timer for a single LED that fades in and out // Timer variables long timer = 0; int offset = 10; // Change this for faster or slower fades // Pin variable int pwm = 11; // Direction variable int upDown = 1; // pwm value holding variable int val1 = 0; //Setup void setup() { // The standard stuff... Serial.begin(9600); // Setup the serial communications so we can debug pinMode(pwm, OUTPUT); timer = millis(); } // Das Loop... void loop() { // Timer if((timer + offset) < millis() ) { doFade(); timer = millis(); } } // Fade function void doFade() { if(val1 >= 50) { upDown = -1; } // The LED on my board only appears to be getting if(val1 <= 0) { upDown = 1; } // brighter on pwm values up to 50 (out of 255) val1 = val1 + ( 1 * upDown); // so, I've set the max value to change the direction analogWrite(pwm, val1); // to 50. }