Interrupts

Can anybody please give me the detaied explanation of interrupts in arduino and how to use dem..

For example how to use interrupts for adjusting time of a digital clock..

Interrupts cause the current program to stop what it is currently doing, call a function and do something else for a short time, then return to where it was. They are generally used to react to an input that could happen at any time, such as reading the sensor on a spinning shaft to measure RPM. The function called should execute as fast as possible and must not use any functions that depend on interrupts because they are disabled.

Often the interrupt service routine (ISR) will change the value of a variable to indicate that the interrupt has occurred and maybe set a variable to the time it occurred. The main program code will then deal with the fact that the ISR has been triggered.

For example how to use interrupts for adjusting time of a digital clock..

That does not seem a good use for an interrupt. Where did you get the idea that it was ?

Can anybody please give me the detaied explanation of interrupts in arduino and how to use dem..

Nick Gammon's interrupt tutorial is the place to start.
http://www.gammon.com.au/interrupts

For example how to use interrupts for adjusting time of a digital clock..

When you get done with the tutorial you will understand why an interrupt is not appropriate for that task.

Use "polling" within loop to read user operated push buttons/tactile switches..

Hi UkheliBob…

Thankss for getting in touch… I will surely have to look more into interrupts… And about the idea… Well i got the idea online… I dont remember xactly where… I am jst a starter and is looking forward to building a digital clock with time adjusting facility using some push buttons… In that program i saw, when the SET button is pressed an interrupt is called and then adusting happens in the interrupt loop…

Hi cattledog…

Thanks for replying… And for suggesting the link… I will look into it and get back… And about polling… I dont know about it… May b have to look somewhere i guess…

And about polling.. I dont know about it.

Polling just refers to checking the state of an input pin with digitalRead() each pass through loop. Your code should be written without the use of delay() so that it is "non-blocking" and repeats through the loop several thousand times a second. Under those conditions, a button press by a human will easily be detected by the Arduino.

ashik4316:
I am jst a starter and is looking forward to building a digital clock with time adjusting facility using some push buttons.

That's a bit ambitious for a starting project, but it's a good goal to have in mind to work towards.

You don't need interrupts, though, if you work on not using delay() to manage time.

PaulMurrayCbr:
That's a bit ambitious for a starting project, but it's a good goal to have in mind to work towards.

Hi paulMurrayCbr.. By starter.. I meant starting to do smewhat heavy stuff.. I have earlier done some small projects.. Thanks for contacting.. And yeah.. Its a good goal to have isnt it?? Looking forward to doing it.. And ur suggestions.. I wll defenitly look into it.. Thanks

Thanks cattledog… That explanation helps… But what if my program execution is in some other place when i press the set button. Then that press wont be detected right?? Its a doubt and i might be wrong…!!

Then that press wont be detected right?

That depends on how long you press the switch. You need to hold it at least as long as your longest delay(). Which is, of course, why you shouldn't be using delay() at all.

Yes, your program execution may be in another place, but you should structure things so it doesn't remain somewhere else that long. It's relatively easy at the speeds the processor operates at. Probably about a million times faster than you can press a button.

The problem is dat my main program is quite length.. Also what if i have to detect multiple button presses.. Say like, no of presses implies the hour value to be updated

It doesn’t matter how long your sketch is, just that you write it in such a way that it passes through “loop()” more than, say, a hundred times a second.

ashik4316:
The problem is dat my main program is quite length.. Also what if i have to detect multiple button presses.. Say like, no of presses implies the hour value to be updated

Then it seems not using delay is just what you want. As you can measure time between button presses and make good choices as to when the pressing is done. Doing a delay or interrupt is not required here at all.

Does sound like a fun project.