-
Notifications
You must be signed in to change notification settings - Fork 26
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
Using interrupt with sleepDelay in pwrDownMode #16
Comments
Found closed issue by DimMedvedev and your input. Modified the .CPP file with your input , Having issues to get the code complied. Could you please make changes to the library. I can test it and let you know . Thanks. |
Ok, was able to compile modified .cpp and .h files with code from n0m1. My goal : if interrupt button is pressed regardless of time passed wakeup. if no interrupt button is pressed wake up if time has passed. /************************************************************************************
***********************************************************************************/ #include "Sleep_n0m1.h" Sleep* Sleep::pSleep = 0; Sleep::Sleep() } /********************************************************************
********************************************************************/ /********************************************************************
********************************************************************/ calibv = (float) sleepTime/(tt2-tt1); //Serial.println(calibv); /********************************************************************
********************************************************************/ /********************************************************************
********************************************************************/
} /********************************************************************
********************************************************************/
} /********************************************************************
********************************************************************/
} /********************************************************************
********************************************************************/ ++sleepCycleCount; /********************************************************************
********************************************************************/ #if defined(WDP3) isrcalled = 0;
} /********************************************************************
*******************************************************************/ /********************************************************************
*******************************************************************/ /********************************************************************
********************************************************************/ } /********************************************************************
********************************************************************/ /********************************************************************
********************************************************************/ void Sleep::newSleep(unsigned long sleepTime, boolean &abortCycle, int interruptPin, int mode) { int intNum = digitalPinToInterrupt(interruptPin); if(mode == FALLING || mode == LOW) ADCSRA &= ~(1<<ADEN); // adc off ++sleepCycleCount; } /************************************************************************************
***********************************************************************************/ #ifndef SLEEP_H #include <avr/sleep.h> extern "C" void WDT_vect(void) attribute ((signal)); class Sleep { public: friend void WDT_vect(void); Sleep(); /* modes of sleep //------------------------------------------------------ //------------------------------------------------------ //------------------------------------------------------ //------------------------------------------------------ //------------------------------------------------------ //------------------------------------------------------ //------------------------------------------------------ //------------------------------------------------------ //------------------------------------------------------ //------------------------------------------------------ //------------------------------------------------------ void newSleep(unsigned long sleepTime, boolean &abortCycle, int interruptPin, int mode) ; private: int sleepMode_; void setSleepMode(int mode); }; #endif // any help greatly appreciated. |
Hello! |
Hmmm, as the library is now there isn't any simple way to do this. However the sleepPinInterrupt library function could be rewritten to pass in a function for the sleep interrupt handler. Something like this:
Then define that handler function in your sketch before you pass it into the sleepPinInterrupt function. Or use a C++11 lambda function (similar to a anonymous function in javascript) like so:
I haven't tested any of this stuff, but if you can make it work and make a pull request I'll be sure to add it in to the library. |
Hello, trying to keep Arduino in sleep mode until one of the two events have occurred
1 if the desired time has passed , Arduino wakes up does its thing. OR if the time has NOT passed but interrupt pin becomes active Arduino wakes up.
Is this possible?
Thanks for you help.
The text was updated successfully, but these errors were encountered: