can't we enter sleep mode via the toggle? watchdog?
I got the same idea, so i tryed it on an ATtiny85 and came up with this sketch
I use momentary button on PB3 and a LED on PB4.
When the led is off either by toggling the button or by the autoshutdown feature the current
consumption is 0.7 μA (if my DVM is to be trusted)
The autoshut-down time is determined by the variable autoDown=10000;
All the sleep codes are from a resent thread
http://arduino.cc/forum/index.php/topic,164146.0.htmland Jack Christensen's Million Ohms project.
// In sleep mode the consumption is 0,7 microA
#include <avr/sleep.h>
#include <avr/interrupt.h>
unsigned long autoDown=10000;
boolean ledState=false;
unsigned long mtime;
volatile boolean state = HIGH;
ISR(PCINT0_vect){
state = !state;
}
void setup(){
pinMode(4,OUTPUT);
GIMSK=_BV(PCIE); //Table 9.3.2
PCMSK=_BV(PCINT3); //Table 9.3.4
sei();
mtime=millis();
}
void loop() {
digitalWrite(4, state);
if(state==LOW){
gotoSleep();
}
if(state==HIGH){
digitalWrite(4, state);
if((millis()-mtime)>=autoDown){
state=LOW;
digitalWrite(4, state);
gotoSleep();
mtime=millis();
}
}
}
void gotoSleep(){
ACSR |= _BV(ACD); //disable the analog comparator
ADCSRA &= ~_BV(ADEN); //disable ADC
set_sleep_mode(SLEEP_MODE_PWR_DOWN); // choose your preferred sleep mode for the chip
sleep_enable(); // this puts the chip into, sleep mode, but doesn't command it to sleep yet.
sleep_mode(); // this command actually puts the chip to sleep.
}