avoid delay

hi all..im still newbie so i wish i could get help from you guys.. im trying to do a coding but since this link did not give the proper code, i hope someone can put a proper code for me to understand it.. here's the link Arduino Playground - AvoidDelay

but since this link did not give the proper code

Define "proper".

What are you trying to do? Have you looked at the blink without delay example?

unsigned long Timer   "ALWAYS use unsigned long for timers, not int"
   (variable declaration outside setup and loop, of course)

if digitalRead==Down 
  then "set timer" Timer = millis , digitalWrite ON
if "timer expired" millis-Timer >= 15000UL
  then digitalWrite Off

(the "UL" after the number is a syntax detail that is important when 
dealing with large numbers in millis and micros, therefore it 
is shown although this is pseudo code)

here as example.. im trying to put this code in debounce actually.. since im cant grasp how the given code should be write, im asking the proper code so i can put it in the debounce

Look in the Blink Without Delay example. Load it. Run it. Read it Understand it. Write your debounce code.

the debounce i use is same as example

const int buttonPin = 2;    // the number of the pushbutton pin
const int ledPin = 13;      // the number of the LED pin

int ledState = HIGH;         // the current state of the output pin
int buttonState;             // the current reading from the input pin
int lastButtonState = LOW;   // the previous reading from the input pin

long lastDebounceTime = 0;  // the last time the output pin was toggled
long debounceDelay = 50;    // the debounce time; increase if the output flickers

void setup() {
  pinMode(buttonPin, INPUT);
  pinMode(ledPin, OUTPUT);

  digitalWrite(ledPin, ledState);

void loop() {
  int reading = digitalRead(buttonPin);

  if (reading != lastButtonState) {
    lastDebounceTime = millis();
  if ((millis() - lastDebounceTime) > debounceDelay) {
    if (reading != buttonState) {
      buttonState = reading;

      if (buttonState == HIGH) {
        ledState = !ledState;
  // set the LED:
  digitalWrite(ledPin, ledState);
  lastButtonState = reading;

so what im to do here is to apply the avoid delay into the given code… here how the thing i want it work

1.the led start with LOW
2.after push button pressed,the led will turn on (HIGH)
3.given time, maybe 20 sec, the led will turn off (LOW)
4.if i push the button within 20 sec, the led will turn off (LOW)
5.after led off (LOW) after 20 sec, i can push the button again to turn led on (HIGH) again

i already read it and try to understand how it work especially

if(currentMillis - previousMillis > interval) {
// save the last time you blinked the LED
previousMillis = currentMillis;

im still unable to understand it

OK, well, millis() returns the time since the last reset of the Arduino (power on, RESET switch, or serial port connect). You can read that value, save it in a variable, then read millis() again to see how long it's been since you last saved the value.

For a better example, see Nick Gammon's excellent tutorial on switches at Gammon Forum : Electronics : Microprocessors : Switches tutorial

In particular, see the section entitled "Debouncing without delay", and while you're there, make sure to look at the switch wiring section, to make sure you have the switch wired correctly.

If you know how long something is supposed to last, like your LED staying on for 20 seconds you can call that Duration.

When the event starts you can write down its StartTime. Then you can keep coming back and check the CurrentTime. Now with some simple math you can know if the event should end.

If the CurrentTime - StartTime < Duration it is NOT time to end the event.

If the CurrentTime - StartTime >= Duration it is time to end the event.

It doesn’t matter how time is kept for this to work. Seconds, milli seconds, micro seconds or even minutes the formula is the same. It’s only the accuracy that varies.

It's only the accuracy that varies.

Precision, I think. The accuracy is a characteristic of the hardware's time-keeping ability.

I sometimes use this technique:

Debouncing switches using the TimedAction library for the Arduino.
see:         http://playground.arduino.cc/Code/TimedAction
#define debounceTime 10UL  //milliseconds

#include <TimedAction.h>  
TimedAction printStuff = TimedAction(1000UL,outputSerial); //every 1000ms Call outputSerial
TimedAction readSwitches = TimedAction(debounceTime,switchInputs); //in this case every 10ms

// ***********************************************
const byte ledPin    = 13;
const byte incSwitch = 8;    //Increment switch pin
const byte decSwitch = 9;    //Decrement switch pin

boolean incSwitchState;      //the last sate of the increment switch
boolean decSwitchState;      //the last state of the decrement switch
int counter;

void setup()

  incSwitchState = digitalRead(incSwitch);
  decSwitchState = digitalRead(decSwitch);

}  //********* END OF setup()*********************

void loop()
  readSwitches.check();      //is it time to check the switches?
  printStuff.check();        //is it time to print to the PC?  

// Other things to be done goes here  
}  //********* END OF loop()**********************

// Functions
void switchInputs()      //Udate all switches
  if (incSwitchState != digitalRead(incSwitch))    //Increment switch code
    incSwitchState = !incSwitchState;              //update the switch state
    //Do stuff
    counter++ ;

  if (decSwitchState != digitalRead(decSwitch))    //Decrement switch code
    decSwitchState = !decSwitchState;              //update the switch state
    //Do stuff
    counter-- ;

  //Other switch code goes here
}  // **** END OF switchIputs() ****

// ***********************************************
void outputSerial()            
   //Other serial o/p code goes here

}  // **** END OF outputSerial() ****

// ***********************************************
//                  END OF CODE
// ***********************************************