|
| 1 | +/* |
| 2 | + Blink_sleep |
| 3 | + Turns on an LED on for one second, then off for one second, until the time to go to sleep runs out. |
| 4 | + You can wake up the feather by pressing a key/switch connecting the WAKE_LOW_PIN to GND and the WAKE_HIGH_PIN to 3.3V (VCC) |
| 5 | +
|
| 6 | + Based on the blinky arduino example |
| 7 | + |
| 8 | + This example code is in the public domain. |
| 9 | +
|
| 10 | + created 19 Jan 2010 |
| 11 | + by Pierre Constantineau |
| 12 | +
|
| 13 | +*/ |
| 14 | +#include <bluefruit.h> |
| 15 | + |
| 16 | +#define WAKE_LOW_PIN PIN_A0 |
| 17 | +#define WAKE_HIGH_PIN PIN_A1 |
| 18 | + |
| 19 | +#define SLEEPING_DELAY 30000 // sleep after 30 seconds of blinking |
| 20 | + |
| 21 | +void gotoSleep(unsigned long time) |
| 22 | +{ |
| 23 | + // shutdown when time reaches SLEEPING_DELAY ms |
| 24 | + if ((time>SLEEPING_DELAY)) |
| 25 | + { |
| 26 | + // to reduce power consumption when sleeping, turn off all your LEDs (and other power hungry devices) |
| 27 | + digitalWrite(LED_BUILTIN, LOW); |
| 28 | + |
| 29 | + // setup your wake-up pins. |
| 30 | + pinMode(WAKE_LOW_PIN, INPUT_PULLUP_SENSE); // this pin (WAKE_LOW_PIN) is pulled up and wakes up the feather when externally connected to ground. |
| 31 | + pinMode(WAKE_HIGH_PIN, INPUT_PULLDOWN_SENSE); // this pin (WAKE_HIGH_PIN) is pulled down and wakes up the feather when externally connected to 3.3v. |
| 32 | + |
| 33 | + // power down nrf52. |
| 34 | + sd_power_system_off(); // this function puts the whole nRF52 to deep sleep (no Bluetooth). If no sense pins are setup (or other hardware interrupts), the nrf52 will not wake up. |
| 35 | + } |
| 36 | +} |
| 37 | + |
| 38 | +// the setup function runs once when you press reset or power the board |
| 39 | +void setup() { |
| 40 | + Bluefruit.begin(); // Sleep functions need the softdevice to be active. |
| 41 | + |
| 42 | + // initialize digital pin LED_BUILTIN as an output. |
| 43 | + pinMode(LED_BUILTIN, OUTPUT); |
| 44 | +} |
| 45 | + |
| 46 | +// the loop function runs over and over again forever |
| 47 | +void loop() { |
| 48 | + digitalToggle(LED_BUILTIN); // turn the LED on (HIGH is the voltage level) |
| 49 | + gotoSleep(millis()); // call millis() and pass it to the sleep function. On wake-up, millis will start at 0 again. |
| 50 | + delay(1000); // wait for a second |
| 51 | +} |
0 commit comments