Following up from my previous effort on Arduino interrupts, here's a simple extension which will help save as much power as possible.
// See AVR4013: picoPower Basics
void implement_power_saving_hacks() {
power_spi_disable();
power_twi_disable(); // I2C
// power_timer0_disable(); // PWM 5 & 6, millis(), do not disable
power_timer1_disable(); // PWM 9 & 10
power_timer2_disable(); // PWM 3 & 11
DDRD &= B0000011; // 0 and 1 are serial comms
PORTD |= B1111100;
DDRB &= B1100000; // 6 and 7 are crystal
PORTB |= B0011111;
}
This implements some of the power saving tips from
AVR4013: PicoPower Basics. Note that the four bitwise operations at the bottom switch digital ports 2 through 13 to inputs, and tie them high with pull-up resistors. The details are in that document, thus no further comments in the code.
Do not disable Timer0, it's required for many parts of the Arduino libraries. I think "delay" uses "millis" which will not work if you turn off Timer0. If you turn off Timer0, "delay" and Serial functions will no longer work.