I know that Arduino has 2 hardware interrupts. It's 2 and 3. Now I read somewhere on the internet that there's another type of interrupt that can be used to all Arduino pins. Now how can I use that? Can all have separate interrupts? And what if an interrupt happened while another interrupt is happening. Will the second interrupt be ignored or it will be executed once the first interrupt finished? And what if 5 interrupts happened while another interrupt is happening?
There are (on the uno) three pin change interrupts, one for each port. You can configure which pins can trigger the interrupt, but there's no way to tell which one did unless you save the state of the port and look at which pins changed (which can actually be a very efficient operation: save 1 byte for the "last value" then xor with current value and bitmask with the ones you have enabled).
There's the PCint library which does all of that for you, but it adds quite a bit of overhead you can avoid if you do them yourself. The best resource is probably the atmega datasheet.
If one interrupt is triggered while interrupts are disabled (which is generally the case when executing an interrupt service routine (ISR)), it will be queued up and the ISR will be called after the processor has executed one instruction after interrupts are reenabled. Each vector can be queued up independently, but if a second trigger for the same interrupt happens while they are still disabled, the ISR is still only called once.
If the pin change for two interrupts happen on the exact same clock cycle, the ISRs will be called in the order specified in the atmega datasheet. It is pretty unlikely, however, that two pins setup to interrupt will change within 60 nanoseconds of each other, so you shouldn't worry about that too much.
here is usefull for you to use interrupt change pin..
To handle a pin change interrupt you need to:
Specify which pin in the group. This is the PCMSKn variable (where n is 0, 1 or 2 from the table below). You can have interrupts on more than one pin.
Enable the appropriate group of interrupts (0, 1 or 2)
Supply an interrupt handler as shown above
you can read it full from this website.Gammon Forum very useful source for learning using interrupt
The INT0 and INT1 are interrupt pins that can detect going up, down, state change. The are also on older chips like the ATmega8.
The newer chips, like the ATmega328p have the PCINT interrupts added to almost every pin. However, they are a little different from the old interrupt pins.
The ATmega2560 (used on the Arduiono Mega 2560 board) has a few INT0..INT5 pins and a few PCINT pins and a number of pins that has neither of those.