As a newbee, I started my first project with a arduino.The project is a small home control system. (push buttoms and relays to control the lights).With the push buttoms I can switch the light on and off. (working)With one pushbutton I switch all the lights off (working), except one. This one has to go one for X minutes and then go off.This last function will not work. The light relay 14 stays on.When I use the delay fucntion it works, but with the millis() function I struggle.I tested the function in a small sketch and it worked perfect. In the general scetchit refuse to work.

// if the input just went from LOW and HIGH and we've waited long enough // to ignore any noise on the circuit, toggle the output pin and remember // the time if (reading == LOW && previous1 == HIGH && millis() - time > debounce) { if (state1 == HIGH) state1 = LOW; else state1 = HIGH; time = millis(); } digitalWrite(Relay_1, state1); previous1 = reading;

Take a look at the Time library and the associated timeAlarms library that are in the arduino playground. You not only get access to the time so you can turn things on and off based on time of day, but you also get timers that can turn things on and off for certain periods.