sleepBlink Example – eS2 2017-03-02T18:55:46+00:00
  1. Home
  2. Knowledge Base
  3. energyShield 2
  4. sleepBlink Example – eS2

This is an example sketch designed to demonstrate the power sleep functionality of the energyShield 2. In this example, the sketch blinks an LED three times and then commands the energyShield to turn the power off for four seconds. After four seconds the energyShield re-enables the power and the sketch restarts.

For more information or to download the Arduino Library check out the eS2 Arduino Library Reference.

/*************************************************************
  sleepBlink - energyShield2                              
  by NightShade Electronics V1.0                          
                                                         
  This sketch blinks the pin 13 LED three times and       
  sleeps for 4 seconds. These results is an approximate   
  20% duty cycle for power comsumption. That means that   
  this blink sketck will run 5 times as long as the       
  standard blink sketch will run on the same battery.         
                                                          
  Created by Aaron D. Liebold                             
  on January 30, 2017

  Distributed under the MIT license
  Copyright 2017 NightShade Electronics
  https://opensource.org/licenses/MIT         
*************************************************************/

// Includes enegyShield2 library files
#include <NS_energyShield2.h>
#include <NS_eS2_Utilities.h>

// Defines NS_energyShield2 class object "es2"
NS_energyShield2 es2;

void setup() {
  es2.begin(); // Initialize energyShield
  es2.setVMPP(-1, 1); // Disable VMPP regulation to allow charging from any source, 7V - 23V

  pinMode(13, OUTPUT);
}

void loop() {
  // Blinks three times
  blink();
  blink();
  blink();

  // Sleeps power for 4 seconds
  es2.sleepSeconds(4);
}

// Blinks LED
void blink() {
  digitalWrite(13, HIGH);
  delay(166);
  digitalWrite(13, LOW);
  delay(166);
}

Was this article helpful?

Related Articles