-
Notifications
You must be signed in to change notification settings - Fork 0
/
devkit_r2_arduino_eeprom.ino
51 lines (43 loc) · 1.09 KB
/
devkit_r2_arduino_eeprom.ino
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
#include "STM32LowPower.h"
#define ENABLE_CLOCK_WAKEUP 0 // Wake up via RTC
#define ENABLE_SERIAL_WAKEUP 1 // Wake up device via Serial
#define LED_PIN PC13
volatile int wakeup_counter = 0;
void setup()
{
Serial.begin(115200);
pinMode(LED_PIN, OUTPUT);
LowPower.begin();
if (ENABLE_SERIAL_WAKEUP)
{
LowPower.enableWakeupFrom(&Serial, WakeUpCallback); // What to do when you wake up
Serial.println("Start deep sleep wakeup from Serial");
}
}
void loop()
{
if (ENABLE_SERIAL_WAKEUP)
{
Serial.print(wakeup_counter);
Serial.println(" wake up");
LowPower.deepSleep();
}
else if (ENABLE_CLOCK_WAKEUP)
{
Serial.println("LED on about to sleep");
digitalWrite(LED_PIN, HIGH);
LowPower.deepSleep(5000);
digitalWrite(LED_PIN, LOW);
Serial.println("Done sleeping");
delay(1000);
}
while (Serial.available())
{
char c = Serial.read();
Serial.print(c);
}
}
void WakeUpCallback()
{
wakeup_counter++;
}