Maybe you should show us where you were reading. If we just start prattling on about millis(), timestamps and State Machines, it won't be helpful if you already found good references and still don't understand it.
It's much better if you ask specific, targeted questions. Example, here is the BlinkWithoutDelay sketch, what does this variable do? Or why does this statement get executed at a specific time? Etc.
We're not going to rewrite the sketch for you, just in case you were hoping for that. Not one of this complexity.
Tom, my code is for auto watering garden and should be remotly controlled using a gsm module , so far it works fine with this code except when sending sms to stop the run it does not turn off, else it accepts sms for turning ON the system. an other fonction is to detect water flooding if true or false thrue analoge input A0 and if no water it should turn off system and send notification sms but also not working as well because all the delays , it only detect water before delays between relays. Concerning swich case, I tried but did not work too. Regards
UKHeliBob, thats good worked as wanted except for pushbutton only turn off the the process not on and need the process to be done once not repeating. regards
Now you are asking for something different, which comes as no surprise
Now that you have the basis of what you now say you want so why not have a go at changing the sketch to add the extra features
Things to consider include :
You need to detect when the button becomes pressed rather than when it is pressed. This will allow you to use the button to stop/start the relay switching with alternate button presses. Take a look at the StateChangeDetection example in the IDE
Should the relay switching sequence continue to its end when the button becomes pressed whilst it is running or simply stop ?
What should happen if the relay switching is stopped and restarted by pressing the button ? Should the relay sequence start from the beginning again or continue where it left off ?
You need a means of knowing that the sequence has run to its end and stopped. A boolean variable to control whether it runs repeatedly would be handy
As implemented the relay sequence stops any other code running until it is complete, which may be OK for you, but maybe not. There is a much better way to do the relay sequence that does not block code execution but the relay sequence code needs to be written differently
UKHeliBob many thanks for the effort, I think I will keep my old sketch and use two arduino board to do the job for me , as I wrote I am newbe and need more learning courses. as you can see my posted sketch is good sofar and easy for me to understand. Regards
Paul_B , its been long time trying with this code but result is the same, I know I have to use non blocking method to achieve what i want but still could not figure out how. i will read more am kind ambarressed.
We will continue to advise you of course, but the simple point is that using two Arduinos makes things substantially more difficult as you have to address all the problems of communicating between the two - that is by no means a trivial problem and worse than your present one.
UKHeliBob can you please help modify your suggesset code? I need to turn on relay1 keep it on delay 10 second then turn on relay2 delay 10 sec turn on relay 3 delay 2 sec turn off relay 2 delay 10 sec turn on relay4 delay 2 sec turn off relay 3 delay 10 sec turn on relay5 delay 2 sec turn off relay4 delay 10 sec turn on relay6 delay 2 sec turn off relay5 delay 10 sec turn on relay7 delay 10 sec turn off relay7. if possible as a function. many thanks.