We can´t replace school .
.. there are tutorials, videos, documents, code examples.. just do a search.
It´s a wide area, thus just in short:
Interrupt can - as the name says - interrupt the normal program flow and can do other software parts (ISR) inbetween.
Let´s say you write code (main loop) that is busy doing heavy calculations maybe for 10 seconds (just as an example).
So usually you don´t have the chance to react on key press, UART, ADC ... during this 10 seconds. Which makes the microcontroller look like it was stalled.
Thus you can set up interrupts (many different types).
For example you can set up an interrupt to be raised every 20ms. (And this 20ms are perfectly 20ms, sou you can even design a high precision watch this way)
So every 20ms an additional piece of code is perfomed. It may
* update the software clock counting, to keep it accurate
* look if keys are pressed and released --> and just store the information for later processing
* look if the UART received bytes --> and store the data in a buffer for later processing
These additional code pieces should be short in time, just doing the most essential stuff then returning ... maybe after a couple of microseconds .. to go on processing the usual main code. (in an ISR you avoid delay(), waiting loops and so on)
Let´s say the ISR takes 50 microseconds .. then this means it takes 0.25% of processing power from your main loop.
There are many ways.
Like instead of checking every 20ms whether a key is pressed you may set up a dedicated "pin change interrupt" ... this way you don´t need to reguraily check (poll) the status of the port pins ... it will run the according ISR as soon as the port changes.
Let´s imagine a real life situation:
* you want to read a book ... maybe takes 5 hours (main loop)
* you have your laundry in the machine .. waiting to be finished and put into the dryer (external even interrupt)
* you have a meal on the oven to be stirred every 5 minutes (regular timer interrupt)
With the interrupt method you can focus on reading your book.
But you set up yur washing machine to give an alarm when finished. --> on alarm just move the laundry into the dryer. Then go on reading your book
And you set up your cell phone to beep every five minutes. --> stir the pot, then go back reading your book.
I guess 95% of my programs use interrupts. I like them, they save a lot of processing time and they make an control loop reliably working. Also they help to keep control loop timing constant. In one single project I can run SPI communication, I2C communication, UART communication, 10.000 times per second ADsampling, heater control loop, software clock, data processing, data displaying, data saving, LED blinking, key press, touch control .. all seems to be performed at the same time... with perfect accuracy and without missing a single event.
Klaus