Comments (5)
Hi DimMedvedev,
The library is currently not really designed to do that. It is however a good idea for an added feature. You could make such a function by re-writing sleepPinInterrupt to set the interrupt, then call sleepDelay inside that function. It could be called sleepDelayOrInterrupt() ?
from sleep_n0m1.
I came up with this method:
`#include <Sleep_n0m1.h>
Sleep sleep;
boolean abortSleep; //cancel sleep cycle
unsigned long sleepTime; //how long you want the arduino to sleep
void setup()
{
Serial.begin(9600);
pinMode(2, INPUT);
abortSleep = false; //can be used to cancel the sleep cycle
sleepTime = 50000; //set sleep time in ms, max sleep time is 49.7 days
}
void knopka()
{
abortSleep = true;
}
void loop()
{
delay(100); ////delays are just for serial print, without serial they can be removed
Serial.println("execute your code here");
Serial.print("sleeping for ");
Serial.println(sleepTime);
delay(100); //delay to allow serial to fully print before sleep
attachInterrupt(0, knopka, CHANGE );
sleep.pwrDownMode(); //set sleep mode
sleep.sleepDelay(sleepTime,abortSleep); //sleep for: sleepTime
detachInterrupt(0);
abortSleep = false;
}
`
from sleep_n0m1.
but my code is not perfect
from sleep_n0m1.
Does it work? Without testing it I wouldn't know. Looks like it might work. I was thinking more about combining the two function in the library.
void Sleep::sleepDelay(unsigned long sleepTime, boolean &abortCycle, int interrupt, int mode) {
int intNum = digitalPinToInterrupt(interruptPin);
if(mode == FALLING || mode == LOW)
{
pinMode (interruptPin, INPUT);
digitalWrite (interruptPin, HIGH);
}
ADCSRA &= ~(1<<ADEN); // adc off
// PRR = 0xEF; // modules off
++sleepCycleCount;
sleepCycleCount = sleepCycleCount % sleepCycleInterval; //recalibrate every interval cycles
if(sleepCycleCount == 1)
{
calibrateTime(sleepTime,abortCycle);
}
else
{
set_sleep_mode(sleepMode_);
//add these two lines
attachInterrupt(interrupt,sleepHandler,mode);
sei(); //make sure interrupts are on!
int trem = sleepWDT(sleepTime*calibv,abortCycle);
/add this line.
detachInterrupt(interrupt);
timeSleep += (sleepTime-trem);
}
// PRR = 0x00; //modules on
ADCSRA |= (1<<ADEN); // adc on
}
Maybe something like this. Its just a guess though.
from sleep_n0m1.
Hello!
I need help regarding the same issue. Device should wakeup from interrupt as well as sleep at the same time. Any help or update regarding the same is greatly appreciated.
Thank you.
from sleep_n0m1.
Related Issues (17)
- Atmega168 - error of compiling HOT 3
- Error on verifying code HOT 7
- Does not work for pin High HOT 4
- Warning on compiling in Arduino IDE 1.6.12
- Sigfox after sleep HOT 2
- Using interrupt with sleepDelay in pwrDownMode HOT 4
- sleepPinInterrupt HOT 1
- Attaching two different interrupts HOT 3
- Oscillator disabled after 1st sleep (except idleMode) ? HOT 1
- Sleep time not working correctly HOT 2
- sleepTime incorrect?
- Could you add compatibility to Due and Zero? HOT 11
- FALLING/LOW not working on bare 328 HOT 3
- Suggestion for the calibration HOT 1
- Working devices? HOT 14
- Arduino ATMEGA2560 sleep not working properly HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from sleep_n0m1.