Can't enter power save mode

1 post / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

This is my code:

 

#ifndef _Power_Save_H_
#define _Power_Save_H_
#include <avr/interrupt.h>
#include <avr/sleep.h>

#define GameONSleepWaitInMS 30*1000
#define GameOFFSleepWaitInMS 10*1000

class powerSaveClass{
    public:
        powerSaveClass(){
            beginUS = 0;
        }
        //active : have job to do or not
        //GameON : if the Game on
        void sleep(bool active,bool GameON){
            if(active){if(beginUS>0)beginUS=0;return;}
            if(beginUS==0) {beginUS = millis();return;}
            if(millis()-beginUS>GameONSleepWaitInMS){
                Serial.println("go to sleep"); delay(2000);
                beginUS = 0;
                if(GameON){set_sleep_mode(SLEEP_MODE_STANDBY);}
                    else {set_sleep_mode(SLEEP_MODE_PWR_DOWN);}
                sleep_enable();
                sleep_cpu();
                sleep_disable();
            }
        }
    private:
        unsigned long beginUS;
};
extern powerSaveClass powerSave;
#endif

Is it right?

While testing, the light of Nano never off, and the debug info never displayed.(with or without UART monitor open)

 

Someone said need to do some works on ISR/interrupts, what does that mean?