First time using interrupts

Ok this is my first time using interrupts so go easy on me
I am going to be building a weather sation using the sparkfun weather meters, fine.

I need to use interrupts, fine.

Firstly, assume arduino Mega 2560

what I don't understand is the Arduino documentation..

External Interrupts: 2 (interrupt 0), 3 (interrupt 1), 18 (interrupt 5), 19 (interrupt 4), 20 (interrupt 3), and 21 (interrupt 2)

am i right in thinking that, the number outside the brackets is the physical pin number
and the interrupt number (the one in brackets) is the number i use in the attachInterrupt method

for example to set 2 interrupts

attachInterrupt(0, myFunc, FALLING)    // sensor attached to pin 2
attachInterrupt(1, myOtherFunc, FALLING)    // sensor attached to pin 3

if i am wrong, can someone please correct me

am i right in thinking that, the number outside the brackets is the physical pin number
and the interrupt number (the one in brackets) is the number i use in the attachInterrupt method

Yes that is correct. :slight_smile:

AH HA!
I love it when I'm right!

now all i need is the sparkfun delivery to arrive, and a 1 10KOhm resistor and I can have a play with the wiring :S

there is some sample code I am going to base my work on (why reinvent the wheel?)

and has the following wiring diagram

                       +5V
                        |
                        <
                        >     10K
                        <   Resistor
                        <
                        >
                        |
 Analog Pin 5-----|
                        |
                        -------| To weather vane
                                | (mystery resistance)
                   -----------|
                   |
                   |
                 -----
                  ---
                   -

am i right in thinking, i can take a feed from the 5+v pin on the arduino, put my resistor in line, then split the line one going to pin 5 (or my chosen pin) and the other to the weather vane.

and GND just goes direct to the Arduino GND pin?

if so, can someone explain how/why this works? so that I understand please?

Yes right again. However you don't need to wait for delivery of your resistor. Just wire it up without and enable the internal pull up resistor, by doing a digithaWrite high to your input pin.

do you mean didtalWrite? even though its an analog input?

DrogoNevets:
do you mean didtalWrite? even though its an analog input?

Analog inputs cannot function as interrupts. What exactly are you trying to accomplish here?

Are you looking for an interrupt to occur when a particular analog signal crosses a certain threshold? If so, you need to set up an external comparator as the source to a digital input that serves as your interrupt.

That, or code a 'software' interrupt that continually reads an Analog input and initiates some function when said threshold is crossed.

Or are you doing something else entirely?

While I agree with the above. Yes the internal pullups work on the analogue inputs as well.

I think you have the 2 use cases mixed up. The resistor is not for an interrupt. It is for a more passive instrument.

And will be connected to analog pin 5, in which case how/why digital write? Its to an analog pin

Analogue inputs will work like digital ones just use the numbers pin 14 for input 0, pin 15 for input 1 and so on.
So yes for analogue input 5 use pin 19.