There are some situations where you need to save power when you are creating battery powered projects, the lowpower library is one solution (we will look at others later)
Code
You will need to install the Lowpower library – https://github.com/rocketscream/Low-Power
This example will flash an LED connected to pin 4 on and off but does not use the delay function
[codesyntax lang=”cpp”]
#include “LowPower.h”
int led = 4;
void setup()
{
pinMode(led, OUTPUT);
}
void loop()
{
digitalWrite(led,HIGH);
// ATmega328P, ATmega168
LowPower.idle(SLEEP_1S, ADC_OFF, TIMER2_OFF, TIMER1_OFF, TIMER0_OFF, SPI_OFF, USART0_OFF, TWI_OFF);
digitalWrite(led,LOW);
LowPower.idle(SLEEP_2S, ADC_OFF, TIMER2_OFF, TIMER1_OFF, TIMER0_OFF, SPI_OFF, USART0_OFF, TWI_OFF);
}
[/codesyntax]