first commit
This commit is contained in:
@@ -0,0 +1,36 @@
|
||||
// **** INCLUDES *****
|
||||
#include "LowPower.h"
|
||||
|
||||
void setup()
|
||||
{
|
||||
// No setup is required for this library
|
||||
}
|
||||
|
||||
void loop()
|
||||
{
|
||||
// Enter idle state for 8 s with the rest of peripherals turned off
|
||||
// Each microcontroller comes with different number of peripherals
|
||||
// Comment off line of code where necessary
|
||||
|
||||
// ATmega328P, ATmega168
|
||||
LowPower.idle(SLEEP_8S, ADC_OFF, TIMER2_OFF, TIMER1_OFF, TIMER0_OFF,
|
||||
SPI_OFF, USART0_OFF, TWI_OFF);
|
||||
|
||||
// ATmega32U4
|
||||
//LowPower.idle(SLEEP_8S, ADC_OFF, TIMER4_OFF, TIMER3_OFF, TIMER1_OFF,
|
||||
// TIMER0_OFF, SPI_OFF, USART1_OFF, TWI_OFF, USB_OFF);
|
||||
|
||||
// ATmega2560
|
||||
//LowPower.idle(SLEEP_8S, ADC_OFF, TIMER5_OFF, TIMER4_OFF, TIMER3_OFF,
|
||||
// TIMER2_OFF, TIMER1_OFF, TIMER0_OFF, SPI_OFF, USART3_OFF,
|
||||
// USART2_OFF, USART1_OFF, USART0_OFF, TWI_OFF);
|
||||
|
||||
// ATmega256RFR2
|
||||
//LowPower.idle(SLEEP_8S, ADC_OFF, TIMER5_OFF, TIMER4_OFF, TIMER3_OFF,
|
||||
// TIMER2_OFF, TIMER1_OFF, TIMER0_OFF, SPI_OFF,
|
||||
// USART1_OFF, USART0_OFF, TWI_OFF);
|
||||
|
||||
// Do something here
|
||||
// Example: Read sensor, data logging, data transmission.
|
||||
}
|
||||
|
||||
@@ -0,0 +1,33 @@
|
||||
// **** INCLUDES *****
|
||||
#include "LowPower.h"
|
||||
|
||||
// Use pin 2 as wake up pin
|
||||
const int wakeUpPin = 2;
|
||||
|
||||
void wakeUp()
|
||||
{
|
||||
// Just a handler for the pin interrupt.
|
||||
}
|
||||
|
||||
void setup()
|
||||
{
|
||||
// Configure wake up pin as input.
|
||||
// This will consumes few uA of current.
|
||||
pinMode(wakeUpPin, INPUT);
|
||||
}
|
||||
|
||||
void loop()
|
||||
{
|
||||
// Allow wake up pin to trigger interrupt on low.
|
||||
attachInterrupt(0, wakeUp, LOW);
|
||||
|
||||
// Enter power down state with ADC and BOD module disabled.
|
||||
// Wake up when wake up pin is low.
|
||||
LowPower.powerDown(SLEEP_FOREVER, ADC_OFF, BOD_OFF);
|
||||
|
||||
// Disable external pin interrupt on wake up pin.
|
||||
detachInterrupt(0);
|
||||
|
||||
// Do something here
|
||||
// Example: Read sensor, data logging, data transmission.
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
// **** INCLUDES *****
|
||||
#include "LowPower.h"
|
||||
|
||||
void setup()
|
||||
{
|
||||
// No setup is required for this library
|
||||
}
|
||||
|
||||
void loop()
|
||||
{
|
||||
// Enter power down state for 8 s with ADC and BOD module disabled
|
||||
LowPower.powerDown(SLEEP_8S, ADC_OFF, BOD_OFF);
|
||||
|
||||
// Do something here
|
||||
// Example: Read sensor, data logging, data transmission.
|
||||
}
|
||||
@@ -0,0 +1,59 @@
|
||||
// **** INCLUDES *****
|
||||
#include "LowPower.h"
|
||||
|
||||
// External interrupt on pin 0 (use pin 0 to 24, except pin 4 on Arduino Zero)
|
||||
const int pin = 0;
|
||||
unsigned char count = 10;
|
||||
|
||||
void setup()
|
||||
{
|
||||
// Wait for serial USB port to open
|
||||
while(!SerialUSB);
|
||||
SerialUSB.println("***** ATSAMD21 Standby Mode Example *****");
|
||||
|
||||
// ***** IMPORTANT *****
|
||||
// Delay is required to allow the USB interface to be active during
|
||||
// sketch upload process
|
||||
SerialUSB.println("Entering standby mode in:");
|
||||
for (count; count > 0; count--)
|
||||
{
|
||||
SerialUSB.print(count);
|
||||
SerialUSB.println(" s");
|
||||
delay(1000);
|
||||
}
|
||||
// *********************
|
||||
|
||||
// External interrupt on pin (example: press of an active low button)
|
||||
// A pullup resistor is used to hold the signal high when no button press
|
||||
attachInterrupt(pin, blink, LOW);
|
||||
}
|
||||
|
||||
void loop()
|
||||
{
|
||||
SerialUSB.println("Entering standby mode.");
|
||||
SerialUSB.println("Apply low signal to wake the processor.");
|
||||
SerialUSB.println("Zzzz...");
|
||||
// Detach USB interface
|
||||
USBDevice.detach();
|
||||
// Enter standby mode
|
||||
LowPower.standby();
|
||||
// Attach USB interface
|
||||
USBDevice.attach();
|
||||
// Wait for serial USB port to open
|
||||
while(!SerialUSB);
|
||||
// Serial USB is blazing fast, you might miss the messages
|
||||
delay(1000);
|
||||
SerialUSB.println("Awake!");
|
||||
SerialUSB.println("Send any character to enter standby mode again");
|
||||
// Wait for user response
|
||||
while(!SerialUSB.available());
|
||||
while(SerialUSB.available() > 0)
|
||||
{
|
||||
SerialUSB.read();
|
||||
}
|
||||
}
|
||||
|
||||
void blink(void)
|
||||
{
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user