Giter Club home page Giter Club logo

Comments (5)

nullboundary avatar nullboundary commented on August 17, 2024

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.

DimMedvedev avatar DimMedvedev commented on August 17, 2024

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.

DimMedvedev avatar DimMedvedev commented on August 17, 2024

but my code is not perfect

from sleep_n0m1.

nullboundary avatar nullboundary commented on August 17, 2024

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.

veer5551 avatar veer5551 commented on August 17, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.