I have a working circuit and program that is triggered whenever a brief low-going pulse to D6 is detected. That IF delivers a sequence of servo arm movements over a period of about 30 s and then does nothing until another pulse is detected. (The program currently uses simple Delay commands.)
I’d now like to add another function: sending D7 high when a brief low-going pulse is detected at D8. Is that simply a matter of a separate, independent IF section following the other one? Or are there any snags/pitfalls I should be aware of please?
Could I extend this multi-purpose approach to as many digital and analog ports as I have on the ATM 328?
If the new pulse occurs when the sketch ud executing delay the pulse will not be detectef.
Get rid if delay. Ude millis.
Look at Robin2d "How to ude millis", or Do deveral things at the same time.
You will probably find this tutorial useful to see how to do two things at once;
Don't forget that you can check out your logic without actually having a circuit attached. Just put in plenty of print statements to see where your code is going and why rather than driving actual outputs.
Millis is quite easy to use once you get the hang of it. With delay you are telling the arduino to do nothing for a set period of time which is not great. Remember that in loop the arduino just runs through your code again and again in order many times a second. If you put a 1s delay then it only loops every 1s and a tiny bit. No other code will run.
It is like watching your oven continuously while your chicken cooks. Not productive use of time. Much better to check when you put the chicken in
unsigned long chickenIn = millis();
Then check your watch regularly to make sure the current time, minus the chickenIn time (declare a variable for this) is not greater than the cookingTime.
If ((millis() - chickenIn) > (cookingTime){
Take chicken out;
}
So your arduino will check every loop to see if the IF statement is true and then perform your action. This allows it to run the rest of your code every loop also so it can check on loads of chickens