/* * LED off LED on * 12.4 mA 14.2 mA Base blink + delay(1000); * 4.6 mA 6.6 mA powerdown1000(); */ void setup() { // try to save power by setting all IO pins to output for(int i = 0; i < 20; i++) { pinMode(i,OUTPUT); } // arduino nano TX and RX LEDs are inverted, lit on LOW digitalWrite(0,HIGH); digitalWrite(1,HIGH); // start off with pin13 LED unlit digitalWrite(13, LOW); // watchdog timers are independent of main cpu clock, // so main cpu clock can be dumped to lowest possible speed CLKPR = B10000000; // enable system clock prescaler adjustment CLKPR = B00001000; // system clock pre-scaler set to divide by 256 } // dummy function needed for watchdog interrupt or it might never trigger ISR(WDT_vect){} void powerdown1000() { // flip bits to enable watchdog timer changes WDTCSR = B00011000; // set watchdog timeout to 128K cycles = 1s WDTCSR = B00000110; // enable watchdog timer (bit 6) WDTCSR = B01000110; // enable sleep instruction for power-down sleep SMCR = B00000101; // disable brown-out detector MCUCR |= (3<<5); MCUCR = (MCUCR & ~(1<<5)) | (1<<6); // sleep puts mcu to sleep until watchdog wakes it up __asm__ __volatile__("sleep"); } void loop() { digitalWrite(13, HIGH); // turn the LED on powerdown1000(); digitalWrite(13, LOW); // turn the LED off powerdown1000(); }