diff --git a/examples/ExternalWakeup/ExternalWakeup.ino b/examples/ExternalWakeup/ExternalWakeup.ino new file mode 100644 index 0000000..09a7610 --- /dev/null +++ b/examples/ExternalWakeup/ExternalWakeup.ino @@ -0,0 +1,45 @@ +/* + ExternalWakeup + + This sketch demonstrates the usage of External Interrupts (on pins) to wakeup a chip in sleep mode. + Sleep modes allow a significant drop in the power usage of a board while it does nothing waiting for an event to happen. Battery powered application can take advantage of these modes to enhance battery life significantly. + + In this sketch, shorting pin 8 to a GND will wake up the board. + Please note that, if the processor is sleeping, a new sketch can't be uploaded. To overcome this, manually reset the board (usually with a single or double tap to the RESET button) + + This example code is in the public domain. +*/ + +#include "ArduinoLowPower.h" + +// Blink sequence number +// Declare it volatile since it's incremented inside an interrupt +volatile int repetitions = 1; + +// Pin used to trigger a wakeup +const int pin = 8; + +void setup() { + pinMode(LED_BUILTIN, OUTPUT); + // Attach a wakeup interrupt on pin 8, calling repetitionsIncrease when the device is woken up + LowPower.attachInterruptWakeup(pin, repetitionsIncrease, CHANGE); +} + +void loop() { + for (int i = 0; i < repetitions; i++) { + digitalWrite(LED_BUILTIN, HIGH); + delay(500); + digitalWrite(LED_BUILTIN, LOW); + delay(500); + } + // Triggers an infinite sleep (the device will be woken up only by the registered wakeup sources) + // The power consumption of the chip will drop consistently + LowPower.sleep(); +} + +void repetitionsIncrease() { + // This function will be called once on device wakeup + // You can do some little operations here (like changing variables which will be used in the loop) + // Remember to avoid calling delay() and long running functions since this functions executes in interrupt context + repetitions ++; +} \ No newline at end of file diff --git a/examples/TimedWakeup/TimedWakeup.ino b/examples/TimedWakeup/TimedWakeup.ino new file mode 100644 index 0000000..87075a1 --- /dev/null +++ b/examples/TimedWakeup/TimedWakeup.ino @@ -0,0 +1,35 @@ +/* + TimedWakeup + + This sketch demonstrates the usage of Internal Interrupts to wakeup a chip in sleep mode. + Sleep modes allow a significant drop in the power usage of a board while it does nothing waiting for an event to happen. Battery powered application can take advantage of these modes to enhance battery life significantly. + + In this sketch, the internal RTC will wake up the processor every 2 seconds. + Please note that, if the processor is sleeping, a new sketch can't be uploaded. To overcome this, manually reset the board (usually with a single or double tap to the RESET button) + + This example code is in the public domain. +*/ + +#include "ArduinoLowPower.h" + +void setup() { + pinMode(LED_BUILTIN, OUTPUT); + // Uncomment this function if you wish to attach function dummy when RTC wakes up the chip + // LowPower.attachInterruptWakeup(RTC_ALARM_WAKEUP, dummy, CHANGE); +} + +void loop() { + digitalWrite(LED_BUILTIN, HIGH); + delay(500); + digitalWrite(LED_BUILTIN, LOW); + delay(500); + // Triggers a 2000 ms sleep (the device will be woken up only by the registered wakeup sources and by internal RTC) + // The power consumption of the chip will drop consistently + LowPower.sleep(2000); +} + +void dummy() { + // This function will be called once on device wakeup + // You can do some little operations here (like changing variables which will be used in the loop) + // Remember to avoid calling delay() and long running functions since this functions executes in interrupt context +} \ No newline at end of file