I've written a simple beginner's code that works up to a point but I want to add something else. What works so far is that pressing a button causes 4 OUTPUT pins to go HIGH progressively (not in turn) and all four remain HIGH until another (second) button is pressed.
This is what I want to add: If another (third) button is pressed at any time after the sequence has started but before the last OUTPUT pin goes HIGH, a 5th OUTPUT pin goes HIGH without interfering with the main sequence and all 5 outputs stay HIGH until the second button is pressed.
I've tried inserting "if else" into the sequence but I have so little knowledge of programming that I can't get it to work properly.
I could easily do this by hardwiring an external logic gate to the Arduino pins but I'd like to do this within Arduino itself. Can you please point me in the right direction?
The delay() function stops anything happening during the delay period so you cannot read an input to interrupt the sequence during a delay()
You need to use non blocking timing using millis() to do what you want. That will require the sketch to be restructured and a solution cannot just be added to your your existing sketch
Thanks for the quick reply and for the pointers. That's the kind of response I was hoping for.
I'd looked at BlinkWithoutDelay and read about millis, both quite some time ago and not in connection with this project. But I'm such a newbie to programming of any kind that those things didn't enter my mind. I'll look them up again and post again if I have - and probably will have - any questions.
Thanks. Will look into that. Actually, the buttons are to be sensors, not physical buttons.
The Arduino is to be at the heart of a fairly complex system. I designed and built a similar setup about 15 years ago without an MCU. It used fixed logic chips, analog devices, several sensors, a dozen SSRs, etc.
Yes, I completely agree with and am well aware of the points made there.
As I mentioned earlier, I'm a total newbie, not only to Arduino but also to any programmable device. OTOH, I've been designing and building electronics stuff, always from scratch (no off-the-shelf modules, no copying of others' designs), for well over 50 years. Why I'm only entering the world of software-driven devices at this late date is a long story.
Anyway, I've seen plenty of hardware products, including those by giant companies, that are ridiculously messed up and could be greatly simplified and optimised with a better approach without sacrificing performance or reliability.
As far as programming is concerned, I'm just learning to take tottering baby steps now. Even so, I've already seen plenty of convoluted codes written by people with far more knowledge and experience that IMHO would benefit from some streamlining. You can be sure that I'll always keep that in mind as I learn.