Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

The function of wakeUpPin? #108

Open
sxontheway opened this issue Dec 3, 2020 · 2 comments
Open

The function of wakeUpPin? #108

sxontheway opened this issue Dec 3, 2020 · 2 comments

Comments

@sxontheway
Copy link

sxontheway commented Dec 3, 2020

Hi, I am wondering that in "powerDownWakeExternalInterrupt.ino", what is the function of "wakeUpPin = 2" ? Since the variable wakeUpPin does not be invoked anywhere during the loop(). Does it mean that any voltage changes on any pin can wake up the system?

@percz
Copy link

percz commented Dec 7, 2020

Interrupts interrupt whatever loop() is doing.

You can have a long list of lines in a function, but if your interrupt is triggered the processor will jump to whatever function is linked to it ( in this example wakeUp() )

Arduino actually does this for millis(). No matter what else your own loop code is doing, it will very quickly stop at exactly a certain time, update the millis() value a little then return to where it left your own code.

@sxontheway
Copy link
Author

Interrupts interrupt whatever loop() is doing.

You can have a long list of lines in a function, but if your interrupt is triggered the processor will jump to whatever function is linked to it ( in this example wakeUp() )

Arduino actually does this for millis(). No matter what else your own loop code is doing, it will very quickly stop at exactly a certain time, update the millis() value a little then return to where it left your own code.

Thanks for your answer. I searched online and found that the code in line22 of the powerDownWakeExternalInterrupt.ino is usually written as attachInterrupt(digitalPinToInterrupt(interruptPin), wakeUp, LOW);.

I find the definition:
#define digitalPinToInterrupt(p) ((p) == 0 ? 2 : ((p) == 1 ? 3 : ((p) == 2 ? 1 : ((p) == 3 ? 0 : ((p) == 7 ? 4 : NOT_AN_INTERRUPT)))))

Does it means that for Arduino (AVR versions), certain pins have certain interrupt numbers? So if we use attachInterrupt(0, wakeUp, LOW); actually we define pin3 as the interrupt pin?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants