sspbass:
I’m reading a few tutorials about interrupts but it’s clear to me that I don’t have the proper foundation to apply the knowledge.Would an external interrupt be used initially to start the process and the timer interrupts would take over after that to do the timing and counting operations? Is the portion that does the timing and counting all in a single timer interrupt?
I wish I could just find a good example online that I could modify to fit my needs without needing to re-write the entire thing.
I’ll give it some thought but at present my thinking is thus …
Design the system so it will time for 2 separate shooters, keeping track of all their hit times separately. The system won’t correlate times with specific targets, all targets for a shooter will be lumped together, but you will know when each hit occured. This can be expanded later if desired. A set of 3 switches will be used to initiate/stop the timing functions and to scroll forward/backward through the displays. Two external interrupt pins will be used to sense when targets for the A and B shooter have been hit. That is all “A targets” will trigger one ext pin, all “B targets” will trigger the other pin.
When the start button is pushed another output pin will be used to drive a high efficiency piezo buzzer for some predetermined amount of time (say 0.5 secs) after a random time (I’m not sure how to do this on an Arduino ATM) has elapsed. Perhaps just start with a fixed time and modify the code to randomize later when every thing else is working.
When the elapsed time (above) has … well, elapsed … the present time (from the millis() function) will be stored (and the buzzer will buzz). Every time either external interrupt is triggered (from here on), the interrupt service routine (ISR) that runs for that ext pin will store the present time away in an array specific to that interrupt routine (that is for the A or B shooter). Each array will be able to save away 10 times (more if you want). Timing stops and interrupts are disabled when any of the 3 buttons is pushed.
For the moment, all times are flushed when the start button is pushed to start again or when power goes away. This can be modified later too.
The display will display which shooter, number of shots and times (total and shot-to-shot splits), scrolling as needed from shot to shot, shooter to shooter.
Other “game” modes to be added later when everything is working.
So if that sounds about right as a baseline, I’d have the Arduino power up and initialize and then sit there polling the button inputs. If there are times from a prior run, the code will run to send the proper message/info to the display in accordance with the scrolling buttons. If/when the start/stop button is pushed, you can use a series of delay() calls to get the initial “long” delay desired. This isn’t the most elegant way and will change later but let’s keep it simple to start with. After say … 3 secs of delay … the code will enable the external interrupts and force the buzzer pin to be “on”. Again a simple delay of 0.5 secs should suffice to then turn the buzzer off. There after the main() loop just polls the start/stop and scroll buttons waiting for any push to tell it to stop. The ISR’s take care of all the timing and storage of times. When the stop command had been detected, the ISRs are disabled and the code goes back to the top of the main() loop, awaiting button inputs to scroll the display or start all over again. Sounds relatively straight forward to start with … I think. :o
For the time being I would use the same serial I/O pins to talk to the display as are used to talk to the USB port and your PC. That requires a manual switch in the Tx line to the display, otherwise the whole boot loading process has been know to futz up the display. But doing it this way will make things easier to code up front. Later if wanted, you could do some software emulation of a UART/serial port via the NewSoftSerial library … but again, let’s keep it simple to start with.
So does any of the above sound right or make sense to you ? Or am I talking all goobletygook ? :mrgreen: