Hey guys. I have a pretty long sketch for a project I am working on. Currently it reads the status of one button and then when that button goes high it reads the status of three other switches to see what it needs to do. For example if switch 1 and 2 are high and the button is pushed it would turn on things for 1 and 2. Everything works, however, I have a delay built into it and I want to eliminate with Millis(); I have tried several things with it and haven't gotten it to work. It would work once, but I would have to hold down the button until my "interval" had passed. Here is part of my sketch

The reason you have to hold the button, is because you don't have a Latch. Look at the state change detection code (I can't think of the actual name right now) it's in your example codes. Just implement that into this code and you will be good to go.

The reason you have to hold the button, is because you don't have a Latch. Look at the state change detection code (I can't think of the actual name right now) it's in your example codes. Just implement that into this code and you will be good to go.

The button will still work in the way I want it to with this feature?

Also, do you think this will help fix my problem with it only working one time?

If it works only one time, then it is because of your delay taken so long and not being able to constantly loop the program. Look at the example blink without delay, that example shows that you can run other things in the background and still blink an LED at 1 second intervals.

If it works only one time, then it is because of your delay taken so long and not being able to constantly loop the program. Look at the example blink without delay, that example shows that you can run other things in the background and still blink an LED at 1 second intervals.

I know I can run other things in the background without the delay. With the delay, it looped fine and I could do it repeatedly. It wasn't an issue until I switched it to without a delay that there was a problem. It would stagger startup one time but if I would turn it off then turn it back on the same way I turned it on the first time, it wouldn't stagger the startup. Does that make sense?

By running in the background, I meant you don't need to devote everything to that one particular code. You can run other things and still monitor the condition. If the time is not, say 3 seconds, you can go to another part of the code, and continue to check the time. If the time is 3 seconds then, you run that particular line of code.

With delay(), your loop has to wait until the delay is done to go on, but without an actual delay, it can check other things until the condition is true.

The reason you have to hold the button, is because you don't have a Latch. Look at the state change detection code (I can't think of the actual name right now) it's in your example codes. Just implement that into this code and you will be good to go.

I implemented it in this way, but it doesn't work still. If I repeatedly push the button it will not turn on until the timer has reached it time, but I have to continually push the bottom until the 6 seconds is up.

Time to read, understand, and embrace the blink without delay example. You don't need timers, and you don't need to wait for the timer to expire to read switches again.

The timers are just the millis functions in a library. I understand that I don't need to wait for the count to expire before it reads the switches again. It is constantly reading the switches, but will only work when time has reached 3 or 6 seconds.

// compare the buttonState to its previous state if (buttonState != lastButtonState) { // if the state has changed, increment the counter if (buttonState == HIGH && button1.read() == HIGH && button2.read() == HIGH && button3.read() == HIGH) { contactor1.on(); if(timer1.timeDelay(3000)) contactor2.on(); if(timer2.timeDelay(6000)) contactor3.on(); } } // save the current state as the last state, //for next time through the loop lastButtonState = buttonState;

I fixed up your indenting and got rid of the useless "else".

You are checking for buttonState to change, but ignoring the change if the time isn't up. Which is what you are reporting is happening.

Please post technical questions on the forum, not by personal message. Thanks!