Quantcast
Channel: Arduino Forum - Latest topics
Viewing all articles
Browse latest Browse all 15287

LowPower: External wakeup in example

$
0
0

Arduino Uno & Nano...
I try to do my research before coming to this forum. Frequently, the library examples provided on GitHUb contain the answers. However in this case, I've looked all over the web and was not able to find the answer. Through the Arduino IDE Library Manager "More info" link I ended up HERE. This is the example provided with a few of my additions identified with the "//Added" comment.

My question is, how does this code demonstrate the wakeup ability?

// **** INCLUDES *****
#include "LowPower.h"

// Use pin 2 as wake up pin
const int wakeUpPin = 2;
const int ledPin = LED_BUILTIN;  //Added

void wakeUp() {
  digitalWrite(ledPin, HIGH);  //Added
}

void setup() {
  // Configure wake up pin as input.
  // This will consumes few uA of current.
  pinMode(wakeUpPin, INPUT);
  pinMode(ledPin, OUTPUT);  //Added
}

void loop() {
  // Allow wake up pin to trigger interrupt on low.
  // attachInterrupt(ledPin, wakeUp, CHANGE);  //Added
  attachInterrupt(0, wakeUp, LOW);

  // Enter power down state with ADC and BOD module disabled.
  // Wake up when wake up pin is low.
  LowPower.powerDown(SLEEP_FOREVER, ADC_OFF, BOD_OFF);

  // Disable external pin interrupt on wake up pin.
  detachInterrupt(0);

  // Do something here
  // Example: Read sensor, data logging, data transmission.
  digitalWrite(ledPin, HIGH);  //Added
}

6 posts - 4 participants

Read full topic


Viewing all articles
Browse latest Browse all 15287

Trending Articles