You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
38 lines
666 B
38 lines
666 B
3 years ago
|
#include <Arduino.h>
|
||
|
#include <avr/sleep.h>
|
||
|
|
||
|
const int wakeUpPin = 7;
|
||
|
const int ledPin = 17;
|
||
|
|
||
|
void wake()
|
||
|
{
|
||
|
sleep_disable();
|
||
|
detachInterrupt(digitalPinToInterrupt(wakeUpPin));
|
||
|
}
|
||
|
|
||
|
void sleepNow()
|
||
|
{
|
||
|
set_sleep_mode(SLEEP_MODE_PWR_DOWN);
|
||
|
noInterrupts();
|
||
|
sleep_enable();
|
||
|
attachInterrupt(digitalPinToInterrupt(wakeUpPin), wake, LOW);
|
||
|
interrupts();
|
||
|
sleep_cpu();
|
||
|
|
||
|
}
|
||
|
|
||
|
void setup()
|
||
|
{
|
||
|
pinMode(wakeUpPin, INPUT_PULLUP);
|
||
|
pinMode(ledPin, OUTPUT);
|
||
|
}
|
||
|
|
||
|
void loop()
|
||
|
{
|
||
|
// Do something here
|
||
|
// Example: Read sensor, data logging, data transmission.
|
||
|
digitalWrite(ledPin, !digitalRead(ledPin));
|
||
|
|
||
|
// Now go to sleep
|
||
|
sleepNow();
|
||
|
}
|