-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathEventLogger.cpp
More file actions
41 lines (35 loc) · 747 Bytes
/
EventLogger.cpp
File metadata and controls
41 lines (35 loc) · 747 Bytes
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
/*
*
* This is an example how to use Power-down mode on Atmega328p MCU
*
* Measured values on root4root's "Event Logger" device:
* 3.3 - 3.5mA in default mode
* ~275uA in PWR_DOWN, including ~100uA for DS3231 RTC
*
* Author: root4root (at gmail dot com)
*
* 06-02-2023
*
* */
#include "Arduino.h"
#include <avr/sleep.h>
void gosleep(void);
void wakeup(void);
void setup() {
pinMode(3, INPUT_PULLUP); //D3 input with built-in pull-up resistor (20K-50K)
}
void loop() {
delay(10000);
gosleep();
}
void gosleep()
{
attachInterrupt(1, wakeup, LOW); //Interrupt to D3
sleep_enable();
set_sleep_mode(SLEEP_MODE_PWR_DOWN);
sleep_cpu();
}
void wakeup(){
sleep_disable();
detachInterrupt(1);
}