Interrupt

I have written code based around the action of an interrupt. What is the simplest code to put the program in a endless loop awaiting for the interrupt to occur? Also I assume that the interrupt returns to the attachInterrupt(a,awaiting,Rising, etc.); Can it be placed anywhere within the program? ex. Inside void loop or void setup. I notice the ISR cannot be placed with a void() of anykind or am I correct? I am monitoring a pin for change so its a hardware interrupt.

Also I assume that the interrupt returns to the attachInterrupt(a,awaiting,Rising, etc.);

No the return from an interrupt is to the place where the program was when the interrupt!

Mark

tnx Mark. I have never used an interrupt on the arduino. Am I correct about the voids? You cant put a void inside another void? I noticed this when I put the ISR in void(loop).

The ISR is a function so you can not place it within another function.

From the point of view of your main code you will just see common variables change value when an interrupt occours.

They are not called voids they are functions, void means this function returns no variable.

So void(setup), void(loop), void(ISR Name) are all functions. Ok would it be considered proper to place my attachInterrupt(Pin,ISR Name, Rising etc.) statement at the bottom of the Void(setup) function then put an endless loop at the very top of the void(loop) function so that the interrupt, when it occurs would return to the beginning of the void(loop). Im wanting to just stop the program at the beginning and wait for an interrupt to occur, returning to the beginning.

A little confused as to the void() structures. They are not functions. I guess I should have put the question more direct. Can I put multiple structures under one main structure like void(loop).

... so that the interrupt, when it occurs would return to the beginning of the void(loop).

NO NO NO Read my first answer to you.

A little confused as to the void() structures

They are not structures!

void loop(){

}

is the declaration of a FUNCTION called loop which returns nothing (void).

loop();

Is the call to the function loop()

Mark

Yes the best advice is to read as long as what you read is plain and straight forth. This is from the reference on this site.

Structure
-setup()
-loop()

This makes things very confusing. I do understand what you guys are telling me and thanks for the advice.

You may find this useful...

The functions can be placed in any order in the code, it does not matter.

You can not detect an interrupt from any function other than from the changes made to common variables.

Put the attach interrupts call anywhere in the setup function.

Interrupts return to exactly the point in the code where the interrupt occours. It is transparent as far as your code is concerned appart from the changes made to common variables. There is no wait for interrupt instruction in the C language.

In the C language a structure is a sort of data format.

stx38834:
Yes the best advice is to read as long as what you read is plain and straight forth. This is from the reference on this site.

Structure
-setup()
-loop()

This makes things very confusing. I do understand what you guys are telling me and thanks for the advice.

I think here "structure" is used in the sense of "this is how your code should be arranged".

Interrupts in C are no different to interrupts in assembler - they return to the next instruction.

In C, data items of different types may be grouped together into "structs"

holmes4:

void loop(){

}




is the declaration of a FUNCTION called loop which returns nothing (void).

No, that's the definition of a function called "loop".