Well, at least you are attempting a fairly simple program to start. The big mistake I ALWAYS make is that I write 2 pages of code before testing any of it. Or I make too many edits. Then I spend a week debugging. I know I should do one thing at a time and test each new function as it is added, but it's easy to get carried away...
Something to think about...there are still some shortcomings with the way I modified your code: The loop that looks for the second and third events should be fairly close to 60 seconds. But...when either of those events is detected, it will ADD 5 seconds to the overall loop time.
Also, you will miss any events that occur while the LED is on or the Horn is on. But that might be okay for your application. I was mainly trying to stay as close to your code as possible so you can understand the changes.
Charles is using a timer and interrupt flag, which is one of those "more elegant" solutions......IF you understand how it all works....otherwise you just might only make things harder for yourself to debug down the road.
Bookmarks