Give it to me straight doc, what is an interrupt (external and software if possible)? Thanks, Luke
in short: a high priority call on another line.
interrupts are signals in the processor that indicate that some special state has been reached. This may be a counter reaching a predefined value, a pin changing value (this is external), an ADC conversion is ready etc.
When such state is reached the processor stops its current work and (if defined it ) executes a so called Interrupt Service Routine == ISR. As there can be multiple ISR's every ISR has a certain priority, and the ISR with highest prio is served first.
Normally ISR's are to be kept as short as possible so the main program will not be affected too much and to prevent that the ISR is called before the ISR code is finished. This latter is called reentry and it can make ISR programming more difficult or even impossible. To prevent reentry ISR's are kept short and typically put the "work + parameters" in a queue that is processed by the main code. E.g. receiving bits in a serial protocol can put the bits in an buffer which is processed outside the ISR.
An important thing to know is that the compiler needs to know which variables are used inside an ISR to prevent som optimization tricks. This is done by using the keyword volatile in the variable definition.
Finally, be aware that ISR's have side effects e.g. it can stop the clock (e.g. millis) from ticking.
Cool thanks for the reply! But can you please give an example of how to use it in code i.e to make an led blink once a second unless the interrupt pin goes high in which the led will stay on for 2 seconds the go back to blinking
But can you please give an example of how to use it in code
You can find all the building blocks you need when you go through the attachInterrupt() tutorial/reference pages on this site. It is not that hard.
i.e to make an led blink once a second unless the interrupt pin goes high in which the led will stay on for 2 seconds the go back to blinking
This set of requirements is incomplete. - what must it do when the pin stays high - what must it do when it goes high at a rate of lets say 1Hz (so before the led starts blinking again)
hint 1: use a variable that represents the time the LED needs to go ON and one that indicates when to go off. hint 2: don't forget the keyword volatile ... hint 3: start with blink without delay example
I wrote up a somewhat PIC-oriented explanation of Interrupts in general, which is here: http://www.piclist.com/techref/microchip/ints16Fintro-wcw.htm
"Hardware Interrupts" are a mechanism for providing faster (more immediate) software servicing of particular hardware events. Typically the CPU hardware will check some hardware status after each CPU instruction (for CISC machines for potentially long-running single instructions, sometimes even within a single instruction.) If the hardware needs attention, the CPU will transfer execution to a special piece of software called "the Interrupt Service Routine" (ISR). The ISR can do whatever is necessary to service the hardware, and then it returns to the point where the main software was interrupted, and continues whatever it was doing before.