Sleep mode and power saving functions

MCU Sleep Function:


Set the sleep mode. There are following sleep modes available:

  • 0: IDLE0 (CPU clock off)
  • 1: IDLE1 (CPU clock, AHB clock off)
  • 2: IDLE2 (CPU clock, AHB clock, APB clock off)
  • 3: STANDBY (MCU is off and waiting for Interrupt)

NOTE: To wakeup the device from STANDBY use only LOW or HIGH interrupt events (RISING, FALLING and CHANGE won´t work in this case)


#include "wino.h"
bool wake = true;

void setup() {
  // put your setup code here, to run once:; //Turn off WIFI to save power
  pinMode(8, INPUT); //Pin 4 will be the wakeup pin
  pinMode(2, OUTPUT); //LED is set to output to show if device is sleeping (LED=off)
  attachInterrupt(8, wakeup, HIGH); //Set interrupt to wakup device from sleep

void loop() {
  // put your main code here, to run repeatedly:
  if (wake == false){
    digitalWrite(2, LOW);
    sleep(3); //send MCU into deep sleep
  } else
      digitalWrite(2, HIGH); //Turn on LED to show that device is alive
      wake = false; 
      delay(5000); //after 5 seconds the device will go into sleep mode again

void wakeup() {          //this function is called when the intterupt is changing state
  wake = true;